Ejemplo n.º 1
0
static bool process_config_line(char *line,
                               char *val,
                               const parm_desc *parms,
                               priority_t precedence )
/* returns true if parm is processed, false if not */
{
    const parm_desc *arg;

    if (parms == NULL)
       return false;

    for ( arg = parms; arg->name != NULL; arg += 1 )
    {
       if (DEBUG_CONFIG(2))
           fprintf(dbgout, "Testing:  %s\n", arg->name);
       if (strcmp(arg->name, line) == 0)
       {
           bool ok = process_config_parameter(arg, val, precedence);
           if (ok && DEBUG_CONFIG(1))
               fprintf(dbgout, "%s\n", "   Found it!");
           return ok;
       }
    }
    return false;
}
Ejemplo n.º 2
0
/* like got_charset() but charset is pure charset name */
void set_charset(const char *charset)
{
    bool q = (charset[0] == '"');
    char *s, *d;
    char *t = xstrdup(charset + q);

    for (s = d = t; *s != '\0'; s++)
    {
	char c = tolower((unsigned char)*s);	/* map upper case to lower */
	if (c == '_')		/* map underscore to dash */
	    c = '-';
	if (c == '-' &&		/* map "iso-" to "iso"     */
	    d - t == 3 &&	/* ensure 3 chars avail    */
	    memcmp(t, "iso", 3) == 0)
	    continue;
	if (q && c == '"')
	    break;
	*d++ = c;
    }
    *d = '\0';
    if (DEBUG_CONFIG(0))
       fprintf(dbgout, "got_charset( '%s' )\n", t);
    init_charset_table( t );
    xfree(t);
}
static e_txn get_txn(const char *name, const char *arg)
{
    e_txn t = get_bool(name, arg) ? T_ENABLED : T_DISABLED;
    if (DEBUG_CONFIG(2))
	fprintf(dbgout, "%s -> %s\n", name,
		t ? "enabled" : "disabled");
    return t;
}
static bool get_bool(const char *name, const char *arg)
{
    bool b = str_to_bool(arg);
    if (DEBUG_CONFIG(2))
	fprintf(dbgout, "%s -> %s\n", name,
		b ? "Yes" : "No");
    return b;
}
Ejemplo n.º 5
0
static char *get_string(const char *name, const char *arg)
{
    char *s = xstrdup(arg);
    remove_comment(s);

    if (DEBUG_CONFIG(2))
	fprintf(dbgout, "%s -> '%s'\n", name, s);
    return s;
}
Ejemplo n.º 6
0
static bool process_config_parameter(const parm_desc *arg, char *val, priority_t precedence)
/* returns true if ok, false if error */
{
    bool ok = true;
    if (arg->addr.v == NULL)
       return ok;
    switch (arg->type)
    {
       case CP_BOOLEAN:
           {
               *arg->addr.b = str_to_bool(val);
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> %s\n", arg->name,
                           *arg->addr.b ? "Yes" : "No");
               break;
           }
       case CP_INTEGER:
           {
               remove_comment(val);
               if (!xatoi(arg->addr.i, val))
                   return false;
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> %d\n", arg->name, *arg->addr.i);
               break;
           }
       case CP_DOUBLE:
           {
               remove_comment(val);
               if (!xatof(arg->addr.d, val))
                   return false;
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> %f\n", arg->name, *arg->addr.d);
               break;
           }
       case CP_CHAR:
           {
               *arg->addr.c = *val;
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> '%c'\n", arg->name, *arg->addr.c);
               break;
           }
       case CP_STRING:
           {
               *arg->addr.s = xstrdup(val);
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> '%s'\n", arg->name, *arg->addr.s);
               break;
           }
       case CP_DIRECTORY:
           {
               char *dir = tildeexpand(val, true);
               if (DEBUG_CONFIG(2))
                   fprintf(dbgout, "%s -> '%s'\n", arg->name, dir);
               if (setup_wordlists(dir, precedence) != 0)
                   exit(EX_ERROR);
                          xfree(dir);
               break;
           }
       case CP_FUNCTION:
       {
           ok = (*arg->addr.f)((unsigned char *)val);
           if (DEBUG_CONFIG(2))
               fprintf(dbgout, "%s -> '%s'\n", arg->name, val);
           break;
       }
       case CP_WORDLIST:
       {
           char c = *val;
           switch (c) {
           case 'c': wl_mode = WL_M_COMBINED; break;
           case 's': wl_mode = WL_M_SEPARATE; break;
           default:
               fprintf(stderr, "Unknown wordlist type - '%s'.\n", val);
               exit(EX_ERROR);
           }
           if (DEBUG_CONFIG(2))
               fprintf(dbgout, "%s -> '%s'\n", arg->name, val);
           break;
       }
       default:
       {
           ok = false;
           break;
       }
    }
    return ok;
}
Ejemplo n.º 7
0
bool read_config_file(const char *fname, bool tilde_expand, bool warn_on_error, priority_t precedence)
/* returns true if ok, false if error */
{
    bool error = false;
    int lineno = 0;
    FILE *fp;
    char *filename;
    char *arg = NULL, *val = NULL;

    filename = tildeexpand(fname, tilde_expand);

    fp = fopen(filename, "r");

    if (fp == NULL) {
       if (DEBUG_CONFIG(0)) {
           fprintf(dbgout, "Cannot open %s: %s\n", filename, strerror(errno));
       }
       xfree(filename);
       return false;
    }

    if (DEBUG_CONFIG(0))
       fprintf(dbgout, "Reading %s\n", filename);

    while (!feof(fp))
    {
       const char delim[] = " \t=";
       size_t len;
       char buff[MAXBUFFLEN];

       memset(buff, '\0', sizeof(buff));               /* for debugging */

       lineno += 1;
       if (fgets(buff, sizeof(buff), fp) == NULL)
           break;
       len = strlen(buff);
       if ( buff[0] == '#' || buff[0] == ';' || buff[0] == '\n' )
           continue;
       while (iscntrl((unsigned char)buff[len-1]) || isspace((unsigned char)buff[len-1]))
           buff[--len] = '\0';

       if (DEBUG_CONFIG(1))
           fprintf(dbgout, "Testing:  %s\n", buff);

       arg = buff;
       if (strcspn(arg, delim) < strlen(arg)) { /* if delimiter present */
           val = arg + strcspn(arg, delim);
           *val++ = '\0';
           val += strspn(val, delim);
       } else {
           val = NULL;
       }

       if (val == NULL ||
              (! process_config_line(arg, val, usr_parms, precedence ) &&
               ! process_config_line(arg, val, sys_parms, precedence ) &&
               ! process_config_line(arg, val, format_parms, precedence )))
       {
           error = true;
           if (warn_on_error)
               fprintf(stderr, "%s:%d:  Error - bad parameter in '%s ... %s'\n", filename, lineno, buff, val);
       }
    }

    if (ferror(fp)) {
       fprintf(stderr, "Error reading file \"%s\"\n.", filename);
       error = true;
    }

    (void)fclose(fp); /* we're just reading, so fclose should succeed */
    xfree(filename);

    return (error);
}