X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Fconffile.c;h=a8b803758f85c2f58d196bb2643874a2371ddb61;hp=c5f9fa7fb2a75852ee8a7f858a8b19813b435575;hb=c6a270ea8ab6ad299e6a43445420f22e0c617e3e;hpb=1a9010602442f466d700fbc4d64fe82ac69b1dd3 diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index c5f9fa7..a8b8037 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -50,11 +50,6 @@ #include "xlog.h" static void conf_load_defaults (int); -#if 0 -static int conf_find_trans_xf (int, char *); -#endif - -size_t strlcpy(char *, const char *, size_t); struct conf_trans { TAILQ_ENTRY (conf_trans) link; @@ -120,6 +115,18 @@ conf_hash(char *s) return hash; } +/* + * Convert letter from upper case to lower case + */ +static inline void upper2lower(char *str) +{ + char *ptr = str; + + while (*ptr) + *ptr++ = tolower(*ptr); +} + + /* * Insert a tag-value combination from LINE (the equal sign is at POS) */ @@ -219,26 +226,48 @@ conf_parse_line(int trans, char *line, size_t sz) if (*line == '#' || *line == ';') return; + /* Ignore blank lines */ + if (*line == '\0') + return; + + /* Strip off any leading blanks */ + while (isblank(*line)) + line++; + /* '[section]' parsing... */ if (*line == '[') { - for (i = 1; i < sz; i++) - if (line[i] == ']') + line++; + /* Strip off any blanks after '[' */ + while (isblank(*line)) + line++; + + for (i = 0; i < sz; i++) { + if (line[i] == ']') { break; + } + } if (section) - free (section); + free(section); if (i == sz) { xlog_warn("conf_parse_line: %d:" "non-matched ']', ignoring until next section", ln); section = 0; return; } + /* Strip off any blanks before ']' */ + val = line; + while (*val && !isblank(*val)) + val++, j++; + if (*val) + i = j; + section = malloc(i); if (!section) { xlog_warn("conf_parse_line: %d: malloc (%lu) failed", ln, (unsigned long)i); return; } - strlcpy(section, line + 1, i); + strncpy(section, line, i); return; } @@ -637,6 +666,9 @@ conf_set(int transaction, char *section, char *tag, xlog_warn("conf_set: strdup(\"%s\") failed", section); goto fail; } + /* Make Section names case-insensitive */ + upper2lower(node->section); + node->tag = strdup(tag); if (!node->tag) { xlog_warn("conf_set: strdup(\"%s\") failed", tag);