diff options
Diffstat (limited to 'lib/parse_ini.c')
-rw-r--r-- | lib/parse_ini.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index 3f2aa3b8..70da7f14 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c | |||
@@ -42,7 +42,7 @@ typedef struct { | |||
42 | #define GOBBLE_TO(f, c, n) do { (c)=fgetc((f)); } while((c)!=EOF && (c)!=(n)) | 42 | #define GOBBLE_TO(f, c, n) do { (c)=fgetc((f)); } while((c)!=EOF && (c)!=(n)) |
43 | 43 | ||
44 | /* internal function that returns the constructed defaults options */ | 44 | /* internal function that returns the constructed defaults options */ |
45 | static np_arg_list* read_defaults(FILE *f, const char *stanza); | 45 | static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts); |
46 | /* internal function that converts a single line into options format */ | 46 | /* internal function that converts a single line into options format */ |
47 | static int add_option(FILE *f, np_arg_list **optlst); | 47 | static int add_option(FILE *f, np_arg_list **optlst); |
48 | 48 | ||
@@ -90,7 +90,12 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){ | |||
90 | inifile=fopen(i.file, "r"); | 90 | inifile=fopen(i.file, "r"); |
91 | } | 91 | } |
92 | if(inifile==NULL) die(STATE_UNKNOWN, _("Config file error")); | 92 | if(inifile==NULL) die(STATE_UNKNOWN, _("Config file error")); |
93 | defaults=read_defaults(inifile, i.stanza); | 93 | if(read_defaults(inifile, i.stanza, &defaults)==FALSE && strcmp(i.stanza, default_section) && inifile!=stdout) { /* FIXME: Shouldn't it be 'stdin' ??? */ |
94 | /* We got nothing, try the default section */ | ||
95 | rewind(inifile); | ||
96 | read_defaults(inifile, default_section, &defaults); | ||
97 | } | ||
98 | |||
94 | free(i.file); | 99 | free(i.file); |
95 | if(inifile!=stdout) fclose(inifile); /* FIXME: Shouldn't it be 'stdin' ??? */ | 100 | if(inifile!=stdout) fclose(inifile); /* FIXME: Shouldn't it be 'stdin' ??? */ |
96 | } | 101 | } |
@@ -104,9 +109,8 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){ | |||
104 | * be extra careful about user-supplied input (i.e. avoiding possible | 109 | * be extra careful about user-supplied input (i.e. avoiding possible |
105 | * format string vulnerabilities, etc) | 110 | * format string vulnerabilities, etc) |
106 | */ | 111 | */ |
107 | static np_arg_list* read_defaults(FILE *f, const char *stanza){ | 112 | static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts){ |
108 | int c; | 113 | int c, status=FALSE; |
109 | np_arg_list *opts=NULL; | ||
110 | size_t i, stanza_len; | 114 | size_t i, stanza_len; |
111 | enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate=NOSTANZA; | 115 | enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate=NOSTANZA; |
112 | 116 | ||
@@ -158,15 +162,16 @@ static np_arg_list* read_defaults(FILE *f, const char *stanza){ | |||
158 | /* okay, this is where we start taking the config */ | 162 | /* okay, this is where we start taking the config */ |
159 | case RIGHTSTANZA: | 163 | case RIGHTSTANZA: |
160 | ungetc(c, f); | 164 | ungetc(c, f); |
161 | if(add_option(f, &opts)){ | 165 | if(add_option(f, opts)){ |
162 | die(STATE_UNKNOWN, _("Config file error")); | 166 | die(STATE_UNKNOWN, _("Config file error")); |
163 | } | 167 | } |
168 | status=TRUE; | ||
164 | break; | 169 | break; |
165 | } | 170 | } |
166 | break; | 171 | break; |
167 | } | 172 | } |
168 | } | 173 | } |
169 | return opts; | 174 | return status; |
170 | } | 175 | } |
171 | 176 | ||
172 | /* | 177 | /* |