Annotation of src/usr.bin/ssh/servconf.c, Revision 1.74
1.1 deraadt 1: /*
1.26 deraadt 2: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3: * All rights reserved
1.34 markus 4: *
1.51 deraadt 5: * As far as I am concerned, the code I have written for this software
6: * can be used freely for any purpose. Any derived versions of this
7: * software must be clearly marked as such, and if the derived work is
8: * incompatible with the protocol description in the RFC file, it must be
9: * called by a name other than "ssh" or "Secure Shell".
1.26 deraadt 10: */
1.1 deraadt 11:
12: #include "includes.h"
1.74 ! stevesk 13: RCSID("$OpenBSD: servconf.c,v 1.73 2001/04/02 14:20:23 stevesk Exp $");
1.62 markus 14:
15: #ifdef KRB4
16: #include <krb.h>
17: #endif
18: #ifdef AFS
19: #include <kafs.h>
20: #endif
1.1 deraadt 21:
22: #include "ssh.h"
1.62 markus 23: #include "log.h"
1.1 deraadt 24: #include "servconf.h"
25: #include "xmalloc.h"
1.33 markus 26: #include "compat.h"
1.60 markus 27: #include "pathnames.h"
1.62 markus 28: #include "tildexpand.h"
29: #include "misc.h"
30: #include "cipher.h"
1.66 markus 31: #include "kex.h"
32: #include "mac.h"
1.1 deraadt 33:
1.29 markus 34: /* add listen address */
1.74 ! stevesk 35: void add_listen_addr(ServerOptions *options, char *addr, char *port);
! 36: void add_one_listen_addr(ServerOptions *options, char *addr, u_short port);
1.29 markus 37:
1.62 markus 38: /* AF_UNSPEC or AF_INET or AF_INET6 */
39: extern int IPv4or6;
40:
1.1 deraadt 41: /* Initializes the server options to their default values. */
42:
1.34 markus 43: void
1.25 markus 44: initialize_server_options(ServerOptions *options)
1.1 deraadt 45: {
1.25 markus 46: memset(options, 0, sizeof(*options));
1.29 markus 47: options->num_ports = 0;
48: options->ports_from_cmdline = 0;
49: options->listen_addrs = NULL;
1.54 markus 50: options->num_host_key_files = 0;
1.36 markus 51: options->pid_file = NULL;
1.25 markus 52: options->server_key_bits = -1;
53: options->login_grace_time = -1;
54: options->key_regeneration_time = -1;
1.67 markus 55: options->permit_root_login = PERMIT_NOT_SET;
1.25 markus 56: options->ignore_rhosts = -1;
57: options->ignore_user_known_hosts = -1;
58: options->print_motd = -1;
1.72 stevesk 59: options->print_lastlog = -1;
1.25 markus 60: options->check_mail = -1;
61: options->x11_forwarding = -1;
62: options->x11_display_offset = -1;
1.42 markus 63: options->xauth_location = NULL;
1.25 markus 64: options->strict_modes = -1;
65: options->keepalives = -1;
66: options->log_facility = (SyslogFacility) - 1;
67: options->log_level = (LogLevel) - 1;
68: options->rhosts_authentication = -1;
69: options->rhosts_rsa_authentication = -1;
70: options->rsa_authentication = -1;
1.54 markus 71: options->pubkey_authentication = -1;
1.1 deraadt 72: #ifdef KRB4
1.25 markus 73: options->kerberos_authentication = -1;
74: options->kerberos_or_local_passwd = -1;
75: options->kerberos_ticket_cleanup = -1;
1.1 deraadt 76: #endif
1.4 dugsong 77: #ifdef AFS
1.25 markus 78: options->kerberos_tgt_passing = -1;
79: options->afs_token_passing = -1;
1.1 deraadt 80: #endif
1.25 markus 81: options->password_authentication = -1;
1.52 markus 82: options->kbd_interactive_authentication = -1;
1.63 markus 83: options->challenge_reponse_authentication = -1;
1.25 markus 84: options->permit_empty_passwd = -1;
85: options->use_login = -1;
1.53 markus 86: options->allow_tcp_forwarding = -1;
1.25 markus 87: options->num_allow_users = 0;
88: options->num_deny_users = 0;
89: options->num_allow_groups = 0;
90: options->num_deny_groups = 0;
1.33 markus 91: options->ciphers = NULL;
1.66 markus 92: options->macs = NULL;
1.33 markus 93: options->protocol = SSH_PROTO_UNKNOWN;
1.38 markus 94: options->gateway_ports = -1;
1.43 jakob 95: options->num_subsystems = 0;
1.50 markus 96: options->max_startups_begin = -1;
97: options->max_startups_rate = -1;
1.46 markus 98: options->max_startups = -1;
1.57 markus 99: options->banner = NULL;
1.64 markus 100: options->reverse_mapping_check = -1;
1.1 deraadt 101: }
102:
1.34 markus 103: void
1.25 markus 104: fill_default_server_options(ServerOptions *options)
1.1 deraadt 105: {
1.54 markus 106: if (options->protocol == SSH_PROTO_UNKNOWN)
107: options->protocol = SSH_PROTO_1|SSH_PROTO_2;
108: if (options->num_host_key_files == 0) {
109: /* fill default hostkeys for protocols */
110: if (options->protocol & SSH_PROTO_1)
1.60 markus 111: options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
1.54 markus 112: if (options->protocol & SSH_PROTO_2)
1.60 markus 113: options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
1.54 markus 114: }
1.29 markus 115: if (options->num_ports == 0)
116: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
117: if (options->listen_addrs == NULL)
1.74 ! stevesk 118: add_listen_addr(options, NULL, NULL);
1.36 markus 119: if (options->pid_file == NULL)
1.60 markus 120: options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25 markus 121: if (options->server_key_bits == -1)
122: options->server_key_bits = 768;
123: if (options->login_grace_time == -1)
124: options->login_grace_time = 600;
125: if (options->key_regeneration_time == -1)
126: options->key_regeneration_time = 3600;
1.67 markus 127: if (options->permit_root_login == PERMIT_NOT_SET)
128: options->permit_root_login = PERMIT_YES;
1.25 markus 129: if (options->ignore_rhosts == -1)
1.30 markus 130: options->ignore_rhosts = 1;
1.25 markus 131: if (options->ignore_user_known_hosts == -1)
132: options->ignore_user_known_hosts = 0;
133: if (options->check_mail == -1)
134: options->check_mail = 0;
135: if (options->print_motd == -1)
136: options->print_motd = 1;
1.72 stevesk 137: if (options->print_lastlog == -1)
138: options->print_lastlog = 1;
1.25 markus 139: if (options->x11_forwarding == -1)
1.30 markus 140: options->x11_forwarding = 0;
1.25 markus 141: if (options->x11_display_offset == -1)
1.30 markus 142: options->x11_display_offset = 10;
1.42 markus 143: #ifdef XAUTH_PATH
144: if (options->xauth_location == NULL)
145: options->xauth_location = XAUTH_PATH;
146: #endif /* XAUTH_PATH */
1.25 markus 147: if (options->strict_modes == -1)
148: options->strict_modes = 1;
149: if (options->keepalives == -1)
150: options->keepalives = 1;
151: if (options->log_facility == (SyslogFacility) (-1))
152: options->log_facility = SYSLOG_FACILITY_AUTH;
153: if (options->log_level == (LogLevel) (-1))
1.58 markus 154: options->log_level = SYSLOG_LEVEL_INFO;
1.25 markus 155: if (options->rhosts_authentication == -1)
156: options->rhosts_authentication = 0;
157: if (options->rhosts_rsa_authentication == -1)
1.30 markus 158: options->rhosts_rsa_authentication = 0;
1.25 markus 159: if (options->rsa_authentication == -1)
160: options->rsa_authentication = 1;
1.54 markus 161: if (options->pubkey_authentication == -1)
162: options->pubkey_authentication = 1;
1.1 deraadt 163: #ifdef KRB4
1.25 markus 164: if (options->kerberos_authentication == -1)
165: options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
166: if (options->kerberos_or_local_passwd == -1)
167: options->kerberos_or_local_passwd = 1;
168: if (options->kerberos_ticket_cleanup == -1)
169: options->kerberos_ticket_cleanup = 1;
1.4 dugsong 170: #endif /* KRB4 */
171: #ifdef AFS
1.25 markus 172: if (options->kerberos_tgt_passing == -1)
173: options->kerberos_tgt_passing = 0;
174: if (options->afs_token_passing == -1)
175: options->afs_token_passing = k_hasafs();
1.4 dugsong 176: #endif /* AFS */
1.25 markus 177: if (options->password_authentication == -1)
178: options->password_authentication = 1;
1.52 markus 179: if (options->kbd_interactive_authentication == -1)
180: options->kbd_interactive_authentication = 0;
1.63 markus 181: if (options->challenge_reponse_authentication == -1)
182: options->challenge_reponse_authentication = 1;
1.25 markus 183: if (options->permit_empty_passwd == -1)
1.30 markus 184: options->permit_empty_passwd = 0;
1.25 markus 185: if (options->use_login == -1)
186: options->use_login = 0;
1.53 markus 187: if (options->allow_tcp_forwarding == -1)
188: options->allow_tcp_forwarding = 1;
1.38 markus 189: if (options->gateway_ports == -1)
190: options->gateway_ports = 0;
1.46 markus 191: if (options->max_startups == -1)
192: options->max_startups = 10;
1.50 markus 193: if (options->max_startups_rate == -1)
194: options->max_startups_rate = 100; /* 100% */
195: if (options->max_startups_begin == -1)
196: options->max_startups_begin = options->max_startups;
1.64 markus 197: if (options->reverse_mapping_check == -1)
198: options->reverse_mapping_check = 0;
1.1 deraadt 199: }
200:
201: /* Keyword tokens. */
1.25 markus 202: typedef enum {
203: sBadOption, /* == unknown option */
204: sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
205: sPermitRootLogin, sLogFacility, sLogLevel,
206: sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
1.1 deraadt 207: #ifdef KRB4
1.25 markus 208: sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.1 deraadt 209: #endif
210: #ifdef AFS
1.25 markus 211: sKerberosTgtPassing, sAFSTokenPassing,
1.1 deraadt 212: #endif
1.63 markus 213: sChallengeResponseAuthentication,
1.52 markus 214: sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
1.72 stevesk 215: sPrintMotd, sPrintLastLog, sIgnoreRhosts,
216: sX11Forwarding, sX11DisplayOffset,
1.69 stevesk 217: sStrictModes, sEmptyPasswd, sKeepAlives, sCheckMail,
1.53 markus 218: sUseLogin, sAllowTcpForwarding,
219: sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66 markus 220: sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.54 markus 221: sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
1.64 markus 222: sBanner, sReverseMappingCheck
1.1 deraadt 223: } ServerOpCodes;
224:
225: /* Textual representation of the tokens. */
1.25 markus 226: static struct {
227: const char *name;
228: ServerOpCodes opcode;
229: } keywords[] = {
230: { "port", sPort },
231: { "hostkey", sHostKeyFile },
1.54 markus 232: { "hostdsakey", sHostKeyFile }, /* alias */
1.65 stevesk 233: { "pidfile", sPidFile },
1.25 markus 234: { "serverkeybits", sServerKeyBits },
235: { "logingracetime", sLoginGraceTime },
236: { "keyregenerationinterval", sKeyRegenerationTime },
237: { "permitrootlogin", sPermitRootLogin },
238: { "syslogfacility", sLogFacility },
239: { "loglevel", sLogLevel },
240: { "rhostsauthentication", sRhostsAuthentication },
241: { "rhostsrsaauthentication", sRhostsRSAAuthentication },
242: { "rsaauthentication", sRSAAuthentication },
1.54 markus 243: { "pubkeyauthentication", sPubkeyAuthentication },
244: { "dsaauthentication", sPubkeyAuthentication }, /* alias */
1.1 deraadt 245: #ifdef KRB4
1.25 markus 246: { "kerberosauthentication", sKerberosAuthentication },
247: { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
248: { "kerberosticketcleanup", sKerberosTicketCleanup },
1.1 deraadt 249: #endif
1.4 dugsong 250: #ifdef AFS
1.25 markus 251: { "kerberostgtpassing", sKerberosTgtPassing },
252: { "afstokenpassing", sAFSTokenPassing },
1.1 deraadt 253: #endif
1.25 markus 254: { "passwordauthentication", sPasswordAuthentication },
1.52 markus 255: { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
1.63 markus 256: { "challengeresponseauthentication", sChallengeResponseAuthentication },
257: { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
1.25 markus 258: { "checkmail", sCheckMail },
259: { "listenaddress", sListenAddress },
260: { "printmotd", sPrintMotd },
1.72 stevesk 261: { "printlastlog", sPrintLastLog },
1.25 markus 262: { "ignorerhosts", sIgnoreRhosts },
263: { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
264: { "x11forwarding", sX11Forwarding },
265: { "x11displayoffset", sX11DisplayOffset },
1.42 markus 266: { "xauthlocation", sXAuthLocation },
1.25 markus 267: { "strictmodes", sStrictModes },
268: { "permitemptypasswords", sEmptyPasswd },
269: { "uselogin", sUseLogin },
270: { "keepalive", sKeepAlives },
1.53 markus 271: { "allowtcpforwarding", sAllowTcpForwarding },
1.25 markus 272: { "allowusers", sAllowUsers },
273: { "denyusers", sDenyUsers },
274: { "allowgroups", sAllowGroups },
275: { "denygroups", sDenyGroups },
1.33 markus 276: { "ciphers", sCiphers },
1.66 markus 277: { "macs", sMacs },
1.33 markus 278: { "protocol", sProtocol },
1.38 markus 279: { "gatewayports", sGatewayPorts },
1.43 jakob 280: { "subsystem", sSubsystem },
1.46 markus 281: { "maxstartups", sMaxStartups },
1.57 markus 282: { "banner", sBanner },
1.64 markus 283: { "reversemappingcheck", sReverseMappingCheck },
1.25 markus 284: { NULL, 0 }
1.1 deraadt 285: };
286:
1.27 markus 287: /*
1.73 stevesk 288: * Returns the number of the token pointed to by cp or sBadOption.
1.27 markus 289: */
1.1 deraadt 290:
1.34 markus 291: static ServerOpCodes
1.25 markus 292: parse_token(const char *cp, const char *filename,
293: int linenum)
1.1 deraadt 294: {
1.55 markus 295: u_int i;
1.1 deraadt 296:
1.25 markus 297: for (i = 0; keywords[i].name; i++)
1.28 markus 298: if (strcasecmp(cp, keywords[i].name) == 0)
1.25 markus 299: return keywords[i].opcode;
300:
301: fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
302: filename, linenum, cp);
303: return sBadOption;
1.1 deraadt 304: }
305:
1.29 markus 306: /*
307: * add listen address
308: */
1.34 markus 309: void
1.74 ! stevesk 310: add_listen_addr(ServerOptions *options, char *addr, char *port)
! 311: {
! 312: int i;
! 313:
! 314: if (options->num_ports == 0)
! 315: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
! 316: if (port == NULL)
! 317: for (i = 0; i < options->num_ports; i++)
! 318: add_one_listen_addr(options, addr, options->ports[i]);
! 319: else
! 320: add_one_listen_addr(options, addr, atoi(port));
! 321: }
! 322:
! 323: void
! 324: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29 markus 325: {
326: struct addrinfo hints, *ai, *aitop;
327: char strport[NI_MAXSERV];
328: int gaierr;
329:
1.74 ! stevesk 330: memset(&hints, 0, sizeof(hints));
! 331: hints.ai_family = IPv4or6;
! 332: hints.ai_socktype = SOCK_STREAM;
! 333: hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
! 334: snprintf(strport, sizeof strport, "%d", port);
! 335: if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
! 336: fatal("bad addr or host: %s (%s)",
! 337: addr ? addr : "<NULL>",
! 338: gai_strerror(gaierr));
! 339: for (ai = aitop; ai->ai_next; ai = ai->ai_next)
! 340: ;
! 341: ai->ai_next = options->listen_addrs;
! 342: options->listen_addrs = aitop;
1.29 markus 343: }
344:
1.1 deraadt 345: /* Reads the server configuration file. */
346:
1.34 markus 347: void
1.25 markus 348: read_server_config(ServerOptions *options, const char *filename)
1.1 deraadt 349: {
1.25 markus 350: FILE *f;
351: char line[1024];
1.74 ! stevesk 352: char *cp, **charptr, *arg, *p;
1.25 markus 353: int linenum, *intptr, value;
354: int bad_options = 0;
355: ServerOpCodes opcode;
1.43 jakob 356: int i;
1.25 markus 357:
358: f = fopen(filename, "r");
359: if (!f) {
360: perror(filename);
1.1 deraadt 361: exit(1);
1.25 markus 362: }
363: linenum = 0;
364: while (fgets(line, sizeof(line), f)) {
365: linenum++;
1.48 provos 366: cp = line;
367: arg = strdelim(&cp);
368: /* Ignore leading whitespace */
369: if (*arg == '\0')
1.49 markus 370: arg = strdelim(&cp);
1.61 djm 371: if (!arg || !*arg || *arg == '#')
1.25 markus 372: continue;
1.54 markus 373: intptr = NULL;
374: charptr = NULL;
1.47 ho 375: opcode = parse_token(arg, filename, linenum);
1.25 markus 376: switch (opcode) {
377: case sBadOption:
378: bad_options++;
379: continue;
380: case sPort:
1.29 markus 381: /* ignore ports from configfile if cmdline specifies ports */
382: if (options->ports_from_cmdline)
383: continue;
384: if (options->listen_addrs != NULL)
385: fatal("%s line %d: ports must be specified before "
386: "ListenAdress.\n", filename, linenum);
387: if (options->num_ports >= MAX_PORTS)
1.70 millert 388: fatal("%s line %d: too many ports.",
1.34 markus 389: filename, linenum);
1.48 provos 390: arg = strdelim(&cp);
1.47 ho 391: if (!arg || *arg == '\0')
1.70 millert 392: fatal("%s line %d: missing port number.",
1.29 markus 393: filename, linenum);
1.47 ho 394: options->ports[options->num_ports++] = atoi(arg);
1.29 markus 395: break;
396:
397: case sServerKeyBits:
398: intptr = &options->server_key_bits;
1.25 markus 399: parse_int:
1.48 provos 400: arg = strdelim(&cp);
1.47 ho 401: if (!arg || *arg == '\0') {
1.25 markus 402: fprintf(stderr, "%s line %d: missing integer value.\n",
403: filename, linenum);
404: exit(1);
405: }
1.47 ho 406: value = atoi(arg);
1.25 markus 407: if (*intptr == -1)
408: *intptr = value;
409: break;
410:
411: case sLoginGraceTime:
412: intptr = &options->login_grace_time;
413: goto parse_int;
414:
415: case sKeyRegenerationTime:
416: intptr = &options->key_regeneration_time;
417: goto parse_int;
418:
419: case sListenAddress:
1.48 provos 420: arg = strdelim(&cp);
1.74 ! stevesk 421: if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
1.70 millert 422: fatal("%s line %d: missing inet addr.",
1.29 markus 423: filename, linenum);
1.74 ! stevesk 424: if (*arg == '[') {
! 425: if ((p = strchr(arg, ']')) == NULL)
! 426: fatal("%s line %d: bad ipv6 inet addr usage.",
! 427: filename, linenum);
! 428: arg++;
! 429: memmove(p, p+1, strlen(p+1)+1);
! 430: } else if (((p = strchr(arg, ':')) == NULL) ||
! 431: (strchr(p+1, ':') != NULL)) {
! 432: add_listen_addr(options, arg, NULL);
! 433: break;
! 434: }
! 435: if (*p == ':') {
! 436: p++;
! 437: if (*p == '\0')
! 438: fatal("%s line %d: bad inet addr:port usage.",
! 439: filename, linenum);
! 440: else {
! 441: *(p-1) = '\0';
! 442: add_listen_addr(options, arg, p);
! 443: }
! 444: } else if (*p == '\0')
! 445: add_listen_addr(options, arg, NULL);
! 446: else
! 447: fatal("%s line %d: bad inet addr usage.",
! 448: filename, linenum);
1.25 markus 449: break;
450:
451: case sHostKeyFile:
1.54 markus 452: intptr = &options->num_host_key_files;
453: if (*intptr >= MAX_HOSTKEYS) {
1.68 deraadt 454: fprintf(stderr,
455: "%s line %d: too many host keys specified (max %d).\n",
1.54 markus 456: filename, linenum, MAX_HOSTKEYS);
457: exit(1);
458: }
459: charptr = &options->host_key_files[*intptr];
1.42 markus 460: parse_filename:
1.48 provos 461: arg = strdelim(&cp);
1.47 ho 462: if (!arg || *arg == '\0') {
1.25 markus 463: fprintf(stderr, "%s line %d: missing file name.\n",
1.36 markus 464: filename, linenum);
465: exit(1);
466: }
1.54 markus 467: if (*charptr == NULL) {
1.47 ho 468: *charptr = tilde_expand_filename(arg, getuid());
1.54 markus 469: /* increase optional counter */
470: if (intptr != NULL)
471: *intptr = *intptr + 1;
472: }
1.36 markus 473: break;
474:
475: case sPidFile:
476: charptr = &options->pid_file;
1.42 markus 477: goto parse_filename;
1.25 markus 478:
479: case sPermitRootLogin:
480: intptr = &options->permit_root_login;
1.48 provos 481: arg = strdelim(&cp);
1.47 ho 482: if (!arg || *arg == '\0') {
1.71 stevesk 483: fprintf(stderr, "%s line %d: missing yes/"
484: "without-password/forced-commands-only/no "
485: "argument.\n", filename, linenum);
1.25 markus 486: exit(1);
487: }
1.47 ho 488: if (strcmp(arg, "without-password") == 0)
1.67 markus 489: value = PERMIT_NO_PASSWD;
490: else if (strcmp(arg, "forced-commands-only") == 0)
491: value = PERMIT_FORCED_ONLY;
1.47 ho 492: else if (strcmp(arg, "yes") == 0)
1.67 markus 493: value = PERMIT_YES;
1.47 ho 494: else if (strcmp(arg, "no") == 0)
1.67 markus 495: value = PERMIT_NO;
1.25 markus 496: else {
1.67 markus 497: fprintf(stderr, "%s line %d: Bad yes/"
498: "without-password/forced-commands-only/no "
499: "argument: %s\n", filename, linenum, arg);
1.25 markus 500: exit(1);
501: }
502: if (*intptr == -1)
503: *intptr = value;
504: break;
505:
506: case sIgnoreRhosts:
507: intptr = &options->ignore_rhosts;
508: parse_flag:
1.48 provos 509: arg = strdelim(&cp);
1.47 ho 510: if (!arg || *arg == '\0') {
1.25 markus 511: fprintf(stderr, "%s line %d: missing yes/no argument.\n",
512: filename, linenum);
513: exit(1);
514: }
1.47 ho 515: if (strcmp(arg, "yes") == 0)
1.25 markus 516: value = 1;
1.47 ho 517: else if (strcmp(arg, "no") == 0)
1.25 markus 518: value = 0;
519: else {
520: fprintf(stderr, "%s line %d: Bad yes/no argument: %s\n",
1.47 ho 521: filename, linenum, arg);
1.25 markus 522: exit(1);
523: }
524: if (*intptr == -1)
525: *intptr = value;
526: break;
527:
528: case sIgnoreUserKnownHosts:
529: intptr = &options->ignore_user_known_hosts;
1.31 markus 530: goto parse_flag;
1.25 markus 531:
532: case sRhostsAuthentication:
533: intptr = &options->rhosts_authentication;
534: goto parse_flag;
535:
536: case sRhostsRSAAuthentication:
537: intptr = &options->rhosts_rsa_authentication;
538: goto parse_flag;
539:
540: case sRSAAuthentication:
541: intptr = &options->rsa_authentication;
1.39 markus 542: goto parse_flag;
543:
1.54 markus 544: case sPubkeyAuthentication:
545: intptr = &options->pubkey_authentication;
1.25 markus 546: goto parse_flag;
547:
1.1 deraadt 548: #ifdef KRB4
1.25 markus 549: case sKerberosAuthentication:
550: intptr = &options->kerberos_authentication;
551: goto parse_flag;
552:
553: case sKerberosOrLocalPasswd:
554: intptr = &options->kerberos_or_local_passwd;
555: goto parse_flag;
556:
557: case sKerberosTicketCleanup:
558: intptr = &options->kerberos_ticket_cleanup;
559: goto parse_flag;
1.1 deraadt 560: #endif
1.25 markus 561:
1.4 dugsong 562: #ifdef AFS
1.25 markus 563: case sKerberosTgtPassing:
564: intptr = &options->kerberos_tgt_passing;
565: goto parse_flag;
566:
567: case sAFSTokenPassing:
568: intptr = &options->afs_token_passing;
569: goto parse_flag;
570: #endif
571:
572: case sPasswordAuthentication:
573: intptr = &options->password_authentication;
1.52 markus 574: goto parse_flag;
575:
576: case sKbdInteractiveAuthentication:
577: intptr = &options->kbd_interactive_authentication;
1.25 markus 578: goto parse_flag;
579:
580: case sCheckMail:
581: intptr = &options->check_mail;
582: goto parse_flag;
1.10 markus 583:
1.63 markus 584: case sChallengeResponseAuthentication:
585: intptr = &options->challenge_reponse_authentication;
1.25 markus 586: goto parse_flag;
587:
588: case sPrintMotd:
589: intptr = &options->print_motd;
1.72 stevesk 590: goto parse_flag;
591:
592: case sPrintLastLog:
593: intptr = &options->print_lastlog;
1.25 markus 594: goto parse_flag;
595:
596: case sX11Forwarding:
597: intptr = &options->x11_forwarding;
598: goto parse_flag;
599:
600: case sX11DisplayOffset:
601: intptr = &options->x11_display_offset;
602: goto parse_int;
603:
1.42 markus 604: case sXAuthLocation:
605: charptr = &options->xauth_location;
606: goto parse_filename;
1.65 stevesk 607:
1.25 markus 608: case sStrictModes:
609: intptr = &options->strict_modes;
610: goto parse_flag;
611:
612: case sKeepAlives:
613: intptr = &options->keepalives;
614: goto parse_flag;
615:
616: case sEmptyPasswd:
617: intptr = &options->permit_empty_passwd;
618: goto parse_flag;
619:
620: case sUseLogin:
621: intptr = &options->use_login;
1.38 markus 622: goto parse_flag;
623:
624: case sGatewayPorts:
625: intptr = &options->gateway_ports;
1.64 markus 626: goto parse_flag;
627:
628: case sReverseMappingCheck:
629: intptr = &options->reverse_mapping_check;
1.25 markus 630: goto parse_flag;
631:
632: case sLogFacility:
633: intptr = (int *) &options->log_facility;
1.48 provos 634: arg = strdelim(&cp);
1.47 ho 635: value = log_facility_number(arg);
1.25 markus 636: if (value == (SyslogFacility) - 1)
1.70 millert 637: fatal("%.200s line %d: unsupported log facility '%s'",
1.47 ho 638: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 639: if (*intptr == -1)
640: *intptr = (SyslogFacility) value;
641: break;
642:
643: case sLogLevel:
644: intptr = (int *) &options->log_level;
1.48 provos 645: arg = strdelim(&cp);
1.47 ho 646: value = log_level_number(arg);
1.25 markus 647: if (value == (LogLevel) - 1)
1.70 millert 648: fatal("%.200s line %d: unsupported log level '%s'",
1.47 ho 649: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 650: if (*intptr == -1)
651: *intptr = (LogLevel) value;
652: break;
1.53 markus 653:
654: case sAllowTcpForwarding:
655: intptr = &options->allow_tcp_forwarding;
656: goto parse_flag;
1.25 markus 657:
658: case sAllowUsers:
1.48 provos 659: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33 markus 660: if (options->num_allow_users >= MAX_ALLOW_USERS)
1.70 millert 661: fatal("%s line %d: too many allow users.",
1.33 markus 662: filename, linenum);
1.47 ho 663: options->allow_users[options->num_allow_users++] = xstrdup(arg);
1.25 markus 664: }
665: break;
666:
667: case sDenyUsers:
1.48 provos 668: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33 markus 669: if (options->num_deny_users >= MAX_DENY_USERS)
1.70 millert 670: fatal( "%s line %d: too many deny users.",
1.33 markus 671: filename, linenum);
1.47 ho 672: options->deny_users[options->num_deny_users++] = xstrdup(arg);
1.25 markus 673: }
674: break;
675:
676: case sAllowGroups:
1.48 provos 677: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33 markus 678: if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
1.70 millert 679: fatal("%s line %d: too many allow groups.",
1.33 markus 680: filename, linenum);
1.47 ho 681: options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
1.25 markus 682: }
683: break;
684:
685: case sDenyGroups:
1.48 provos 686: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.33 markus 687: if (options->num_deny_groups >= MAX_DENY_GROUPS)
1.70 millert 688: fatal("%s line %d: too many deny groups.",
1.33 markus 689: filename, linenum);
1.47 ho 690: options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
1.25 markus 691: }
1.33 markus 692: break;
693:
694: case sCiphers:
1.48 provos 695: arg = strdelim(&cp);
1.47 ho 696: if (!arg || *arg == '\0')
1.41 markus 697: fatal("%s line %d: Missing argument.", filename, linenum);
1.47 ho 698: if (!ciphers_valid(arg))
1.40 markus 699: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1.47 ho 700: filename, linenum, arg ? arg : "<NONE>");
1.33 markus 701: if (options->ciphers == NULL)
1.47 ho 702: options->ciphers = xstrdup(arg);
1.66 markus 703: break;
704:
705: case sMacs:
706: arg = strdelim(&cp);
707: if (!arg || *arg == '\0')
708: fatal("%s line %d: Missing argument.", filename, linenum);
709: if (!mac_valid(arg))
710: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
711: filename, linenum, arg ? arg : "<NONE>");
712: if (options->macs == NULL)
713: options->macs = xstrdup(arg);
1.33 markus 714: break;
715:
716: case sProtocol:
717: intptr = &options->protocol;
1.48 provos 718: arg = strdelim(&cp);
1.47 ho 719: if (!arg || *arg == '\0')
1.41 markus 720: fatal("%s line %d: Missing argument.", filename, linenum);
1.47 ho 721: value = proto_spec(arg);
1.33 markus 722: if (value == SSH_PROTO_UNKNOWN)
723: fatal("%s line %d: Bad protocol spec '%s'.",
1.47 ho 724: filename, linenum, arg ? arg : "<NONE>");
1.33 markus 725: if (*intptr == SSH_PROTO_UNKNOWN)
726: *intptr = value;
1.43 jakob 727: break;
728:
729: case sSubsystem:
730: if(options->num_subsystems >= MAX_SUBSYSTEMS) {
731: fatal("%s line %d: too many subsystems defined.",
732: filename, linenum);
733: }
1.48 provos 734: arg = strdelim(&cp);
1.47 ho 735: if (!arg || *arg == '\0')
1.43 jakob 736: fatal("%s line %d: Missing subsystem name.",
737: filename, linenum);
738: for (i = 0; i < options->num_subsystems; i++)
1.47 ho 739: if(strcmp(arg, options->subsystem_name[i]) == 0)
1.43 jakob 740: fatal("%s line %d: Subsystem '%s' already defined.",
1.47 ho 741: filename, linenum, arg);
742: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1.48 provos 743: arg = strdelim(&cp);
1.47 ho 744: if (!arg || *arg == '\0')
1.43 jakob 745: fatal("%s line %d: Missing subsystem command.",
746: filename, linenum);
1.47 ho 747: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.43 jakob 748: options->num_subsystems++;
1.25 markus 749: break;
1.46 markus 750:
751: case sMaxStartups:
1.50 markus 752: arg = strdelim(&cp);
753: if (!arg || *arg == '\0')
754: fatal("%s line %d: Missing MaxStartups spec.",
755: filename, linenum);
756: if (sscanf(arg, "%d:%d:%d",
757: &options->max_startups_begin,
758: &options->max_startups_rate,
759: &options->max_startups) == 3) {
760: if (options->max_startups_begin >
761: options->max_startups ||
762: options->max_startups_rate > 100 ||
763: options->max_startups_rate < 1)
764: fatal("%s line %d: Illegal MaxStartups spec.",
765: filename, linenum);
766: break;
767: }
1.46 markus 768: intptr = &options->max_startups;
769: goto parse_int;
1.25 markus 770:
1.57 markus 771: case sBanner:
772: charptr = &options->banner;
773: goto parse_filename;
1.65 stevesk 774:
1.25 markus 775: default:
776: fprintf(stderr, "%s line %d: Missing handler for opcode %s (%d)\n",
1.47 ho 777: filename, linenum, arg, opcode);
1.25 markus 778: exit(1);
1.13 markus 779: }
1.48 provos 780: if ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1.65 stevesk 781: fprintf(stderr,
1.47 ho 782: "%s line %d: garbage at end of line; \"%.200s\".\n",
783: filename, linenum, arg);
1.25 markus 784: exit(1);
1.13 markus 785: }
1.1 deraadt 786: }
1.25 markus 787: fclose(f);
788: if (bad_options > 0) {
789: fprintf(stderr, "%s: terminating, %d bad configuration options\n",
790: filename, bad_options);
791: exit(1);
1.1 deraadt 792: }
793: }