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