summaryrefslogtreecommitdiffstats
path: root/lib/parse_ini.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse_ini.c')
-rw-r--r--lib/parse_ini.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 004396f..76953e9 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -1,9 +1,9 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Nagios-plugins parse_ini library 3* Monitoring Plugins parse_ini library
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2007 Nagios Plugins Development Team 6* Copyright (c) 2007 Monitoring Plugins Development Team
7* 7*
8* This program is free software: you can redistribute it and/or modify 8* This program is free software: you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by 9* it under the terms of the GNU General Public License as published by
@@ -49,7 +49,7 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts);
49static int add_option(FILE *f, np_arg_list **optlst); 49static int add_option(FILE *f, np_arg_list **optlst);
50/* internal function to find default file */ 50/* internal function to find default file */
51static char* default_file(void); 51static char* default_file(void);
52/* internal function to stat() files */ 52/* internal function to test files access */
53static int test_file(const char* env, int len, const char* file, char* temp_file); 53static int test_file(const char* env, int len, const char* file, char* temp_file);
54 54
55/* parse_locator decomposes a string of the form 55/* parse_locator decomposes a string of the form
@@ -101,7 +101,7 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){
101 } else { 101 } else {
102 inifile=fopen(i.file, "r"); 102 inifile=fopen(i.file, "r");
103 } 103 }
104 if(inifile==NULL) die(STATE_UNKNOWN, _("Can't read config file")); 104 if(inifile==NULL) die(STATE_UNKNOWN, "%s\n", _("Can't read config file"));
105 if(read_defaults(inifile, i.stanza, &defaults)==FALSE) 105 if(read_defaults(inifile, i.stanza, &defaults)==FALSE)
106 die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file); 106 die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file);
107 107
@@ -163,7 +163,7 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts){
163 * we're dealing with a config error 163 * we're dealing with a config error
164 */ 164 */
165 case NOSTANZA: 165 case NOSTANZA:
166 die(STATE_UNKNOWN, _("Config file error")); 166 die(STATE_UNKNOWN, "%s\n", _("Config file error"));
167 break; 167 break;
168 /* we're in a stanza, but for a different plugin */ 168 /* we're in a stanza, but for a different plugin */
169 case WRONGSTANZA: 169 case WRONGSTANZA:
@@ -173,7 +173,7 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts){
173 case RIGHTSTANZA: 173 case RIGHTSTANZA:
174 ungetc(c, f); 174 ungetc(c, f);
175 if(add_option(f, opts)){ 175 if(add_option(f, opts)){
176 die(STATE_UNKNOWN, _("Config file error")); 176 die(STATE_UNKNOWN, "%s\n", _("Config file error"));
177 } 177 }
178 status=TRUE; 178 status=TRUE;
179 break; 179 break;
@@ -229,7 +229,7 @@ static int add_option(FILE *f, np_arg_list **optlst){
229 if(optend==NULL) optend=eqptr; 229 if(optend==NULL) optend=eqptr;
230 --optend; 230 --optend;
231 /* ^[[:space:]]*=foo is a syntax error */ 231 /* ^[[:space:]]*=foo is a syntax error */
232 if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n")); 232 if(optptr==eqptr) die(STATE_UNKNOWN, "%s\n", _("Config file error"));
233 /* continue from '=' to start of value or EOL */ 233 /* continue from '=' to start of value or EOL */
234 for(valptr=eqptr+1; valptr<lineend && isspace(*valptr); valptr++); 234 for(valptr=eqptr+1; valptr<lineend && isspace(*valptr); valptr++);
235 /* continue to the end of value */ 235 /* continue to the end of value */
@@ -256,7 +256,7 @@ static int add_option(FILE *f, np_arg_list **optlst){
256 cfg_len+=1; 256 cfg_len+=1;
257 } 257 }
258 /* A line with no equal sign isn't valid */ 258 /* A line with no equal sign isn't valid */
259 if(equals==0) die(STATE_UNKNOWN, _("Config file error\n")); 259 if(equals==0) die(STATE_UNKNOWN, "%s\n", _("Config file error"));
260 260
261 /* okay, now we have all the info we need, so we create a new np_arg_list 261 /* okay, now we have all the info we need, so we create a new np_arg_list
262 * element and set the argument... 262 * element and set the argument...
@@ -350,7 +350,6 @@ static char* default_file(void){
350 * existence. Returns 1 if found, 0 if not and -1 if test wasn't performed. 350 * existence. Returns 1 if found, 0 if not and -1 if test wasn't performed.
351 */ 351 */
352static int test_file(const char* env, int len, const char* file, char* temp_file){ 352static int test_file(const char* env, int len, const char* file, char* temp_file){
353 struct stat sb;
354 353
355 /* test if len + filelen + '/' + '\0' fits in temp_file */ 354 /* test if len + filelen + '/' + '\0' fits in temp_file */
356 if((len+strlen(file)+2)>MAX_INPUT_BUFFER) return -1; 355 if((len+strlen(file)+2)>MAX_INPUT_BUFFER) return -1;
@@ -360,7 +359,7 @@ static int test_file(const char* env, int len, const char* file, char* temp_file
360 strncat(temp_file,"/",len+1); 359 strncat(temp_file,"/",len+1);
361 strncat(temp_file,file,len+strlen(file)+1); 360 strncat(temp_file,file,len+strlen(file)+1);
362 361
363 if(stat(temp_file, &sb) != -1) return 1; 362 if(access(temp_file, F_OK) == 0) return 1;
364 return 0; 363 return 0;
365} 364}
366 365