View | Details | Raw Unified | Return to bug 2417 | Differences between
and this patch

Collapse All | Expand All

(-)channels.c.orig-6.8 (+63 lines)
Lines 1141-1146 Link Here
1141
#define SSH_SOCKS5_IPV6		0x04
1141
#define SSH_SOCKS5_IPV6		0x04
1142
#define SSH_SOCKS5_CONNECT	0x01
1142
#define SSH_SOCKS5_CONNECT	0x01
1143
#define SSH_SOCKS5_SUCCESS	0x00
1143
#define SSH_SOCKS5_SUCCESS	0x00
1144
#define SSH_SOCKS5_GENERICERROR	0x01
1145
#define SSH_SOCKS5_RULESETBLOCK	0x02
1146
#define SSH_SOCKS5_CONNREFUSED	0x05
1147
#define SSH_SOCKS5_BADATYP	0x08
1144
1148
1145
/* ARGSUSED */
1149
/* ARGSUSED */
1146
static int
1150
static int
Lines 1214-1219 Link Here
1214
		break;
1218
		break;
1215
	default:
1219
	default:
1216
		debug2("channel %d: bad socks5 atyp %d", c->self, s5_req.atyp);
1220
		debug2("channel %d: bad socks5 atyp %d", c->self, s5_req.atyp);
1221
		s5_rsp.version = 0x05;
1222
		s5_rsp.command = SSH_SOCKS5_BADATYP;
1223
		s5_rsp.reserved = 0;			/* ignored */
1224
		s5_rsp.atyp = SSH_SOCKS5_DOMAIN;
1225
		dest_port = 0;				/* ignored */
1226
1227
		buffer_append(&c->output, &s5_rsp, sizeof(s5_rsp));
1228
		buffer_put_char(&c->output, 0x00);	/* fake fqdn length = 0 */
1229
		buffer_append(&c->output, &dest_port, sizeof(dest_port));
1230
		FD_SET(c->sock, writeset);
1231
		/* TODO ensure the bytes buffered by above function are sent, which might require changing the return value below */
1217
		return -1;
1232
		return -1;
1218
	}
1233
	}
1219
	need = sizeof(s5_req) + addrlen + 2;
1234
	need = sizeof(s5_req) + addrlen + 2;
Lines 1233-1238 Link Here
1233
		if (addrlen >= NI_MAXHOST) {
1248
		if (addrlen >= NI_MAXHOST) {
1234
			error("channel %d: dynamic request: socks5 hostname "
1249
			error("channel %d: dynamic request: socks5 hostname "
1235
			    "\"%.100s\" too long", c->self, dest_addr);
1250
			    "\"%.100s\" too long", c->self, dest_addr);
1251
1252
			s5_rsp.version = 0x05;
1253
			s5_rsp.command = SSH_SOCKS5_RULESETBLOCK;
1254
			s5_rsp.reserved = 0;			/* ignored */
1255
			s5_rsp.atyp = SSH_SOCKS5_DOMAIN;
1256
			dest_port = 0;				/* ignored */
1257
1258
			buffer_append(&c->output, &s5_rsp, sizeof(s5_rsp));
1259
			buffer_put_char(&c->output, 0x00);	/* fake fqdn length = 0 */
1260
			buffer_append(&c->output, &dest_port, sizeof(dest_port));
1261
			FD_SET(c->sock, writeset);
1262
			/* TODO ensure the bytes buffered by above function are sent, which might require changing the return value below */
1236
			return -1;
1263
			return -1;
1237
		}
1264
		}
1238
		c->path = xstrdup(dest_addr);
1265
		c->path = xstrdup(dest_addr);
Lines 2572-2577 Link Here
2572
	return "unknown reason";
2599
	return "unknown reason";
2573
}
2600
}
2574
2601
2602
static int
2603
reason2socks5(int reason)
2604
{
2605
	switch (reason) {
2606
	case SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED:
2607
		return SSH_SOCKS5_RULESETBLOCK;
2608
	case SSH2_OPEN_CONNECT_FAILED:
2609
		return SSH_SOCKS5_CONNREFUSED;
2610
	}
2611
	return SSH_SOCKS5_GENERICERROR;
2612
}
2613
2575
/* ARGSUSED */
2614
/* ARGSUSED */
2576
int
2615
int
2577
channel_input_open_failure(int type, u_int32_t seq, void *ctxt)
2616
channel_input_open_failure(int type, u_int32_t seq, void *ctxt)
Lines 2596-2601 Link Here
2596
		    reason2txt(reason), msg ? ": ": "", msg ? msg : "");
2635
		    reason2txt(reason), msg ? ": ": "", msg ? msg : "");
2597
		free(msg);
2636
		free(msg);
2598
		free(lang);
2637
		free(lang);
2638
		/* TODO should this perhaps occur after open_confirm? */
2639
		if (c->remote_name && strcmp(c->remote_name, "dynamic-tcpip") == 0 && (c->flags & SSH_SOCKS5_AUTHDONE)) {
2640
			/* struct copied from channel_decode_socks5() */
2641
			struct {
2642
				u_int8_t version;
2643
				u_int8_t command;
2644
				u_int8_t reserved;
2645
				u_int8_t atyp;
2646
			} s5_rsp;
2647
			u_int16_t dest_port;
2648
2649
			s5_rsp.version = 0x05;
2650
			s5_rsp.command = reason2socks5(reason);
2651
			s5_rsp.reserved = 0;			/* ignored */
2652
			s5_rsp.atyp = SSH_SOCKS5_DOMAIN;
2653
			dest_port = 0;				/* ignored */
2654
2655
			buffer_append(&c->output, &s5_rsp, sizeof(s5_rsp));
2656
			buffer_put_char(&c->output, 0x00);	/* fake fqdn length = 0 */
2657
			buffer_append(&c->output, &dest_port, sizeof(dest_port));
2658
			FD_SET(c->sock, writeset);
2659
2660
			/* TODO will the data above get sent despite the chan_mark_dead() below? */
2661
		}
2599
		if (c->open_confirm) {
2662
		if (c->open_confirm) {
2600
			debug2("callback start");
2663
			debug2("callback start");
2601
			c->open_confirm(c->self, 0, c->open_confirm_ctx);
2664
			c->open_confirm(c->self, 0, c->open_confirm_ctx);

Return to bug 2417