fixed config parser to accept arbitrary whitespace

This commit is contained in:
Michael Elkins 2000-12-28 18:44:06 +00:00
parent e585d40076
commit d03ce3f73d

102
main.c
View File

@ -113,9 +113,9 @@ load_config (char *where)
char buf[1024]; char buf[1024];
struct passwd *pw; struct passwd *pw;
config_t **cur = &box; config_t **cur = &box;
char *p, *q;
int line = 0; int line = 0;
FILE *fp; FILE *fp;
char *p, *cmd, *val;
if (!where) if (!where)
{ {
@ -134,29 +134,29 @@ load_config (char *where)
return; return;
} }
} }
buf[sizeof buf - 1] = 0;
while ((fgets (buf, sizeof (buf) - 1, fp))) while ((fgets (buf, sizeof (buf) - 1, fp)))
{ {
if (buf[0])
buf[strlen (buf) - 1] = 0;
p = buf; p = buf;
q = next_arg (&p); cmd = next_arg (&p);
val = next_arg (&p);
line++; line++;
if (!q || *q == '#') if (!cmd || *cmd == '#')
continue; continue;
if (!strncasecmp ("mailbox", q, 7)) if (!strncasecmp ("mailbox", cmd, 7))
{ {
if (*cur) if (*cur)
cur = &(*cur)->next; cur = &(*cur)->next;
*cur = calloc (1, sizeof (config_t)); *cur = calloc (1, sizeof (config_t));
config_defaults (*cur); config_defaults (*cur);
(*cur)->path = strdup (p); (*cur)->path = strdup (val);
} }
else if (!strncasecmp ("host", q, 4)) else if (!strncasecmp ("host", cmd, 4))
{ {
#if HAVE_LIBSSL #if HAVE_LIBSSL
if (!strncasecmp ("imaps:", p, 6)) if (!strncasecmp ("imaps:", val, 6))
{ {
p += 6; val += 6;
if (*cur) if (*cur)
{ {
(*cur)->use_imaps = 1; (*cur)->use_imaps = 1;
@ -170,103 +170,103 @@ load_config (char *where)
} }
#endif #endif
if (*cur) if (*cur)
(*cur)->host = strdup (p); (*cur)->host = strdup (val);
else else
global.host = strdup (p); global.host = strdup (val);
} }
else if (!strncasecmp ("user", q, 4)) else if (!strncasecmp ("user", cmd, 4))
{ {
if (*cur) if (*cur)
(*cur)->user = strdup (p); (*cur)->user = strdup (val);
else else
global.user = strdup (p); global.user = strdup (val);
} }
else if (!strncasecmp ("pass", q, 4)) else if (!strncasecmp ("pass", cmd, 4))
{ {
if (*cur) if (*cur)
(*cur)->pass = strdup (p); (*cur)->pass = strdup (val);
else else
global.pass = strdup (p); global.pass = strdup (val);
} }
else if (!strncasecmp ("port", q, 4)) else if (!strncasecmp ("port", cmd, 4))
{ {
if (*cur) if (*cur)
(*cur)->port = atoi (p); (*cur)->port = atoi (val);
else else
global.port = atoi (p); global.port = atoi (val);
} }
else if (!strncasecmp ("box", q, 3)) else if (!strncasecmp ("box", cmd, 3))
{ {
if (*cur) if (*cur)
(*cur)->box = strdup (p); (*cur)->box = strdup (val);
else else
global.box = strdup (p); global.box = strdup (val);
} }
else if (!strncasecmp ("alias", q, 5)) else if (!strncasecmp ("alias", cmd, 5))
{ {
if (*cur) if (*cur)
(*cur)->alias = strdup (p); (*cur)->alias = strdup (val);
} }
else if (!strncasecmp ("maxsize", q, 7)) else if (!strncasecmp ("maxsize", cmd, 7))
{ {
if (*cur) if (*cur)
(*cur)->max_size = atol (p); (*cur)->max_size = atol (val);
else else
global.max_size = atol (p); global.max_size = atol (val);
} }
else if (!strncasecmp ("UseNamespace", q, 12)) else if (!strncasecmp ("UseNamespace", cmd, 12))
{ {
if (*cur) if (*cur)
(*cur)->use_namespace = (strcasecmp (p, "yes") == 0); (*cur)->use_namespace = (strcasecmp (val, "yes") == 0);
else else
global.use_namespace = (strcasecmp (p, "yes") == 0); global.use_namespace = (strcasecmp (val, "yes") == 0);
} }
#if HAVE_LIBSSL #if HAVE_LIBSSL
else if (!strncasecmp ("CertificateFile", q, 15)) else if (!strncasecmp ("CertificateFile", cmd, 15))
{ {
if (*cur) if (*cur)
(*cur)->cert_file = strdup (p); (*cur)->cert_file = strdup (val);
else else
global.cert_file = strdup (p); global.cert_file = strdup (val);
} }
else if (!strncasecmp ("RequireSSL", q, 10)) else if (!strncasecmp ("RequireSSL", cmd, 10))
{ {
if (*cur) if (*cur)
(*cur)->require_ssl = (strcasecmp (p, "yes") == 0); (*cur)->require_ssl = (strcasecmp (val, "yes") == 0);
else else
global.require_ssl = (strcasecmp (p, "yes") == 0); global.require_ssl = (strcasecmp (val, "yes") == 0);
} }
else if (!strncasecmp ("UseSSLv2", q, 8)) else if (!strncasecmp ("UseSSLv2", cmd, 8))
{ {
if (*cur) if (*cur)
(*cur)->use_sslv2 = (strcasecmp (p, "yes") == 0); (*cur)->use_sslv2 = (strcasecmp (val, "yes") == 0);
else else
global.use_sslv2 = (strcasecmp (p, "yes") == 0); global.use_sslv2 = (strcasecmp (val, "yes") == 0);
} }
else if (!strncasecmp ("UseSSLv3", q, 8)) else if (!strncasecmp ("UseSSLv3", cmd, 8))
{ {
if (*cur) if (*cur)
(*cur)->use_sslv3 = (strcasecmp (p, "yes") == 0); (*cur)->use_sslv3 = (strcasecmp (val, "yes") == 0);
else else
global.use_sslv3 = (strcasecmp (p, "yes") == 0); global.use_sslv3 = (strcasecmp (val, "yes") == 0);
} }
else if (!strncasecmp ("UseTLSv1", q, 8)) else if (!strncasecmp ("UseTLSv1", cmd, 8))
{ {
if (*cur) if (*cur)
(*cur)->use_tlsv1 = (strcasecmp (p, "yes") == 0); (*cur)->use_tlsv1 = (strcasecmp (val, "yes") == 0);
else else
global.use_tlsv1 = (strcasecmp (p, "yes") == 0); global.use_tlsv1 = (strcasecmp (val, "yes") == 0);
} }
else if (!strncasecmp ("RequireCRAM", q, 11)) else if (!strncasecmp ("RequireCRAM", cmd, 11))
{ {
if (*cur) if (*cur)
(*cur)->require_cram = (strcasecmp (p, "yes") == 0); (*cur)->require_cram = (strcasecmp (val, "yes") == 0);
else else
global.require_cram = (strcasecmp (p, "yes") == 0); global.require_cram = (strcasecmp (val, "yes") == 0);
} }
#endif #endif
else if (buf[0]) else if (buf[0])
printf ("%s:%d:unknown command:%s", path, line, q); printf ("%s:%d:unknown command:%s", path, line, cmd);
} }
fclose (fp); fclose (fp);
} }