summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-03-15 22:42:01 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-03-15 22:42:01 (GMT)
commit92b969e2391936cbb66a8f547a77f94f05430419 (patch)
tree3526b7993dc5b7061061e2ba5ceb6bfc934d2888 /lib
parent252d9a78ccaf08a175bb4fcbf91145761d47780d (diff)
downloadmonitoring-plugins-92b969e2391936cbb66a8f547a77f94f05430419.tar.gz
parse_ini now reads the default section if the request one can't be found.
All tests should return ok now. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1950 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib')
-rw-r--r--lib/parse_ini.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 3f2aa3b..70da7f1 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 */
45static np_arg_list* read_defaults(FILE *f, const char *stanza); 45static 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 */
47static int add_option(FILE *f, np_arg_list **optlst); 47static 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 */
107static np_arg_list* read_defaults(FILE *f, const char *stanza){ 112static 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/*