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