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