|
Lines 206-224
static struct {
Link Here
|
| 206 |
*/ |
206 |
*/ |
| 207 |
|
207 |
|
| 208 |
void |
208 |
void |
| 209 |
add_local_forward(Options *options, u_short port, const char *host, |
209 |
add_local_forward(Options *options, const char *listen_host, |
| 210 |
u_short host_port) |
210 |
u_short listen_port, const char *connect_host, u_short connect_port) |
| 211 |
{ |
211 |
{ |
| 212 |
Forward *fwd; |
212 |
Forward *fwd; |
| 213 |
extern uid_t original_real_uid; |
213 |
extern uid_t original_real_uid; |
| 214 |
if (port < IPPORT_RESERVED && original_real_uid != 0) |
214 |
if (listen_port < IPPORT_RESERVED && original_real_uid != 0) |
| 215 |
fatal("Privileged ports can only be forwarded by root."); |
215 |
fatal("Privileged ports can only be forwarded by root."); |
| 216 |
if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
216 |
if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
| 217 |
fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION); |
217 |
fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION); |
| 218 |
fwd = &options->local_forwards[options->num_local_forwards++]; |
218 |
fwd = &options->local_forwards[options->num_local_forwards++]; |
| 219 |
fwd->port = port; |
219 |
if (listen_host == NULL) |
| 220 |
fwd->host = xstrdup(host); |
220 |
fwd->listen_host = NULL; |
| 221 |
fwd->host_port = host_port; |
221 |
else |
|
|
222 |
fwd->listen_host = xstrdup(listen_host); |
| 223 |
fwd->listen_port = listen_port; |
| 224 |
fwd->connect_host = xstrdup(connect_host); |
| 225 |
fwd->connect_port = connect_port; |
| 222 |
} |
226 |
} |
| 223 |
|
227 |
|
| 224 |
/* |
228 |
/* |
|
Lines 227-243
add_local_forward(Options *options, u_sh
Link Here
|
| 227 |
*/ |
231 |
*/ |
| 228 |
|
232 |
|
| 229 |
void |
233 |
void |
| 230 |
add_remote_forward(Options *options, u_short port, const char *host, |
234 |
add_remote_forward(Options *options, const char *listen_host, |
| 231 |
u_short host_port) |
235 |
u_short listen_port, const char *connect_host, u_short connect_port) |
| 232 |
{ |
236 |
{ |
| 233 |
Forward *fwd; |
237 |
Forward *fwd; |
| 234 |
if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
238 |
if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
| 235 |
fatal("Too many remote forwards (max %d).", |
239 |
fatal("Too many remote forwards (max %d).", |
| 236 |
SSH_MAX_FORWARDS_PER_DIRECTION); |
240 |
SSH_MAX_FORWARDS_PER_DIRECTION); |
| 237 |
fwd = &options->remote_forwards[options->num_remote_forwards++]; |
241 |
fwd = &options->remote_forwards[options->num_remote_forwards++]; |
| 238 |
fwd->port = port; |
242 |
if (listen_host == NULL) |
| 239 |
fwd->host = xstrdup(host); |
243 |
fwd->listen_host = NULL; |
| 240 |
fwd->host_port = host_port; |
244 |
else |
|
|
245 |
fwd->listen_host = xstrdup(listen_host); |
| 246 |
fwd->listen_port = listen_port; |
| 247 |
fwd->connect_host = xstrdup(connect_host); |
| 248 |
fwd->connect_port = connect_port; |
| 241 |
} |
249 |
} |
| 242 |
|
250 |
|
| 243 |
static void |
251 |
static void |
|
Lines 245-255
clear_forwardings(Options *options)
Link Here
|
| 245 |
{ |
253 |
{ |
| 246 |
int i; |
254 |
int i; |
| 247 |
|
255 |
|
| 248 |
for (i = 0; i < options->num_local_forwards; i++) |
256 |
for (i = 0; i < options->num_local_forwards; i++) { |
| 249 |
xfree(options->local_forwards[i].host); |
257 |
xfree(options->local_forwards[i].listen_host); |
|
|
258 |
xfree(options->local_forwards[i].connect_host); |
| 259 |
} |
| 250 |
options->num_local_forwards = 0; |
260 |
options->num_local_forwards = 0; |
| 251 |
for (i = 0; i < options->num_remote_forwards; i++) |
261 |
for (i = 0; i < options->num_remote_forwards; i++) { |
| 252 |
xfree(options->remote_forwards[i].host); |
262 |
xfree(options->remote_forwards[i].listen_host); |
|
|
263 |
xfree(options->remote_forwards[i].connect_host); |
| 264 |
} |
| 253 |
options->num_remote_forwards = 0; |
265 |
options->num_remote_forwards = 0; |
| 254 |
} |
266 |
} |
| 255 |
|
267 |
|
|
Lines 282-292
process_config_line(Options *options, co
Link Here
|
| 282 |
char *line, const char *filename, int linenum, |
294 |
char *line, const char *filename, int linenum, |
| 283 |
int *activep) |
295 |
int *activep) |
| 284 |
{ |
296 |
{ |
| 285 |
char buf[256], *s, **charptr, *endofnumber, *keyword, *arg; |
297 |
char *s, **charptr, *endofnumber, *keyword, *arg, *arg2, fwdarg[256]; |
| 286 |
int opcode, *intptr, value; |
298 |
int opcode, *intptr, value; |
| 287 |
size_t len; |
299 |
size_t len; |
| 288 |
u_short fwd_port, fwd_host_port; |
300 |
Forward fwd; |
| 289 |
char sfwd_host_port[6]; |
|
|
| 290 |
|
301 |
|
| 291 |
/* Strip trailing whitespace */ |
302 |
/* Strip trailing whitespace */ |
| 292 |
for(len = strlen(line) - 1; len > 0; len--) { |
303 |
for(len = strlen(line) - 1; len > 0; len--) { |
|
Lines 646-672
parse_int:
Link Here
|
| 646 |
if (!arg || *arg == '\0') |
657 |
if (!arg || *arg == '\0') |
| 647 |
fatal("%.200s line %d: Missing port argument.", |
658 |
fatal("%.200s line %d: Missing port argument.", |
| 648 |
filename, linenum); |
659 |
filename, linenum); |
| 649 |
if ((fwd_port = a2port(arg)) == 0) |
660 |
arg2 = strdelim(&s); |
| 650 |
fatal("%.200s line %d: Bad listen port.", |
661 |
if (!arg2 || *arg2 == '\0') |
| 651 |
filename, linenum); |
|
|
| 652 |
arg = strdelim(&s); |
| 653 |
if (!arg || *arg == '\0') |
| 654 |
fatal("%.200s line %d: Missing second argument.", |
662 |
fatal("%.200s line %d: Missing second argument.", |
| 655 |
filename, linenum); |
663 |
filename, linenum); |
| 656 |
if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 && |
664 |
|
| 657 |
sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2) |
665 |
/* construct a string for parse_forward */ |
|
|
666 |
snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2); |
| 667 |
|
| 668 |
if (parse_forward(&fwd, fwdarg) == 0) |
| 658 |
fatal("%.200s line %d: Bad forwarding specification.", |
669 |
fatal("%.200s line %d: Bad forwarding specification.", |
| 659 |
filename, linenum); |
670 |
filename, linenum); |
| 660 |
if ((fwd_host_port = a2port(sfwd_host_port)) == 0) |
671 |
if (fwd.listen_port == 0) |
|
|
672 |
fatal("%.200s line %d: Bad listen port.", |
| 673 |
filename, linenum); |
| 674 |
if (fwd.connect_port == 0) |
| 661 |
fatal("%.200s line %d: Bad forwarding port.", |
675 |
fatal("%.200s line %d: Bad forwarding port.", |
| 662 |
filename, linenum); |
676 |
filename, linenum); |
|
|
677 |
|
| 663 |
if (*activep) { |
678 |
if (*activep) { |
| 664 |
if (opcode == oLocalForward) |
679 |
if (opcode == oLocalForward) |
| 665 |
add_local_forward(options, fwd_port, buf, |
680 |
add_local_forward(options, |
| 666 |
fwd_host_port); |
681 |
fwd.listen_host, fwd.listen_port, |
|
|
682 |
fwd.connect_host, fwd.connect_port); |
| 667 |
else if (opcode == oRemoteForward) |
683 |
else if (opcode == oRemoteForward) |
| 668 |
add_remote_forward(options, fwd_port, buf, |
684 |
add_remote_forward(options, |
| 669 |
fwd_host_port); |
685 |
fwd.listen_host, fwd.listen_port, |
|
|
686 |
fwd.connect_host, fwd.connect_port); |
| 670 |
} |
687 |
} |
| 671 |
break; |
688 |
break; |
| 672 |
|
689 |
|
|
Lines 675-686
parse_int:
Link Here
|
| 675 |
if (!arg || *arg == '\0') |
692 |
if (!arg || *arg == '\0') |
| 676 |
fatal("%.200s line %d: Missing port argument.", |
693 |
fatal("%.200s line %d: Missing port argument.", |
| 677 |
filename, linenum); |
694 |
filename, linenum); |
| 678 |
fwd_port = a2port(arg); |
695 |
fwd.listen_port = 0; |
| 679 |
if (fwd_port == 0) |
696 |
fwd.listen_host = hpdelim(&arg); |
|
|
697 |
if (!fwd.listen_host) |
| 698 |
fatal("%.200s line %d: Bad forwarding specification.", |
| 699 |
filename, linenum); |
| 700 |
if (arg) { |
| 701 |
fwd.listen_port = a2port(arg); |
| 702 |
fwd.listen_host = cleanhostname(fwd.listen_host); |
| 703 |
} else { |
| 704 |
fwd.listen_port = a2port(fwd.listen_host); |
| 705 |
fwd.listen_host = ""; |
| 706 |
} |
| 707 |
if (fwd.listen_port == 0) |
| 680 |
fatal("%.200s line %d: Badly formatted port number.", |
708 |
fatal("%.200s line %d: Badly formatted port number.", |
| 681 |
filename, linenum); |
709 |
filename, linenum); |
| 682 |
if (*activep) |
710 |
if (*activep) |
| 683 |
add_local_forward(options, fwd_port, "socks", 0); |
711 |
add_local_forward(options, fwd.listen_host, |
|
|
712 |
fwd.listen_port, "socks4", 0); |
| 684 |
break; |
713 |
break; |
| 685 |
|
714 |
|
| 686 |
case oClearAllForwardings: |
715 |
case oClearAllForwardings: |
|
Lines 1042-1045
fill_default_options(Options * options)
Link Here
|
| 1042 |
/* options->hostname will be set in the main program if appropriate */ |
1071 |
/* options->hostname will be set in the main program if appropriate */ |
| 1043 |
/* options->host_key_alias should not be set by default */ |
1072 |
/* options->host_key_alias should not be set by default */ |
| 1044 |
/* options->preferred_authentications will be set in ssh */ |
1073 |
/* options->preferred_authentications will be set in ssh */ |
|
|
1074 |
} |
| 1075 |
|
| 1076 |
/* |
| 1077 |
* parse_forward |
| 1078 |
* parses a string containing a port forwarding specification of the form: |
| 1079 |
* [listenhost:]listenport:connecthost:connectport |
| 1080 |
* returns number of arguments parsed or zero on error |
| 1081 |
*/ |
| 1082 |
int |
| 1083 |
parse_forward(Forward *fwd, const char *fwdspec) |
| 1084 |
{ |
| 1085 |
int i; |
| 1086 |
char *p, *cp, *fwdarg[4]; |
| 1087 |
|
| 1088 |
cp = p = xstrdup(fwdspec); |
| 1089 |
|
| 1090 |
/* skip leading spaces */ |
| 1091 |
while (*cp && isspace(*cp)) |
| 1092 |
cp++; |
| 1093 |
|
| 1094 |
for (i = 0; i < 4; ++i) |
| 1095 |
if ( !(fwdarg[i] = hpdelim(&cp)) ) |
| 1096 |
break; |
| 1097 |
switch(i) { |
| 1098 |
case 3: |
| 1099 |
fwd->listen_host = NULL; |
| 1100 |
fwd->listen_port = a2port(fwdarg[0]); |
| 1101 |
fwd->connect_host = xstrdup(cleanhostname(fwdarg[1])); |
| 1102 |
fwd->connect_port = a2port(fwdarg[2]); |
| 1103 |
break; |
| 1104 |
|
| 1105 |
case 4: |
| 1106 |
fwd->listen_host = xstrdup(cleanhostname(fwdarg[0])); |
| 1107 |
fwd->listen_port = a2port(fwdarg[1]); |
| 1108 |
fwd->connect_host = xstrdup(cleanhostname(fwdarg[2])); |
| 1109 |
fwd->connect_port = a2port(fwdarg[3]); |
| 1110 |
break; |
| 1111 |
default: |
| 1112 |
i = 0; /* failure */ |
| 1113 |
} |
| 1114 |
|
| 1115 |
xfree(p); |
| 1116 |
|
| 1117 |
if (fwd->listen_port == 0 && fwd->connect_port == 0) |
| 1118 |
i = 0; /* failure */ |
| 1119 |
|
| 1120 |
return(i); |
| 1045 |
} |
1121 |
} |