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