summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--servconf.c126
2 files changed, 60 insertions, 70 deletions
diff --git a/ChangeLog b/ChangeLog
index 15320284c..74c3f90f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,10 @@
17 [sftp-server.c] 17 [sftp-server.c]
18 the protocol version should be unsigned; bz#1913 reported by mb AT 18 the protocol version should be unsigned; bz#1913 reported by mb AT
19 smartftp.com 19 smartftp.com
20 - djm@cvs.openbsd.org 2011/06/17 21:47:35
21 [servconf.c]
22 factor out multi-choice option parsing into a parse_multistate label
23 and some support structures; ok dtucker@
20 24
2120110603 2520110603
22 - (dtucker) [README version.h contrib/caldera/openssh.spec 26 - (dtucker) [README version.h contrib/caldera/openssh.spec
diff --git a/servconf.c b/servconf.c
index 74710c41f..909ad7d8f 100644
--- a/servconf.c
+++ b/servconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: servconf.c,v 1.219 2011/05/23 03:30:07 djm Exp $ */ 1/* $OpenBSD: servconf.c,v 1.220 2011/06/17 21:47:35 djm Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -671,6 +671,37 @@ match_cfg_line(char **condition, int line, const char *user, const char *host,
671 671
672#define WHITESPACE " \t\r\n" 672#define WHITESPACE " \t\r\n"
673 673
674/* Multistate option parsing */
675struct multistate {
676 char *key;
677 int value;
678};
679static const struct multistate multistate_addressfamily[] = {
680 { "inet", AF_INET },
681 { "inet6", AF_INET6 },
682 { "any", AF_UNSPEC },
683 { NULL, -1 }
684};
685static const struct multistate multistate_permitrootlogin[] = {
686 { "without-password", PERMIT_NO_PASSWD },
687 { "forced-commands-only", PERMIT_FORCED_ONLY },
688 { "yes", PERMIT_YES },
689 { "no", PERMIT_NO },
690 { NULL, -1 }
691};
692static const struct multistate multistate_compression[] = {
693 { "delayed", COMP_DELAYED },
694 { "yes", COMP_ZLIB },
695 { "no", COMP_NONE },
696 { NULL, -1 }
697};
698static const struct multistate multistate_gatewayports[] = {
699 { "clientspecified", 2 },
700 { "yes", 1 },
701 { "no", 0 },
702 { NULL, -1 }
703};
704
674int 705int
675process_server_config_line(ServerOptions *options, char *line, 706process_server_config_line(ServerOptions *options, char *line,
676 const char *filename, int linenum, int *activep, const char *user, 707 const char *filename, int linenum, int *activep, const char *user,
@@ -684,6 +715,7 @@ process_server_config_line(ServerOptions *options, char *line,
684 int port; 715 int port;
685 u_int i, flags = 0; 716 u_int i, flags = 0;
686 size_t len; 717 size_t len;
718 const struct multistate *multistate_ptr;
687 719
688 cp = line; 720 cp = line;
689 if ((arg = strdelim(&cp)) == NULL) 721 if ((arg = strdelim(&cp)) == NULL)
@@ -799,24 +831,27 @@ process_server_config_line(ServerOptions *options, char *line,
799 break; 831 break;
800 832
801 case sAddressFamily: 833 case sAddressFamily:
834 intptr = &options->address_family;
835 multistate_ptr = multistate_addressfamily;
836 if (options->listen_addrs != NULL)
837 fatal("%s line %d: address family must be specified "
838 "before ListenAddress.", filename, linenum);
839 parse_multistate:
802 arg = strdelim(&cp); 840 arg = strdelim(&cp);
803 if (!arg || *arg == '\0') 841 if (!arg || *arg == '\0')
804 fatal("%s line %d: missing address family.", 842 fatal("%s line %d: missing argument.",
805 filename, linenum); 843 filename, linenum);
806 intptr = &options->address_family; 844 value = -1;
807 if (options->listen_addrs != NULL) 845 for (i = 0; multistate_ptr[i].key != NULL; i++) {
808 fatal("%s line %d: address family must be specified before " 846 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
809 "ListenAddress.", filename, linenum); 847 value = multistate_ptr[i].value;
810 if (strcasecmp(arg, "inet") == 0) 848 break;
811 value = AF_INET; 849 }
812 else if (strcasecmp(arg, "inet6") == 0) 850 }
813 value = AF_INET6; 851 if (value == -1)
814 else if (strcasecmp(arg, "any") == 0) 852 fatal("%s line %d: unsupported option \"%s\".",
815 value = AF_UNSPEC;
816 else
817 fatal("%s line %d: unsupported address family \"%s\".",
818 filename, linenum, arg); 853 filename, linenum, arg);
819 if (*intptr == -1) 854 if (*activep && *intptr == -1)
820 *intptr = value; 855 *intptr = value;
821 break; 856 break;
822 857
@@ -855,27 +890,8 @@ process_server_config_line(ServerOptions *options, char *line,
855 890
856 case sPermitRootLogin: 891 case sPermitRootLogin:
857 intptr = &options->permit_root_login; 892 intptr = &options->permit_root_login;
858 arg = strdelim(&cp); 893 multistate_ptr = multistate_permitrootlogin;
859 if (!arg || *arg == '\0') 894 goto parse_multistate;
860 fatal("%s line %d: missing yes/"
861 "without-password/forced-commands-only/no "
862 "argument.", filename, linenum);
863 value = 0; /* silence compiler */
864 if (strcmp(arg, "without-password") == 0)
865 value = PERMIT_NO_PASSWD;
866 else if (strcmp(arg, "forced-commands-only") == 0)
867 value = PERMIT_FORCED_ONLY;
868 else if (strcmp(arg, "yes") == 0)
869 value = PERMIT_YES;
870 else if (strcmp(arg, "no") == 0)
871 value = PERMIT_NO;
872 else
873 fatal("%s line %d: Bad yes/"
874 "without-password/forced-commands-only/no "
875 "argument: %s", filename, linenum, arg);
876 if (*activep && *intptr == -1)
877 *intptr = value;
878 break;
879 895
880 case sIgnoreRhosts: 896 case sIgnoreRhosts:
881 intptr = &options->ignore_rhosts; 897 intptr = &options->ignore_rhosts;
@@ -1006,43 +1022,13 @@ process_server_config_line(ServerOptions *options, char *line,
1006 1022
1007 case sCompression: 1023 case sCompression:
1008 intptr = &options->compression; 1024 intptr = &options->compression;
1009 arg = strdelim(&cp); 1025 multistate_ptr = multistate_compression;
1010 if (!arg || *arg == '\0') 1026 goto parse_multistate;
1011 fatal("%s line %d: missing yes/no/delayed "
1012 "argument.", filename, linenum);
1013 value = 0; /* silence compiler */
1014 if (strcmp(arg, "delayed") == 0)
1015 value = COMP_DELAYED;
1016 else if (strcmp(arg, "yes") == 0)
1017 value = COMP_ZLIB;
1018 else if (strcmp(arg, "no") == 0)
1019 value = COMP_NONE;
1020 else
1021 fatal("%s line %d: Bad yes/no/delayed "
1022 "argument: %s", filename, linenum, arg);
1023 if (*intptr == -1)
1024 *intptr = value;
1025 break;
1026 1027
1027 case sGatewayPorts: 1028 case sGatewayPorts:
1028 intptr = &options->gateway_ports; 1029 intptr = &options->gateway_ports;
1029 arg = strdelim(&cp); 1030 multistate_ptr = multistate_gatewayports;
1030 if (!arg || *arg == '\0') 1031 goto parse_multistate;
1031 fatal("%s line %d: missing yes/no/clientspecified "
1032 "argument.", filename, linenum);
1033 value = 0; /* silence compiler */
1034 if (strcmp(arg, "clientspecified") == 0)
1035 value = 2;
1036 else if (strcmp(arg, "yes") == 0)
1037 value = 1;
1038 else if (strcmp(arg, "no") == 0)
1039 value = 0;
1040 else
1041 fatal("%s line %d: Bad yes/no/clientspecified "
1042 "argument: %s", filename, linenum, arg);
1043 if (*activep && *intptr == -1)
1044 *intptr = value;
1045 break;
1046 1032
1047 case sUseDNS: 1033 case sUseDNS:
1048 intptr = &options->use_dns; 1034 intptr = &options->use_dns;