1 /* sasl_config.c -- Configuration routines
2 Copyright (C) 2000 Kenichi Okada <okada@opaopa.org>
4 Author: Kenichi Okada <okada@opaopa.org>
13 #include "inn/innconf.h"
16 #include "sasl_config.h"
25 static struct configlist *configlist;
26 static int nconfiglist;
28 const char *sasl_config_getstring(key, def)
34 for (opt = 0; opt < nconfiglist; opt++) {
35 if (*key == configlist[opt].key[0] &&
36 !strcmp(key, configlist[opt].key))
37 return configlist[opt].value;
42 int sasl_config_getint(key, def)
46 const char *val = sasl_config_getstring(key, (char *)0);
49 if (!isdigit(*val) && (*val != '-' || !isdigit(val[1]))) return def;
53 int sasl_config_getswitch(key, def)
57 const char *val = sasl_config_getstring(key, (char *)0);
61 if (*val == '0' || *val == 'n' ||
62 (*val == 'o' && val[1] == 'f') || *val == 'f') {
65 else if (*val == '1' || *val == 'y' ||
66 (*val == 'o' && val[1] == 'n') || *val == 't') {
72 const char *sasl_config_partitiondir(partition)
73 const char *partition;
77 if (strlen(partition) > 70) return 0;
78 snprintf(buf, sizeof(buf), "partition-%s", partition);
80 return sasl_config_getstring(buf, (char *)0);
83 #define CONFIGLISTGROWSIZE 10 /* 100 */
92 static char *SASL_CONFIG = NULL;
95 SASL_CONFIG = concatpath(innconf->pathetc, _PATH_SASL_CONFIG);
96 infile = fopen(SASL_CONFIG, "r");
98 fprintf(stderr, "can't open configuration file %s\n", SASL_CONFIG);
102 while (fgets(buf, sizeof(buf), infile)) {
105 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
106 for (p = buf; *p && isspace(*p); p++);
107 if (!*p || *p == '#') continue;
110 while (*p && (isalnum(*p) || *p == '-' || *p == '_')) {
111 if (isupper(*p)) *p = tolower(*p);
116 "invalid option name on line %d of configuration file\n",
122 while (*p && isspace(*p)) p++;
125 fprintf(stderr, "empty option value on line %d of configuration file\n",
130 if (nconfiglist == alloced) {
131 alloced += CONFIGLISTGROWSIZE;
132 configlist = xrealloc(configlist, alloced * sizeof(struct configlist));
135 configlist[nconfiglist].key = xstrdup(key);
136 configlist[nconfiglist].value = xstrdup(p);
142 #endif /* HAVE_SSL */