summaryrefslogtreecommitdiff
path: root/readconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'readconf.c')
-rw-r--r--readconf.c130
1 files changed, 79 insertions, 51 deletions
diff --git a/readconf.c b/readconf.c
index 73f6eb361..53fc6c7ba 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readconf.c,v 1.167 2008/06/26 11:46:31 grunk Exp $ */ 1/* $OpenBSD: readconf.c,v 1.176 2009/02/12 03:00:56 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -130,7 +130,7 @@ typedef enum {
130 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly, 130 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
131 oSendEnv, oControlPath, oControlMaster, oHashKnownHosts, 131 oSendEnv, oControlPath, oControlMaster, oHashKnownHosts,
132 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand, 132 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
133 oVisualHostKey, 133 oVisualHostKey, oZeroKnowledgePasswordAuthentication,
134 oDeprecated, oUnsupported 134 oDeprecated, oUnsupported
135} OpCodes; 135} OpCodes;
136 136
@@ -172,7 +172,7 @@ static struct {
172 { "fallbacktorsh", oDeprecated }, 172 { "fallbacktorsh", oDeprecated },
173 { "usersh", oDeprecated }, 173 { "usersh", oDeprecated },
174 { "identityfile", oIdentityFile }, 174 { "identityfile", oIdentityFile },
175 { "identityfile2", oIdentityFile }, /* alias */ 175 { "identityfile2", oIdentityFile }, /* obsolete */
176 { "identitiesonly", oIdentitiesOnly }, 176 { "identitiesonly", oIdentitiesOnly },
177 { "hostname", oHostName }, 177 { "hostname", oHostName },
178 { "hostkeyalias", oHostKeyAlias }, 178 { "hostkeyalias", oHostKeyAlias },
@@ -188,8 +188,8 @@ static struct {
188 { "host", oHost }, 188 { "host", oHost },
189 { "escapechar", oEscapeChar }, 189 { "escapechar", oEscapeChar },
190 { "globalknownhostsfile", oGlobalKnownHostsFile }, 190 { "globalknownhostsfile", oGlobalKnownHostsFile },
191 { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */ 191 { "globalknownhostsfile2", oGlobalKnownHostsFile2 }, /* obsolete */
192 { "globalknownhostsfile2", oGlobalKnownHostsFile2 }, 192 { "userknownhostsfile", oUserKnownHostsFile },
193 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */ 193 { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */
194 { "connectionattempts", oConnectionAttempts }, 194 { "connectionattempts", oConnectionAttempts },
195 { "batchmode", oBatchMode }, 195 { "batchmode", oBatchMode },
@@ -228,6 +228,13 @@ static struct {
228 { "localcommand", oLocalCommand }, 228 { "localcommand", oLocalCommand },
229 { "permitlocalcommand", oPermitLocalCommand }, 229 { "permitlocalcommand", oPermitLocalCommand },
230 { "visualhostkey", oVisualHostKey }, 230 { "visualhostkey", oVisualHostKey },
231#ifdef JPAKE
232 { "zeroknowledgepasswordauthentication",
233 oZeroKnowledgePasswordAuthentication },
234#else
235 { "zeroknowledgepasswordauthentication", oUnsupported },
236#endif
237
231 { NULL, oBadOption } 238 { NULL, oBadOption }
232}; 239};
233 240
@@ -249,10 +256,9 @@ add_local_forward(Options *options, const Forward *newfwd)
249 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION); 256 fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
250 fwd = &options->local_forwards[options->num_local_forwards++]; 257 fwd = &options->local_forwards[options->num_local_forwards++];
251 258
252 fwd->listen_host = (newfwd->listen_host == NULL) ? 259 fwd->listen_host = newfwd->listen_host;
253 NULL : xstrdup(newfwd->listen_host);
254 fwd->listen_port = newfwd->listen_port; 260 fwd->listen_port = newfwd->listen_port;
255 fwd->connect_host = xstrdup(newfwd->connect_host); 261 fwd->connect_host = newfwd->connect_host;
256 fwd->connect_port = newfwd->connect_port; 262 fwd->connect_port = newfwd->connect_port;
257} 263}
258 264
@@ -270,10 +276,9 @@ add_remote_forward(Options *options, const Forward *newfwd)
270 SSH_MAX_FORWARDS_PER_DIRECTION); 276 SSH_MAX_FORWARDS_PER_DIRECTION);
271 fwd = &options->remote_forwards[options->num_remote_forwards++]; 277 fwd = &options->remote_forwards[options->num_remote_forwards++];
272 278
273 fwd->listen_host = (newfwd->listen_host == NULL) ? 279 fwd->listen_host = newfwd->listen_host;
274 NULL : xstrdup(newfwd->listen_host);
275 fwd->listen_port = newfwd->listen_port; 280 fwd->listen_port = newfwd->listen_port;
276 fwd->connect_host = xstrdup(newfwd->connect_host); 281 fwd->connect_host = newfwd->connect_host;
277 fwd->connect_port = newfwd->connect_port; 282 fwd->connect_port = newfwd->connect_port;
278} 283}
279 284
@@ -412,6 +417,10 @@ parse_flag:
412 intptr = &options->password_authentication; 417 intptr = &options->password_authentication;
413 goto parse_flag; 418 goto parse_flag;
414 419
420 case oZeroKnowledgePasswordAuthentication:
421 intptr = &options->zero_knowledge_password_authentication;
422 goto parse_flag;
423
415 case oKbdInteractiveAuthentication: 424 case oKbdInteractiveAuthentication:
416 intptr = &options->kbd_interactive_authentication; 425 intptr = &options->kbd_interactive_authentication;
417 goto parse_flag; 426 goto parse_flag;
@@ -706,56 +715,40 @@ parse_int:
706 715
707 case oLocalForward: 716 case oLocalForward:
708 case oRemoteForward: 717 case oRemoteForward:
718 case oDynamicForward:
709 arg = strdelim(&s); 719 arg = strdelim(&s);
710 if (arg == NULL || *arg == '\0') 720 if (arg == NULL || *arg == '\0')
711 fatal("%.200s line %d: Missing port argument.", 721 fatal("%.200s line %d: Missing port argument.",
712 filename, linenum); 722 filename, linenum);
713 arg2 = strdelim(&s);
714 if (arg2 == NULL || *arg2 == '\0')
715 fatal("%.200s line %d: Missing target argument.",
716 filename, linenum);
717 723
718 /* construct a string for parse_forward */ 724 if (opcode == oLocalForward ||
719 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2); 725 opcode == oRemoteForward) {
726 arg2 = strdelim(&s);
727 if (arg2 == NULL || *arg2 == '\0')
728 fatal("%.200s line %d: Missing target argument.",
729 filename, linenum);
730
731 /* construct a string for parse_forward */
732 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
733 } else if (opcode == oDynamicForward) {
734 strlcpy(fwdarg, arg, sizeof(fwdarg));
735 }
720 736
721 if (parse_forward(&fwd, fwdarg) == 0) 737 if (parse_forward(&fwd, fwdarg,
738 opcode == oDynamicForward ? 1 : 0,
739 opcode == oRemoteForward ? 1 : 0) == 0)
722 fatal("%.200s line %d: Bad forwarding specification.", 740 fatal("%.200s line %d: Bad forwarding specification.",
723 filename, linenum); 741 filename, linenum);
724 742
725 if (*activep) { 743 if (*activep) {
726 if (opcode == oLocalForward) 744 if (opcode == oLocalForward ||
745 opcode == oDynamicForward)
727 add_local_forward(options, &fwd); 746 add_local_forward(options, &fwd);
728 else if (opcode == oRemoteForward) 747 else if (opcode == oRemoteForward)
729 add_remote_forward(options, &fwd); 748 add_remote_forward(options, &fwd);
730 } 749 }
731 break; 750 break;
732 751
733 case oDynamicForward:
734 arg = strdelim(&s);
735 if (!arg || *arg == '\0')
736 fatal("%.200s line %d: Missing port argument.",
737 filename, linenum);
738 memset(&fwd, '\0', sizeof(fwd));
739 fwd.connect_host = "socks";
740 fwd.listen_host = hpdelim(&arg);
741 if (fwd.listen_host == NULL ||
742 strlen(fwd.listen_host) >= NI_MAXHOST)
743 fatal("%.200s line %d: Bad forwarding specification.",
744 filename, linenum);
745 if (arg) {
746 fwd.listen_port = a2port(arg);
747 fwd.listen_host = cleanhostname(fwd.listen_host);
748 } else {
749 fwd.listen_port = a2port(fwd.listen_host);
750 fwd.listen_host = NULL;
751 }
752 if (fwd.listen_port == 0)
753 fatal("%.200s line %d: Badly formatted port number.",
754 filename, linenum);
755 if (*activep)
756 add_local_forward(options, &fwd);
757 break;
758
759 case oClearAllForwardings: 752 case oClearAllForwardings:
760 intptr = &options->clear_forwardings; 753 intptr = &options->clear_forwardings;
761 goto parse_flag; 754 goto parse_flag;
@@ -959,7 +952,6 @@ read_config_file(const char *filename, const char *host, Options *options,
959 int active, linenum; 952 int active, linenum;
960 int bad_options = 0; 953 int bad_options = 0;
961 954
962 /* Open the file. */
963 if ((f = fopen(filename, "r")) == NULL) 955 if ((f = fopen(filename, "r")) == NULL)
964 return 0; 956 return 0;
965 957
@@ -1072,6 +1064,7 @@ initialize_options(Options * options)
1072 options->local_command = NULL; 1064 options->local_command = NULL;
1073 options->permit_local_command = -1; 1065 options->permit_local_command = -1;
1074 options->visual_host_key = -1; 1066 options->visual_host_key = -1;
1067 options->zero_knowledge_password_authentication = -1;
1075} 1068}
1076 1069
1077/* 1070/*
@@ -1208,6 +1201,8 @@ fill_default_options(Options * options)
1208 options->permit_local_command = 0; 1201 options->permit_local_command = 0;
1209 if (options->visual_host_key == -1) 1202 if (options->visual_host_key == -1)
1210 options->visual_host_key = 0; 1203 options->visual_host_key = 0;
1204 if (options->zero_knowledge_password_authentication == -1)
1205 options->zero_knowledge_password_authentication = 0;
1211 /* options->local_command should not be set by default */ 1206 /* options->local_command should not be set by default */
1212 /* options->proxy_command should not be set by default */ 1207 /* options->proxy_command should not be set by default */
1213 /* options->user will be set in the main program if appropriate */ 1208 /* options->user will be set in the main program if appropriate */
@@ -1219,11 +1214,14 @@ fill_default_options(Options * options)
1219/* 1214/*
1220 * parse_forward 1215 * parse_forward
1221 * parses a string containing a port forwarding specification of the form: 1216 * parses a string containing a port forwarding specification of the form:
1217 * dynamicfwd == 0
1222 * [listenhost:]listenport:connecthost:connectport 1218 * [listenhost:]listenport:connecthost:connectport
1219 * dynamicfwd == 1
1220 * [listenhost:]listenport
1223 * returns number of arguments parsed or zero on error 1221 * returns number of arguments parsed or zero on error
1224 */ 1222 */
1225int 1223int
1226parse_forward(Forward *fwd, const char *fwdspec) 1224parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1227{ 1225{
1228 int i; 1226 int i;
1229 char *p, *cp, *fwdarg[4]; 1227 char *p, *cp, *fwdarg[4];
@@ -1240,11 +1238,23 @@ parse_forward(Forward *fwd, const char *fwdspec)
1240 if ((fwdarg[i] = hpdelim(&cp)) == NULL) 1238 if ((fwdarg[i] = hpdelim(&cp)) == NULL)
1241 break; 1239 break;
1242 1240
1243 /* Check for trailing garbage in 4-arg case*/ 1241 /* Check for trailing garbage */
1244 if (cp != NULL) 1242 if (cp != NULL)
1245 i = 0; /* failure */ 1243 i = 0; /* failure */
1246 1244
1247 switch (i) { 1245 switch (i) {
1246 case 1:
1247 fwd->listen_host = NULL;
1248 fwd->listen_port = a2port(fwdarg[0]);
1249 fwd->connect_host = xstrdup("socks");
1250 break;
1251
1252 case 2:
1253 fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1254 fwd->listen_port = a2port(fwdarg[1]);
1255 fwd->connect_host = xstrdup("socks");
1256 break;
1257
1248 case 3: 1258 case 3:
1249 fwd->listen_host = NULL; 1259 fwd->listen_host = NULL;
1250 fwd->listen_port = a2port(fwdarg[0]); 1260 fwd->listen_port = a2port(fwdarg[0]);
@@ -1264,19 +1274,37 @@ parse_forward(Forward *fwd, const char *fwdspec)
1264 1274
1265 xfree(p); 1275 xfree(p);
1266 1276
1267 if (fwd->listen_port == 0 || fwd->connect_port == 0) 1277 if (dynamicfwd) {
1278 if (!(i == 1 || i == 2))
1279 goto fail_free;
1280 } else {
1281 if (!(i == 3 || i == 4))
1282 goto fail_free;
1283 if (fwd->connect_port <= 0)
1284 goto fail_free;
1285 }
1286
1287 if (fwd->listen_port < 0 || (!remotefwd && fwd->listen_port == 0))
1268 goto fail_free; 1288 goto fail_free;
1269 1289
1270 if (fwd->connect_host != NULL && 1290 if (fwd->connect_host != NULL &&
1271 strlen(fwd->connect_host) >= NI_MAXHOST) 1291 strlen(fwd->connect_host) >= NI_MAXHOST)
1272 goto fail_free; 1292 goto fail_free;
1293 if (fwd->listen_host != NULL &&
1294 strlen(fwd->listen_host) >= NI_MAXHOST)
1295 goto fail_free;
1296
1273 1297
1274 return (i); 1298 return (i);
1275 1299
1276 fail_free: 1300 fail_free:
1277 if (fwd->connect_host != NULL) 1301 if (fwd->connect_host != NULL) {
1278 xfree(fwd->connect_host); 1302 xfree(fwd->connect_host);
1279 if (fwd->listen_host != NULL) 1303 fwd->connect_host = NULL;
1304 }
1305 if (fwd->listen_host != NULL) {
1280 xfree(fwd->listen_host); 1306 xfree(fwd->listen_host);
1307 fwd->listen_host = NULL;
1308 }
1281 return (0); 1309 return (0);
1282} 1310}