]> andersk Git - openssh.git/blobdiff - readconf.c
- Big OpenBSD CVS update (mainly beginnings of SSH2 infrastructure)
[openssh.git] / readconf.c
index f2387a313e632e2921df4c3d97530afc0fe0a700..c1aa3ceb8684a14dc658a805159d019fbc18926c 100644 (file)
@@ -19,6 +19,7 @@ RCSID("$Id$");
 #include "ssh.h"
 #include "cipher.h"
 #include "readconf.h"
+#include "match.h"
 #include "xmalloc.h"
 
 /* Format of the configuration file:
@@ -158,17 +159,17 @@ static struct {
 #define WHITESPACE " \t\r\n"
 
 
-/* Adds a local TCP/IP port forward to options.  Never returns if there
-   is an error. */
+/*
+ * Adds a local TCP/IP port forward to options.  Never returns if there is an
+ * error.
+ */
 
 void 
-add_local_forward(Options *options, int port, const char *host,
-                 int host_port)
+add_local_forward(Options *options, u_short port, const char *host,
+                 u_short host_port)
 {
        Forward *fwd;
        extern uid_t original_real_uid;
-       if ((port & 0xffff) != port)
-               fatal("Requested forwarding of nonexistent port %d.", port);
        if (port < IPPORT_RESERVED && original_real_uid != 0)
                fatal("Privileged ports can only be forwarded by root.\n");
        if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
@@ -179,12 +180,14 @@ add_local_forward(Options *options, int port, const char *host,
        fwd->host_port = host_port;
 }
 
-/* Adds a remote TCP/IP port forward to options.  Never returns if there
-   is an error. */
+/*
+ * Adds a remote TCP/IP port forward to options.  Never returns if there is
+ * an error.
+ */
 
 void 
-add_remote_forward(Options *options, int port, const char *host,
-                  int host_port)
+add_remote_forward(Options *options, u_short port, const char *host,
+                  u_short host_port)
 {
        Forward *fwd;
        if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
@@ -196,8 +199,10 @@ add_remote_forward(Options *options, int port, const char *host,
        fwd->host_port = host_port;
 }
 
-/* Returns the number of the token pointed to by cp of length len.
-   Never returns if the token is not known. */
+/*
+ * Returns the number of the token pointed to by cp of length len. Never
+ * returns if the token is not known.
+ */
 
 static OpCodes 
 parse_token(const char *cp, const char *filename, int linenum)
@@ -205,7 +210,7 @@ parse_token(const char *cp, const char *filename, int linenum)
        unsigned int i;
 
        for (i = 0; keywords[i].name; i++)
-               if (strcmp(cp, keywords[i].name) == 0)
+               if (strcasecmp(cp, keywords[i].name) == 0)
                        return keywords[i].opcode;
 
        fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
@@ -213,37 +218,33 @@ parse_token(const char *cp, const char *filename, int linenum)
        return oBadOption;
 }
 
-/* Processes a single option line as used in the configuration files.
-   This only sets those values that have not already been set. */
+/*
+ * Processes a single option line as used in the configuration files. This
+ * only sets those values that have not already been set.
+ */
 
 int
 process_config_line(Options *options, const char *host,
                    char *line, const char *filename, int linenum,
                    int *activep)
 {
-       char buf[256], *cp, *string, **charptr;
-       int opcode, *intptr, value, fwd_port, fwd_host_port;
+       char buf[256], *cp, *string, **charptr, *cp2;
+       int opcode, *intptr, value;
+       u_short fwd_port, fwd_host_port;
 
        /* Skip leading whitespace. */
        cp = line + strspn(line, WHITESPACE);
        if (!*cp || *cp == '\n' || *cp == '#')
                return 0;
 
-       /* Get the keyword. (Each line is supposed to begin with a
-          keyword). */
+       /* Get the keyword. (Each line is supposed to begin with a keyword). */
        cp = strtok(cp, WHITESPACE);
-       {
-               char *t = cp;
-               for (; *t != 0; t++)
-                       if ('A' <= *t && *t <= 'Z')
-                               *t = *t - 'A' + 'a';    /* tolower */
-
-       }
        opcode = parse_token(cp, filename, linenum);
 
        switch (opcode) {
        case oBadOption:
-               return -1;      /* don't panic, but count bad options */
+               /* don't panic, but count bad options */
+               return -1;
                /* NOTREACHED */
        case oForwardAgent:
                intptr = &options->forward_agent;
@@ -419,17 +420,11 @@ parse_int:
                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                if (cp[0] < '0' || cp[0] > '9')
                        fatal("%.200s line %d: Bad number.", filename, linenum);
-#if 0
-               value = atoi(cp);
-#else
-               {
-                       char *ptr;
-                       value = strtol(cp, &ptr, 0);    /* Octal, decimal, or
-                                                          hex format? */
-                       if (cp == ptr)
-                               fatal("%.200s line %d: Bad number.", filename, linenum);
-               }
-#endif
+
+               /* Octal, decimal, or hex format? */
+               value = strtol(cp, &cp2, 0);
+               if (cp == cp2)
+                       fatal("%.200s line %d: Bad number.", filename, linenum);
                if (*activep && *intptr == -1)
                        *intptr = value;
                break;
@@ -472,7 +467,7 @@ parse_int:
                if (!cp)
                        fatal("%.200s line %d: Missing second argument.",
                              filename, linenum);
-               if (sscanf(cp, "%255[^:]:%d", buf, &fwd_host_port) != 2)
+               if (sscanf(cp, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
                        fatal("%.200s line %d: Badly formatted host:port.",
                              filename, linenum);
                if (*activep)
@@ -491,7 +486,7 @@ parse_int:
                if (!cp)
                        fatal("%.200s line %d: Missing second argument.",
                              filename, linenum);
-               if (sscanf(cp, "%255[^:]:%d", buf, &fwd_host_port) != 2)
+               if (sscanf(cp, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
                        fatal("%.200s line %d: Badly formatted host:port.",
                              filename, linenum);
                if (*activep)
@@ -506,8 +501,7 @@ parse_int:
                                *activep = 1;
                                break;
                        }
-               /* Avoid garbage check below, as strtok already returned
-                  NULL. */
+               /* Avoid garbage check below, as strtok already returned NULL. */
                return 0;
 
        case oEscapeChar:
@@ -544,9 +538,11 @@ parse_int:
 }
 
 
-/* Reads the config file and modifies the options accordingly.  Options should
-   already be initialized before this call.  This never returns if there
-   is an error.  If the file does not exist, this returns immediately. */
+/*
+ * Reads the config file and modifies the options accordingly.  Options
+ * should already be initialized before this call.  This never returns if
+ * there is an error.  If the file does not exist, this returns immediately.
+ */
 
 void 
 read_config_file(const char *filename, const char *host, Options *options)
@@ -563,8 +559,10 @@ read_config_file(const char *filename, const char *host, Options *options)
 
        debug("Reading configuration data %.200s", filename);
 
-       /* Mark that we are now processing the options.  This flag is
-          turned on/off by Host specifications. */
+       /*
+        * Mark that we are now processing the options.  This flag is turned
+        * on/off by Host specifications.
+        */
        active = 1;
        linenum = 0;
        while (fgets(line, sizeof(line), f)) {
@@ -579,10 +577,12 @@ read_config_file(const char *filename, const char *host, Options *options)
                      filename, bad_options);
 }
 
-/* Initializes options to special values that indicate that they have not
-   yet been set.  Read_config_file will only set options with this value.
-   Options are processed in the following order: command line, user config
-   file, system config file.  Last, fill_default_options is called. */
+/*
+ * Initializes options to special values that indicate that they have not yet
+ * been set.  Read_config_file will only set options with this value. Options
+ * are processed in the following order: command line, user config file,
+ * system config file.  Last, fill_default_options is called.
+ */
 
 void 
 initialize_options(Options * options)
@@ -628,8 +628,10 @@ initialize_options(Options * options)
        options->log_level = (LogLevel) - 1;
 }
 
-/* Called after processing other sources of option data, this fills those
-   options for which no value has been specified with their default values. */
+/*
+ * Called after processing other sources of option data, this fills those
+ * options for which no value has been specified with their default values.
+ */
 
 void 
 fill_default_options(Options * options)
@@ -637,7 +639,7 @@ fill_default_options(Options * options)
        if (options->forward_agent == -1)
                options->forward_agent = 1;
        if (options->forward_x11 == -1)
-               options->forward_x11 = 1;
+               options->forward_x11 = 0;
        if (options->gateway_ports == -1)
                options->gateway_ports = 0;
        if (options->use_privileged_port == -1)
This page took 0.048335 seconds and 4 git commands to generate.