Improvement to config file parsing code?

Dave McMurtrie dave64 at andrew.cmu.edu
Wed Apr 15 15:22:33 EDT 2009


I discovered that the code in libconfig.c that parses imapd.conf really
has no way of warning you if you make a typo.  It looks like someone
tried to deal with this at some point, but that code is commented out
because it would die on any service-specific configuration options.

The patch I propose here relies on the fact that a service-specific
option must contain a '_' character in it, so this patch would at least
catch simple typos to real imapd configuration options.  Of course, this
patch is only valid if my assumption that all service-specific options
must contain an underscore is valid.

Thoughts?  If this would be useful, I'll throw it in bugzilla.  If it's
a dumb idea, I'll forget about it.

--- libconfig.c.orig    2009-03-31 08:22:14.000000000 -0400
+++ libconfig.c 2009-04-15 15:04:44.000000000 -0400
@@ -589,18 +589,14 @@
            /* check to make sure it's valid for overflow */
            /* that is, partition names and anything that might be
             * used by SASL */
-/*
-  xxx this would be nice if it wasn't for other services who might be
-      sharing this config file and whose names we cannot predict
-
            if(strncasecmp(key,"sasl_",5)
-           && strncasecmp(key,"partition-",10)) {
+              && strncasecmp(key,"partition-",10)
+              && (!strchr(key,'_'))) {
                sprintf(errbuf,
                        "option '%s' is unknown on line %d of config file",
                        fullkey, lineno);
                fatal(errbuf, EC_CONFIG);
            }
-*/

            /* Put it in the overflow hash table */
            newval = xstrdup(p);

-- 
Dave McMurtrie, SPE
Email Systems Team Leader
Carnegie Mellon University,
Computing Services


More information about the Cyrus-devel mailing list