| ︙ | | | ︙ | |
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#define GET_16BIT(endian, cp) \
(endian=='B' ? GET_16BIT_MSB_FIRST(cp) : GET_16BIT_LSB_FIRST(cp))
#define PUT_16BIT(endian, cp, val) \
(endian=='B' ? PUT_16BIT_MSB_FIRST(cp, val) : PUT_16BIT_LSB_FIRST(cp, val))
extern void sshfwd_close(void *);
extern void sshfwd_write(void *, char *, int);
struct X11Private {
struct plug_function_table *fn;
/* the above variable absolutely *must* be the first in this structure */
unsigned char firstpkt[12]; /* first X data packet */
char *auth_protocol;
unsigned char *auth_data;
int data_read, auth_plen, auth_psize, auth_dlen, auth_dsize;
int verified;
void *c; /* data used by ssh.c */
Socket s;
};
void x11_close(Socket s);
static unsigned char x11_authdata[64];
|
<
<
<
>
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#define GET_16BIT(endian, cp) \
(endian=='B' ? GET_16BIT_MSB_FIRST(cp) : GET_16BIT_LSB_FIRST(cp))
#define PUT_16BIT(endian, cp, val) \
(endian=='B' ? PUT_16BIT_MSB_FIRST(cp, val) : PUT_16BIT_LSB_FIRST(cp, val))
struct X11Private {
struct plug_function_table *fn;
/* the above variable absolutely *must* be the first in this structure */
unsigned char firstpkt[12]; /* first X data packet */
char *auth_protocol;
unsigned char *auth_data;
int data_read, auth_plen, auth_psize, auth_dlen, auth_dsize;
int verified;
int throttled, throttle_override;
void *c; /* data used by ssh.c */
Socket s;
};
void x11_close(Socket s);
static unsigned char x11_authdata[64];
|
| ︙ | | | ︙ | |
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
return 1;
}
static int x11_receive(Plug plug, int urgent, char *data, int len)
{
struct X11Private *pr = (struct X11Private *) plug;
sshfwd_write(pr->c, data, len);
return 1;
}
/*
* Called to set up the raw connection.
*
* Returns an error message, or NULL on success.
* also, fills the SocketsStructure
*/
char *x11_init(Socket * s, char *display, void *c)
{
static struct plug_function_table fn_table = {
x11_closing,
x11_receive
};
SockAddr addr;
int port;
char *err, *dummy_realhost;
char host[128];
int n, displaynum;
|
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
return 1;
}
static int x11_receive(Plug plug, int urgent, char *data, int len)
{
struct X11Private *pr = (struct X11Private *) plug;
if (sshfwd_write(pr->c, data, len) > 0) {
pr->throttled = 1;
sk_set_frozen(pr->s, 1);
}
return 1;
}
static void x11_sent(Plug plug, int bufsize)
{
struct X11Private *pr = (struct X11Private *) plug;
sshfwd_unthrottle(pr->c, bufsize);
}
/*
* Called to set up the raw connection.
*
* Returns an error message, or NULL on success.
* also, fills the SocketsStructure
*/
char *x11_init(Socket * s, char *display, void *c)
{
static struct plug_function_table fn_table = {
x11_closing,
x11_receive,
x11_sent,
NULL
};
SockAddr addr;
int port;
char *err, *dummy_realhost;
char host[128];
int n, displaynum;
|
| ︙ | | | ︙ | |
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
* Open socket.
*/
pr = (struct X11Private *) smalloc(sizeof(struct X11Private));
pr->fn = &fn_table;
pr->auth_protocol = NULL;
pr->verified = 0;
pr->data_read = 0;
pr->c = c;
pr->s = *s = sk_new(addr, port, 0, 1, (Plug) pr);
if ((err = sk_socket_error(*s))) {
sfree(pr);
return err;
}
|
>
|
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
* Open socket.
*/
pr = (struct X11Private *) smalloc(sizeof(struct X11Private));
pr->fn = &fn_table;
pr->auth_protocol = NULL;
pr->verified = 0;
pr->data_read = 0;
pr->throttled = pr->throttle_override = 0;
pr->c = c;
pr->s = *s = sk_new(addr, port, 0, 1, (Plug) pr);
if ((err = sk_socket_error(*s))) {
sfree(pr);
return err;
}
|
| ︙ | | | ︙ | |
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
sfree(pr->auth_data);
}
sfree(pr);
sk_close(s);
}
/*
* Called to send data down the raw connection.
*/
void x11_send(Socket s, char *data, int len)
{
struct X11Private *pr = (struct X11Private *) sk_get_private_ptr(s);
if (s == NULL)
return;
/*
* Read the first packet.
*/
while (len > 0 && pr->data_read < 12)
pr->firstpkt[pr->data_read++] = (unsigned char) (len--, *data++);
if (pr->data_read < 12)
return;
/*
* If we have not allocated the auth_protocol and auth_data
* strings, do so now.
*/
if (!pr->auth_protocol) {
pr->auth_plen = GET_16BIT(pr->firstpkt[0], pr->firstpkt + 6);
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
sfree(pr->auth_data);
}
sfree(pr);
sk_close(s);
}
void x11_unthrottle(Socket s)
{
struct X11Private *pr;
if (!s)
return;
pr = (struct X11Private *) sk_get_private_ptr(s);
pr->throttled = 0;
sk_set_frozen(s, pr->throttled || pr->throttle_override);
}
void x11_override_throttle(Socket s, int enable)
{
struct X11Private *pr;
if (!s)
return;
pr = (struct X11Private *) sk_get_private_ptr(s);
pr->throttle_override = enable;
sk_set_frozen(s, pr->throttled || pr->throttle_override);
}
/*
* Called to send data down the raw connection.
*/
int x11_send(Socket s, char *data, int len)
{
struct X11Private *pr = (struct X11Private *) sk_get_private_ptr(s);
if (s == NULL)
return 0;
/*
* Read the first packet.
*/
while (len > 0 && pr->data_read < 12)
pr->firstpkt[pr->data_read++] = (unsigned char) (len--, *data++);
if (pr->data_read < 12)
return 0;
/*
* If we have not allocated the auth_protocol and auth_data
* strings, do so now.
*/
if (!pr->auth_protocol) {
pr->auth_plen = GET_16BIT(pr->firstpkt[0], pr->firstpkt + 6);
|
| ︙ | | | ︙ | |
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
*/
while (len > 0 && pr->data_read < 12 + pr->auth_psize)
pr->auth_protocol[pr->data_read++ - 12] = (len--, *data++);
while (len > 0 && pr->data_read < 12 + pr->auth_psize + pr->auth_dsize)
pr->auth_data[pr->data_read++ - 12 -
pr->auth_psize] = (unsigned char) (len--, *data++);
if (pr->data_read < 12 + pr->auth_psize + pr->auth_dsize)
return;
/*
* If we haven't verified the authentication, do so now.
*/
if (!pr->verified) {
int ret;
|
|
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
*/
while (len > 0 && pr->data_read < 12 + pr->auth_psize)
pr->auth_protocol[pr->data_read++ - 12] = (len--, *data++);
while (len > 0 && pr->data_read < 12 + pr->auth_psize + pr->auth_dsize)
pr->auth_data[pr->data_read++ - 12 -
pr->auth_psize] = (unsigned char) (len--, *data++);
if (pr->data_read < 12 + pr->auth_psize + pr->auth_dsize)
return 0;
/*
* If we haven't verified the authentication, do so now.
*/
if (!pr->verified) {
int ret;
|
| ︙ | | | ︙ | |
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
memcpy(reply + 2, pr->firstpkt + 2, 4); /* major/minor proto vsn */
PUT_16BIT(pr->firstpkt[0], reply + 6, msglen >> 2); /* data len */
memset(reply + 8, 0, msgsize);
memcpy(reply + 8, message, msglen);
sshfwd_write(pr->c, reply, 8 + msgsize);
sshfwd_close(pr->c);
x11_close(s);
return;
}
/*
* Now we know we're going to accept the connection. Strip
* the auth data. (TODO: if we ever work out how, we should
* replace some real auth data in here.)
*/
PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 6, 0); /* auth proto */
PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 8, 0); /* auth data */
sk_write(s, pr->firstpkt, 12);
pr->verified = 1;
}
/*
* After initialisation, just copy data simply.
*/
sk_write(s, data, len);
}
|
|
|
|
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
memcpy(reply + 2, pr->firstpkt + 2, 4); /* major/minor proto vsn */
PUT_16BIT(pr->firstpkt[0], reply + 6, msglen >> 2); /* data len */
memset(reply + 8, 0, msgsize);
memcpy(reply + 8, message, msglen);
sshfwd_write(pr->c, reply, 8 + msgsize);
sshfwd_close(pr->c);
x11_close(s);
return 0;
}
/*
* Now we know we're going to accept the connection. Strip
* the auth data. (TODO: if we ever work out how, we should
* replace some real auth data in here.)
*/
PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 6, 0); /* auth proto */
PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 8, 0); /* auth data */
sk_write(s, pr->firstpkt, 12);
pr->verified = 1;
}
/*
* After initialisation, just copy data simply.
*/
return sk_write(s, data, len);
}
|