|
|
@@ -1,24 +1,24 @@
|
|
|
/*****************************************************************************
|
|
|
-*
|
|
|
+*
|
|
|
* Nagios-plugins parse_ini library
|
|
|
-*
|
|
|
+*
|
|
|
* License: GPL
|
|
|
* Copyright (c) 2007-2014 Nagios Plugins Development Team
|
|
|
-*
|
|
|
+*
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
* (at your option) any later version.
|
|
|
-*
|
|
|
+*
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
* GNU General Public License for more details.
|
|
|
-*
|
|
|
+*
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
-*
|
|
|
-*
|
|
|
+*
|
|
|
+*
|
|
|
*****************************************************************************/
|
|
|
|
|
|
#include "common.h"
|
|
|
@@ -124,33 +124,32 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){
|
|
|
|
|
|
parse_locator(locator, default_section, &i);
|
|
|
/* If a file was specified or if we're using the default file. */
|
|
|
- if (i.file != NULL && strlen(i.file) > 0) {
|
|
|
- if (strcmp(i.file, "-") == 0) {
|
|
|
- inifile = stdin;
|
|
|
- } else {
|
|
|
- /* We must be able to stat() the thing. */
|
|
|
- if (lstat(i.file, &fstat) != 0)
|
|
|
- die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."), strerror(errno));
|
|
|
- /* The requested file must be a regular file. */
|
|
|
- if (!S_ISREG(fstat.st_mode))
|
|
|
- die(STATE_UNKNOWN, "%s\n", _("Can't read config file. Requested path is not a regular file."));
|
|
|
- /* We must be able to read the requested file. */
|
|
|
- if (access(i.file, R_OK|F_OK) != 0)
|
|
|
- die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."), strerror(errno));
|
|
|
- /* We need to successfully open the file for reading... */
|
|
|
- if ((inifile=fopen(i.file, "r")) == NULL)
|
|
|
- die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."), strerror(errno));
|
|
|
- }
|
|
|
+ if (i.file != NULL && strlen(i.file) > 0) {
|
|
|
+ if (strcmp(i.file, "-") == 0) {
|
|
|
+ inifile = stdin;
|
|
|
+ } else {
|
|
|
+ /* We must be able to stat() the thing. */
|
|
|
+ if (lstat(i.file, &fstat) != 0)
|
|
|
+ die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."), strerror(errno));
|
|
|
+ /* The requested file must be a regular file. */
|
|
|
+ if (!S_ISREG(fstat.st_mode))
|
|
|
+ die(STATE_UNKNOWN, "%s\n", _("Can't read config file. Requested path is not a regular file."));
|
|
|
+ /* We must be able to read the requested file. */
|
|
|
+ if (access(i.file, R_OK|F_OK) != 0)
|
|
|
+ die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."), strerror(errno));
|
|
|
+ /* We need to successfully open the file for reading... */
|
|
|
+ if ((inifile=fopen(i.file, "r")) == NULL)
|
|
|
+ die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."), strerror(errno));
|
|
|
+ }
|
|
|
|
|
|
/* before attempting access, let's make sure inifile is not null, this should never be the case though */
|
|
|
if (inifile == NULL)
|
|
|
die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file:"), strerror(errno));
|
|
|
- /* inifile points to an open FILE our ruid/rgid can access, parse its contents. */
|
|
|
- if (read_defaults(inifile, i.stanza, &defaults) == FALSE)
|
|
|
- die(STATE_UNKNOWN,"%s%s%s%s'\n", _("Invalid section '"), i.stanza, _("' in config file '"), i.file);
|
|
|
-
|
|
|
- if (inifile != stdin) fclose(inifile);
|
|
|
- }
|
|
|
+ /* inifile points to an open FILE our ruid/rgid can access, parse its contents. */
|
|
|
+ if (read_defaults(inifile, i.stanza, &defaults) == FALSE)
|
|
|
+ die(STATE_UNKNOWN,"%s%s%s%s'\n", _("Invalid section '"), i.stanza, _("' in config file '"), i.file);
|
|
|
+ if (inifile != stdin) fclose(inifile);
|
|
|
+ }
|
|
|
|
|
|
if (i.file != NULL) {
|
|
|
free(i.file);
|