}
/* Parse a variable assignment line */
-static int parse_line(const char *filename, unsigned line, char **section, const ConfigItem *t, char *l, void *userdata) {
+static int parse_line(const char *filename, unsigned line, char **section, const char* const * sections, const ConfigItem *t, char *l, void *userdata) {
char *e, *c, *b;
b = l+strspn(l, WHITESPACE);
}
}
- r = config_parse(fn, t, userdata);
+ r = config_parse(fn, sections, t, userdata);
free(path);
return r;
}
if (!(n = strndup(b+1, k-2)))
return -ENOMEM;
+ if (sections) {
+ const char * const * i;
+ bool good = false;
+ STRV_FOREACH(i, sections)
+ if (streq(*i, n)) {
+ good = true;
+ break;
+ }
+
+ if (!good) {
+ free(n);
+ return -EBADMSG;
+ }
+ }
+
free(*section);
*section = n;
}
/* Go through the file and parse each line */
-int config_parse(const char *filename, const ConfigItem *t, void *userdata) {
+int config_parse(const char *filename, const char* const * sections, const ConfigItem *t, void *userdata) {
unsigned line = 0;
char *section = NULL;
FILE *f;
goto finish;
}
- if ((r = parse_line(filename, ++line, §ion, t, l, userdata)) < 0)
+ if ((r = parse_line(filename, ++line, §ion, sections, t, l, userdata)) < 0)
goto finish;
}