summaryrefslogtreecommitdiff
path: root/conf-parser.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-19 02:56:37 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-19 02:56:37 +0100
commit42f4e3c4413ad35e3815f25211fee95d775488a7 (patch)
treef9b69266acc05db37467ee6c0383969ca9c21081 /conf-parser.c
parenta66d02c3290008d50b2b52f84cfbf46a546ba831 (diff)
parse socket files properly
Diffstat (limited to 'conf-parser.c')
-rw-r--r--conf-parser.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/conf-parser.c b/conf-parser.c
index d6703dcb61..3a7da7960c 100644
--- a/conf-parser.c
+++ b/conf-parser.c
@@ -76,7 +76,7 @@ static char *strip(char *s) {
}
/* 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);
@@ -109,7 +109,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const
}
}
- r = config_parse(fn, t, userdata);
+ r = config_parse(fn, sections, t, userdata);
free(path);
return r;
}
@@ -129,6 +129,21 @@ static int parse_line(const char *filename, unsigned line, char **section, const
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;
@@ -147,7 +162,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const
}
/* 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;
@@ -174,7 +189,7 @@ int config_parse(const char *filename, const ConfigItem *t, void *userdata) {
goto finish;
}
- if ((r = parse_line(filename, ++line, &section, t, l, userdata)) < 0)
+ if ((r = parse_line(filename, ++line, &section, sections, t, l, userdata)) < 0)
goto finish;
}