"Fossies" - the Fresh Open Source Software Archive

Member "pidentd-3.0.19/src/conf.c" (21 Jan 1999, 5853 Bytes) of package /linux/misc/old/pidentd-3.0.19.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "conf.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2 ** conf.c - Parse the config file
    3 **
    4 ** Copyright (c) 1997-1998 Peter Eriksson <pen@lysator.liu.se>
    5 **
    6 ** This program is free software; you can redistribute it and/or
    7 ** modify it as you wish - as long as you don't claim that you wrote
    8 ** it.
    9 **
   10 ** This program is distributed in the hope that it will be useful,
   11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   13 */
   14 
   15 #include "config.h"
   16 
   17 #include <stdio.h>
   18 #include <ctype.h>
   19 #include <string.h>
   20 #include <syslog.h>
   21 
   22 #include "pidentd.h"
   23 
   24 
   25 int
   26 conf_parse(const char *path,
   27        int silent)
   28 {
   29     FILE *fp;
   30     char buf[1024], *cp, *sp, *arg;
   31     int line;
   32     
   33 
   34     fp = fopen(path, "r");
   35     if (fp == NULL)
   36     {
   37     if (!silent)
   38         syslog(LOG_ERR, "fopen(\"%s\"): %m", path);
   39     
   40     return -1;
   41     }
   42 
   43     line = 0;
   44     while (fgets(buf, sizeof(buf), fp))
   45     {
   46     ++line;
   47     
   48     cp = strchr(buf, '#');
   49     if (cp != NULL)
   50         *cp = '\0';
   51 
   52     cp = s_strtok_r(buf, " \t\r\n", &sp);
   53     if (cp == NULL)
   54         continue;
   55 
   56     arg = s_strtok_r(NULL, " \t\r\n", &sp);
   57     if (arg == NULL || strcmp(arg, "=") != 0)
   58     {
   59         syslog(LOG_ERR, "%s: %d: missing '='", path, line);
   60         continue;
   61     }
   62 
   63     arg = s_strtok_r(NULL, "\r\n", &sp);
   64     if (arg == NULL)
   65     {
   66         syslog(LOG_ERR, "%s: %d: missing argument", path, line);
   67         continue;
   68     }
   69 
   70 
   71     if (debug)
   72         fprintf(stderr, "conf_parse(\"%s\"), line #%d: %s = %s\n",
   73             path, line, cp, arg ? arg : "");
   74 
   75 
   76     /* Global directives */
   77     
   78     if (strcasecmp(cp, "include") == 0)
   79     {
   80         conf_parse(arg, silent);
   81     }
   82 
   83     
   84     
   85     /* Global variables */
   86     
   87     else if (strcasecmp(cp, "syslog:facility") == 0)
   88     {
   89         int code = syslog_str2fac(arg);
   90         
   91         if (code < 0)
   92         syslog(LOG_ERR, "%s: %d: invalid syslog facility: %s",
   93                path, line, arg);
   94         else
   95         {
   96         closelog();
   97         s_openlog(argv0, LOG_PID|LOG_ODELAY, code);
   98         }
   99     }
  100 
  101     
  102     /* Server variables */
  103     
  104     else if (strcasecmp(cp, "server:port") == 0)
  105     {
  106         if (str2port(arg, &listen_port) < 0)
  107         syslog(LOG_ERR, "%s: %d: invalid port: %s",
  108                path, line, arg);
  109     }
  110 
  111     else if (strcasecmp(cp, "server:backlog") == 0)
  112     {
  113         if (str2int(arg, &listen_backlog) < 0)
  114         syslog(LOG_ERR, "%s: %d: invalid number: %s",
  115                path, line, arg);
  116     }
  117 
  118 #if 0 /* Enable when we have a str2addr() */
  119     else if (strcasecmp(cp, "server:address") == 0)
  120     {
  121         if (str2addr(arg, &listen_address) < 0)
  122         syslog(LOG_ERR, "%s: %d: invalid address: %s",
  123                path, line, arg);
  124     }
  125 #endif
  126     
  127     else if (strcasecmp(cp, "server:user") == 0)
  128     {
  129         if (str2uid(arg, &server_uid, &server_gid) < 0)
  130         syslog(LOG_ERR, "%s: %d: invalid user: %s",
  131                path, line, arg);
  132     }
  133 
  134     
  135     else if (strcasecmp(cp, "server:group") == 0)
  136     {
  137         if (str2gid(arg, &server_gid) < 0)
  138         syslog(LOG_ERR, "%s: %d: invalid group: %s",
  139                path, line, arg);
  140     }
  141 
  142     
  143     else if (strcasecmp(cp, "server:pid-file") == 0)
  144     {
  145          if (str2str(arg, &pidfile_path) < 0)
  146          syslog(LOG_ERR, "%s: %d: invalid string: %s",
  147             path, line, arg);
  148     }
  149 
  150     else if (strcasecmp(cp, "server:max-requests") == 0)
  151     {
  152          if (str2int(arg, &requests_max) < 0)
  153          syslog(LOG_ERR, "%s: %d: invalid integer: %s",
  154             path, line, arg);
  155     }
  156 
  157 
  158     /* Protocol variables */
  159     
  160     else if (strcasecmp(cp, "protocol:extensions") == 0)
  161     {
  162         if (str2bool(arg, &extensions_enabled) < 0)
  163         syslog(LOG_ERR, "%s: %d: invalid bool: %s",
  164                path, line, arg);
  165     }
  166     
  167     else if (strcasecmp(cp, "protocol:multiquery") == 0)
  168     {
  169         if (str2bool(arg, &multiquery_enabled) < 0)
  170         syslog(LOG_ERR, "%s: %d: invalid bool: %s",
  171                path, line, arg);
  172     }
  173 
  174     else if (strcasecmp(cp, "protocol:timeout") == 0)
  175     {
  176         if (str2int(arg, &request_timeout) < 0)
  177         syslog(LOG_ERR, "%s: %d: invalid integer: %s",
  178                path, line, arg);
  179     }
  180 
  181 
  182     /* Result variables */
  183     
  184     else if (strcasecmp(cp, "result:noident") == 0)
  185     {
  186         if (str2bool(arg, &noident_flag) < 0)
  187         syslog(LOG_ERR, "%s: %d: invalid bool: %s",
  188                path, line, arg);
  189     }
  190 
  191     
  192     else if (strcasecmp(cp, "result:uid-only") == 0)
  193     {
  194         if (str2bool(arg, &uidonly_flag) < 0)
  195         syslog(LOG_ERR, "%s: %d: invalid bool: %s",
  196                path, line, arg);
  197     }
  198 
  199 #ifdef HAVE_LIBDES
  200     else if (strcasecmp(cp, "result:encrypt") == 0)
  201     {
  202         if (str2bool(arg, &encrypt_flag) < 0)
  203         syslog(LOG_ERR, "%s: %d: invalid bool: %s",
  204                path, line, arg);
  205     }
  206 #endif
  207     
  208     else if (strcasecmp(cp, "result:charset") == 0)
  209     {
  210         if (str2str(arg, &charset) < 0)
  211         syslog(LOG_ERR, "%s: %d: invalid string: %s",
  212                path, line, arg);
  213     }
  214 
  215     else if (strcasecmp(cp, "result:opsys") == 0)
  216     {
  217         if (str2str(arg, &opsys) < 0)
  218         syslog(LOG_ERR, "%s: %d: invalid string: %s",
  219                path, line, arg);
  220     }
  221 
  222     else if (strcasecmp(cp, "result:syslog-level") == 0)
  223     {
  224         if (arg && strcasecmp(arg, "none") == 0)
  225         result_syslog_level = -1;
  226         else
  227         {
  228         int code = syslog_str2lev(arg);
  229         
  230         if (code < 0)
  231             syslog(LOG_ERR, "%s: %d: invalid syslog level: %s",
  232                path, line, arg);
  233         else
  234             result_syslog_level = code;
  235         }
  236     }
  237 
  238     
  239     /* Kernel variables */
  240     
  241     else if (strcasecmp(cp, "kernel:threads") == 0)
  242     {
  243         if (str2int(arg, &kernel_threads) < 0)
  244         syslog(LOG_ERR, "%s: %d: invalid integer: %s",
  245                path, line, arg);
  246     }
  247 
  248     else if (strcasecmp(cp, "kernel:attempts") == 0)
  249     {
  250         if (str2int(arg, &kernel_attempts) < 0)
  251         syslog(LOG_ERR, "%s: %d: invalid integer: %s",
  252                path, line, arg);
  253     }
  254 
  255     else if (strcasecmp(cp, "kernel:buffers") == 0)
  256     {
  257         if (str2int(arg, &kernel_buffers) < 0)
  258         syslog(LOG_ERR, "%s: %d: invalid integer: %s",
  259                path, line, arg);
  260     }
  261 
  262 #ifdef HAVE_LIBDES
  263     else if (strcasecmp(cp, "encrypt:key-file") == 0)
  264     {
  265         if (str2str(arg, &encrypt_keyfile) < 0)
  266         syslog(LOG_ERR, "%s: %d: invalid string: %s",
  267                path, line, arg);
  268     }
  269 #endif
  270     
  271     else
  272         syslog(LOG_ERR, "%s: %d: unknown option: %s", path, line, cp);
  273     }
  274 
  275     fclose(fp);
  276     return 0;
  277 }