diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 6 | ||||
-rw-r--r-- | lib/extra_opts.c | 4 | ||||
-rw-r--r-- | lib/extra_opts.h | 2 | ||||
-rw-r--r-- | lib/parse_ini.c | 19 | ||||
-rw-r--r-- | lib/parse_ini.h | 2 | ||||
-rw-r--r-- | lib/tests/Makefile.am | 2 | ||||
-rwxr-xr-x | lib/tests/test_base64.t | 2 | ||||
-rw-r--r-- | lib/tests/test_cmd.t | 2 | ||||
-rwxr-xr-x | lib/tests/test_disk.t | 2 | ||||
-rwxr-xr-x | lib/tests/test_ini1.t | 2 | ||||
-rwxr-xr-x | lib/tests/test_ini3.t | 2 | ||||
-rwxr-xr-x | lib/tests/test_opts1.t | 2 | ||||
-rwxr-xr-x | lib/tests/test_opts2.t | 2 | ||||
-rwxr-xr-x | lib/tests/test_opts3.t | 2 | ||||
-rwxr-xr-x | lib/tests/test_tcp.t | 2 | ||||
-rw-r--r-- | lib/tests/test_utils.c | 58 | ||||
-rwxr-xr-x | lib/tests/test_utils.t | 2 | ||||
-rw-r--r-- | lib/utils_base.c | 117 | ||||
-rw-r--r-- | lib/utils_base.h | 8 | ||||
-rw-r--r-- | lib/utils_cmd.c | 4 | ||||
-rw-r--r-- | lib/utils_cmd.h | 2 | ||||
-rw-r--r-- | lib/utils_disk.c | 2 | ||||
-rw-r--r-- | lib/utils_tcp.c | 2 |
23 files changed, 132 insertions, 116 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 99fa591..1515312 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -2,15 +2,15 @@ | |||
2 | 2 | ||
3 | SUBDIRS = . tests | 3 | SUBDIRS = . tests |
4 | 4 | ||
5 | noinst_LIBRARIES = libnagiosplug.a | 5 | noinst_LIBRARIES = libmonitoringplug.a |
6 | 6 | ||
7 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" | 7 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" |
8 | 8 | ||
9 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c | 9 | libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c |
10 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h | 10 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h |
11 | 11 | ||
12 | if USE_PARSE_INI | 12 | if USE_PARSE_INI |
13 | libnagiosplug_a_SOURCES += parse_ini.c extra_opts.c | 13 | libmonitoringplug_a_SOURCES += parse_ini.c extra_opts.c |
14 | endif USE_PARSE_INI | 14 | endif USE_PARSE_INI |
15 | 15 | ||
16 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 16 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 2939c7a..f4d5e66 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c | |||
@@ -1,9 +1,9 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Nagios-plugins extra_opts library | 3 | * Monitoring Plugins extra_opts 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 |
diff --git a/lib/extra_opts.h b/lib/extra_opts.h index 4bb7b73..8ff14a1 100644 --- a/lib/extra_opts.h +++ b/lib/extra_opts.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #define _EXTRA_OPTS_H_ | 2 | #define _EXTRA_OPTS_H_ |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * extra_opts.h: routines for loading nagios-plugin defaults from ini | 5 | * extra_opts.h: routines for loading monitoring-plugin defaults from ini |
6 | * configuration files. | 6 | * configuration files. |
7 | */ | 7 | */ |
8 | 8 | ||
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); | |||
49 | static int add_option(FILE *f, np_arg_list **optlst); | 49 | static int add_option(FILE *f, np_arg_list **optlst); |
50 | /* internal function to find default file */ | 50 | /* internal function to find default file */ |
51 | static char* default_file(void); | 51 | static char* default_file(void); |
52 | /* internal function to stat() files */ | 52 | /* internal function to test files access */ |
53 | static int test_file(const char* env, int len, const char* file, char* temp_file); | 53 | static 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 | */ |
352 | static int test_file(const char* env, int len, const char* file, char* temp_file){ | 352 | static 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 | ||
diff --git a/lib/parse_ini.h b/lib/parse_ini.h index e0ba816..a3a494e 100644 --- a/lib/parse_ini.h +++ b/lib/parse_ini.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #define _PARSE_INI_H_ | 2 | #define _PARSE_INI_H_ |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * parse_ini.h: routines for loading nagios-plugin defaults from ini | 5 | * parse_ini.h: routines for loading monitoring-plugin defaults from ini |
6 | * configuration files. | 6 | * configuration files. |
7 | */ | 7 | */ |
8 | 8 | ||
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am index 1af5891..c0411ac 100644 --- a/lib/tests/Makefile.am +++ b/lib/tests/Makefile.am | |||
@@ -28,7 +28,7 @@ endif | |||
28 | 28 | ||
29 | AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) | 29 | AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) |
30 | AM_LDFLAGS = $(tap_ldflags) -ltap | 30 | AM_LDFLAGS = $(tap_ldflags) -ltap |
31 | LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a | 31 | LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a |
32 | 32 | ||
33 | SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c | 33 | SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c |
34 | 34 | ||
diff --git a/lib/tests/test_base64.t b/lib/tests/test_base64.t index 4b9236f..4ad6473 100755 --- a/lib/tests/test_base64.t +++ b/lib/tests/test_base64.t | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_base64") { | 3 | if (! -e "./test_base64") { |
4 | plan skip_all => "./test_base64 not compiled - please install tap library to test"; | 4 | plan skip_all => "./test_base64 not compiled - please enable libtap library to test"; |
5 | } | 5 | } |
6 | exec "./test_base64"; | 6 | exec "./test_base64"; |
diff --git a/lib/tests/test_cmd.t b/lib/tests/test_cmd.t index 4dd54ef..c50dded 100644 --- a/lib/tests/test_cmd.t +++ b/lib/tests/test_cmd.t | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_cmd") { | 3 | if (! -e "./test_cmd") { |
4 | plan skip_all => "./test_cmd not compiled - please install tap library to test"; | 4 | plan skip_all => "./test_cmd not compiled - please enable libtap library to test"; |
5 | } | 5 | } |
6 | exec "./test_cmd"; | 6 | exec "./test_cmd"; |
diff --git a/lib/tests/test_disk.t b/lib/tests/test_disk.t index d32567a..da84dfd 100755 --- a/lib/tests/test_disk.t +++ b/lib/tests/test_disk.t | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_disk") { | 3 | if (! -e "./test_disk") { |
4 | plan skip_all => "./test_disk not compiled - please install tap library to test"; | 4 | plan skip_all => "./test_disk not compiled - please enable libtap library to test"; |
5 | } | 5 | } |
6 | exec "./test_disk"; | 6 | exec "./test_disk"; |
diff --git a/lib/tests/test_ini1.t b/lib/tests/test_ini1.t index d481011..25baed9 100755 --- a/lib/tests/test_ini1.t +++ b/lib/tests/test_ini1.t | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_ini1") { | 3 | if (! -e "./test_ini1") { |
4 | plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test"; | 4 | plan skip_all => "./test_ini not compiled - please enable libtap library and/or extra-opts to test"; |
5 | } | 5 | } |
6 | exec "./test_ini1"; | 6 | exec "./test_ini1"; |
diff --git a/lib/tests/test_ini3.t b/lib/tests/test_ini3.t index 4b0be4c..a2ca94a 100755 --- a/lib/tests/test_ini3.t +++ b/lib/tests/test_ini3.t | |||
@@ -4,7 +4,7 @@ use strict; | |||
4 | use warnings; | 4 | use warnings; |
5 | 5 | ||
6 | if (! -e "./test_ini3") { | 6 | if (! -e "./test_ini3") { |
7 | plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test"; | 7 | plan skip_all => "./test_ini not compiled - please enable libtap library and/or extra-opts to test"; |
8 | } | 8 | } |
9 | 9 | ||
10 | # array of argument arrays | 10 | # array of argument arrays |
diff --git a/lib/tests/test_opts1.t b/lib/tests/test_opts1.t index 52eed94..1934f12 100755 --- a/lib/tests/test_opts1.t +++ b/lib/tests/test_opts1.t | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_opts1") { | 3 | if (! -e "./test_opts1") { |
4 | plan skip_all => "./test_opts1 not compiled - please install tap library and/or enable parse-ini to test"; | 4 | plan skip_all => "./test_opts1 not compiled - please enable libtap library and/or extra-opts to test"; |
5 | } | 5 | } |
6 | exec "./test_opts1"; | 6 | exec "./test_opts1"; |
diff --git a/lib/tests/test_opts2.t b/lib/tests/test_opts2.t index f7444f6..59b9fdb 100755 --- a/lib/tests/test_opts2.t +++ b/lib/tests/test_opts2.t | |||
@@ -1,7 +1,7 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_opts2") { | 3 | if (! -e "./test_opts2") { |
4 | plan skip_all => "./test_opts2 not compiled - please install tap library and/or enable parse-ini to test"; | 4 | plan skip_all => "./test_opts2 not compiled - please enable libtap library and/or extra-opts to test"; |
5 | } | 5 | } |
6 | $ENV{"NAGIOS_CONFIG_PATH"} = "."; | 6 | $ENV{"NAGIOS_CONFIG_PATH"} = "."; |
7 | exec "./test_opts2"; | 7 | exec "./test_opts2"; |
diff --git a/lib/tests/test_opts3.t b/lib/tests/test_opts3.t index fa7876d..8d974ca 100755 --- a/lib/tests/test_opts3.t +++ b/lib/tests/test_opts3.t | |||
@@ -4,7 +4,7 @@ use strict; | |||
4 | use warnings; | 4 | use warnings; |
5 | 5 | ||
6 | if (! -e "./test_opts3") { | 6 | if (! -e "./test_opts3") { |
7 | plan skip_all => "./test_opts3 not compiled - please install tap library and/or enable parse-ini to test"; | 7 | plan skip_all => "./test_opts3 not compiled - please enable libtap library and/or extra-opts to test"; |
8 | } | 8 | } |
9 | 9 | ||
10 | # array of argument arrays | 10 | # array of argument arrays |
diff --git a/lib/tests/test_tcp.t b/lib/tests/test_tcp.t index 8f34b67..e5e12fc 100755 --- a/lib/tests/test_tcp.t +++ b/lib/tests/test_tcp.t | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_tcp") { | 3 | if (! -e "./test_tcp") { |
4 | plan skip_all => "./test_tcp not compiled - please install tap library to test"; | 4 | plan skip_all => "./test_tcp not compiled - please enable libtap library to test"; |
5 | } | 5 | } |
6 | exec "./test_tcp"; | 6 | exec "./test_tcp"; |
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 79e1110..0571340 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
@@ -38,22 +38,22 @@ main (int argc, char **argv) | |||
38 | state_data *temp_state_data; | 38 | state_data *temp_state_data; |
39 | time_t current_time; | 39 | time_t current_time; |
40 | 40 | ||
41 | plan_tests(150); | 41 | plan_tests(151); |
42 | 42 | ||
43 | ok( this_nagios_plugin==NULL, "nagios_plugin not initialised"); | 43 | ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised"); |
44 | 44 | ||
45 | np_init( "check_test", argc, argv ); | 45 | np_init( "check_test", argc, argv ); |
46 | 46 | ||
47 | ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised"); | 47 | ok( this_monitoring_plugin!=NULL, "monitoring_plugin now initialised"); |
48 | ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" ); | 48 | ok( !strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised" ); |
49 | 49 | ||
50 | ok( this_nagios_plugin->argc==argc, "Argc set" ); | 50 | ok( this_monitoring_plugin->argc==argc, "Argc set" ); |
51 | ok( this_nagios_plugin->argv==argv, "Argv set" ); | 51 | ok( this_monitoring_plugin->argv==argv, "Argv set" ); |
52 | 52 | ||
53 | np_set_args(0,0); | 53 | np_set_args(0,0); |
54 | 54 | ||
55 | ok( this_nagios_plugin->argc==0, "argc changed" ); | 55 | ok( this_monitoring_plugin->argc==0, "argc changed" ); |
56 | ok( this_nagios_plugin->argv==0, "argv changed" ); | 56 | ok( this_monitoring_plugin->argv==0, "argv changed" ); |
57 | 57 | ||
58 | np_set_args(argc, argv); | 58 | np_set_args(argc, argv); |
59 | 59 | ||
@@ -296,23 +296,23 @@ main (int argc, char **argv) | |||
296 | diag( "You are probably running in wrong directory. Must run as ./test_utils" ); | 296 | diag( "You are probably running in wrong directory. Must run as ./test_utils" ); |
297 | 297 | ||
298 | 298 | ||
299 | this_nagios_plugin->argc=4; | 299 | this_monitoring_plugin->argc=4; |
300 | this_nagios_plugin->argv[0] = "./test_utils"; | 300 | this_monitoring_plugin->argv[0] = "./test_utils"; |
301 | this_nagios_plugin->argv[1] = "here"; | 301 | this_monitoring_plugin->argv[1] = "here"; |
302 | this_nagios_plugin->argv[2] = "--and"; | 302 | this_monitoring_plugin->argv[2] = "--and"; |
303 | this_nagios_plugin->argv[3] = "now"; | 303 | this_monitoring_plugin->argv[3] = "now"; |
304 | temp_string = (char *) _np_state_generate_key(); | 304 | temp_string = (char *) _np_state_generate_key(); |
305 | ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); | 305 | ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); |
306 | 306 | ||
307 | unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); | 307 | unsetenv("MP_STATE_PATH"); |
308 | temp_string = (char *) _np_state_calculate_location_prefix(); | 308 | temp_string = (char *) _np_state_calculate_location_prefix(); |
309 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" ); | 309 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" ); |
310 | 310 | ||
311 | setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1); | 311 | setenv("MP_STATE_PATH", "", 1); |
312 | temp_string = (char *) _np_state_calculate_location_prefix(); | 312 | temp_string = (char *) _np_state_calculate_location_prefix(); |
313 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" ); | 313 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" ); |
314 | 314 | ||
315 | setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1); | 315 | setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1); |
316 | temp_string = (char *) _np_state_calculate_location_prefix(); | 316 | temp_string = (char *) _np_state_calculate_location_prefix(); |
317 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); | 317 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); |
318 | 318 | ||
@@ -320,16 +320,16 @@ main (int argc, char **argv) | |||
320 | 320 | ||
321 | ok(temp_state_key==NULL, "temp_state_key initially empty"); | 321 | ok(temp_state_key==NULL, "temp_state_key initially empty"); |
322 | 322 | ||
323 | this_nagios_plugin->argc=1; | 323 | this_monitoring_plugin->argc=1; |
324 | this_nagios_plugin->argv[0] = "./test_utils"; | 324 | this_monitoring_plugin->argv[0] = "./test_utils"; |
325 | np_enable_state(NULL, 51); | 325 | np_enable_state(NULL, 51); |
326 | temp_state_key = this_nagios_plugin->state; | 326 | temp_state_key = this_monitoring_plugin->state; |
327 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 327 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
328 | ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); | 328 | ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); |
329 | 329 | ||
330 | 330 | ||
331 | np_enable_state("allowedchars_in_keyname", 77); | 331 | np_enable_state("allowedchars_in_keyname", 77); |
332 | temp_state_key = this_nagios_plugin->state; | 332 | temp_state_key = this_monitoring_plugin->state; |
333 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 333 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
334 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); | 334 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); |
335 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" ); | 335 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" ); |
@@ -338,12 +338,12 @@ main (int argc, char **argv) | |||
338 | /* Don't do this test just yet. Will die */ | 338 | /* Don't do this test just yet. Will die */ |
339 | /* | 339 | /* |
340 | np_enable_state("bad^chars$in@here", 77); | 340 | np_enable_state("bad^chars$in@here", 77); |
341 | temp_state_key = this_nagios_plugin->state; | 341 | temp_state_key = this_monitoring_plugin->state; |
342 | ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" ); | 342 | ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" ); |
343 | */ | 343 | */ |
344 | 344 | ||
345 | np_enable_state("funnykeyname", 54); | 345 | np_enable_state("funnykeyname", 54); |
346 | temp_state_key = this_nagios_plugin->state; | 346 | temp_state_key = this_monitoring_plugin->state; |
347 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 347 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
348 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); | 348 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); |
349 | 349 | ||
@@ -367,9 +367,9 @@ main (int argc, char **argv) | |||
367 | 367 | ||
368 | temp_state_key->_filename="var/statefile"; | 368 | temp_state_key->_filename="var/statefile"; |
369 | temp_state_data = np_state_read(); | 369 | temp_state_data = np_state_read(); |
370 | ok( this_nagios_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not"); | 370 | ok( this_monitoring_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not"); |
371 | ok( this_nagios_plugin->state->state_data->time==1234567890, "Got time" ); | 371 | ok( this_monitoring_plugin->state->state_data->time==1234567890, "Got time" ); |
372 | ok( !strcmp((char *)this_nagios_plugin->state->state_data->data, "String to read"), "Data as expected" ); | 372 | ok( !strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected" ); |
373 | 373 | ||
374 | temp_state_key->data_version=53; | 374 | temp_state_key->data_version=53; |
375 | temp_state_data = np_state_read(); | 375 | temp_state_data = np_state_read(); |
@@ -379,7 +379,7 @@ main (int argc, char **argv) | |||
379 | temp_state_key->_filename="var/nonexistant"; | 379 | temp_state_key->_filename="var/nonexistant"; |
380 | temp_state_data = np_state_read(); | 380 | temp_state_data = np_state_read(); |
381 | ok( temp_state_data==NULL, "Missing file gives NULL" ); | 381 | ok( temp_state_data==NULL, "Missing file gives NULL" ); |
382 | ok( this_nagios_plugin->state->state_data==NULL, "No state information" ); | 382 | ok( this_monitoring_plugin->state->state_data==NULL, "No state information" ); |
383 | 383 | ||
384 | temp_state_key->_filename="var/oldformat"; | 384 | temp_state_key->_filename="var/oldformat"; |
385 | temp_state_data = np_state_read(); | 385 | temp_state_data = np_state_read(); |
@@ -426,7 +426,7 @@ main (int argc, char **argv) | |||
426 | temp_state_data = np_state_read(); | 426 | temp_state_data = np_state_read(); |
427 | /* Check time is set to current_time */ | 427 | /* Check time is set to current_time */ |
428 | ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); | 428 | ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); |
429 | ok(this_nagios_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); | 429 | ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); |
430 | 430 | ||
431 | 431 | ||
432 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ | 432 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ |
@@ -438,7 +438,9 @@ main (int argc, char **argv) | |||
438 | 438 | ||
439 | np_cleanup(); | 439 | np_cleanup(); |
440 | 440 | ||
441 | ok( this_nagios_plugin==NULL, "Free'd this_nagios_plugin" ); | 441 | ok( this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin" ); |
442 | |||
443 | ok( mp_suid() == FALSE, "test aren't suid" ); | ||
442 | 444 | ||
443 | return exit_status(); | 445 | return exit_status(); |
444 | } | 446 | } |
diff --git a/lib/tests/test_utils.t b/lib/tests/test_utils.t index 152eb71..e2a9311 100755 --- a/lib/tests/test_utils.t +++ b/lib/tests/test_utils.t | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use Test::More; | 2 | use Test::More; |
3 | if (! -e "./test_utils") { | 3 | if (! -e "./test_utils") { |
4 | plan skip_all => "./test_utils not compiled - please install tap library to test"; | 4 | plan skip_all => "./test_utils not compiled - please enable libtap library to test"; |
5 | } | 5 | } |
6 | exec "./test_utils"; | 6 | exec "./test_utils"; |
diff --git a/lib/utils_base.c b/lib/utils_base.c index 54463e9..f5f7506 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * utils_base.c | 3 | * utils_base.c |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2006 Nagios Plugins Development Team | 6 | * Copyright (c) 2006 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Library of useful functions for plugins | 8 | * Library of useful functions for plugins |
9 | * | 9 | * |
@@ -30,56 +30,58 @@ | |||
30 | #include <ctype.h> | 30 | #include <ctype.h> |
31 | #include <fcntl.h> | 31 | #include <fcntl.h> |
32 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
33 | #include <unistd.h> | ||
34 | #include <sys/types.h> | ||
33 | 35 | ||
34 | #define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } } | 36 | #define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } } |
35 | 37 | ||
36 | nagios_plugin *this_nagios_plugin=NULL; | 38 | monitoring_plugin *this_monitoring_plugin=NULL; |
37 | 39 | ||
38 | int _np_state_read_file(FILE *); | 40 | int _np_state_read_file(FILE *); |
39 | 41 | ||
40 | void np_init( char *plugin_name, int argc, char **argv ) { | 42 | void np_init( char *plugin_name, int argc, char **argv ) { |
41 | if (this_nagios_plugin==NULL) { | 43 | if (this_monitoring_plugin==NULL) { |
42 | this_nagios_plugin = calloc(1, sizeof(nagios_plugin)); | 44 | this_monitoring_plugin = calloc(1, sizeof(monitoring_plugin)); |
43 | if (this_nagios_plugin==NULL) { | 45 | if (this_monitoring_plugin==NULL) { |
44 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 46 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), |
45 | strerror(errno)); | 47 | strerror(errno)); |
46 | } | 48 | } |
47 | this_nagios_plugin->plugin_name = strdup(plugin_name); | 49 | this_monitoring_plugin->plugin_name = strdup(plugin_name); |
48 | if (this_nagios_plugin->plugin_name==NULL) | 50 | if (this_monitoring_plugin->plugin_name==NULL) |
49 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 51 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
50 | this_nagios_plugin->argc = argc; | 52 | this_monitoring_plugin->argc = argc; |
51 | this_nagios_plugin->argv = argv; | 53 | this_monitoring_plugin->argv = argv; |
52 | } | 54 | } |
53 | } | 55 | } |
54 | 56 | ||
55 | void np_set_args( int argc, char **argv ) { | 57 | void np_set_args( int argc, char **argv ) { |
56 | if (this_nagios_plugin==NULL) | 58 | if (this_monitoring_plugin==NULL) |
57 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | 59 | die(STATE_UNKNOWN, _("This requires np_init to be called")); |
58 | 60 | ||
59 | this_nagios_plugin->argc = argc; | 61 | this_monitoring_plugin->argc = argc; |
60 | this_nagios_plugin->argv = argv; | 62 | this_monitoring_plugin->argv = argv; |
61 | } | 63 | } |
62 | 64 | ||
63 | 65 | ||
64 | void np_cleanup() { | 66 | void np_cleanup() { |
65 | if (this_nagios_plugin!=NULL) { | 67 | if (this_monitoring_plugin!=NULL) { |
66 | if(this_nagios_plugin->state!=NULL) { | 68 | if(this_monitoring_plugin->state!=NULL) { |
67 | if(this_nagios_plugin->state->state_data) { | 69 | if(this_monitoring_plugin->state->state_data) { |
68 | np_free(this_nagios_plugin->state->state_data->data); | 70 | np_free(this_monitoring_plugin->state->state_data->data); |
69 | np_free(this_nagios_plugin->state->state_data); | 71 | np_free(this_monitoring_plugin->state->state_data); |
70 | } | 72 | } |
71 | np_free(this_nagios_plugin->state->name); | 73 | np_free(this_monitoring_plugin->state->name); |
72 | np_free(this_nagios_plugin->state); | 74 | np_free(this_monitoring_plugin->state); |
73 | } | 75 | } |
74 | np_free(this_nagios_plugin->plugin_name); | 76 | np_free(this_monitoring_plugin->plugin_name); |
75 | np_free(this_nagios_plugin); | 77 | np_free(this_monitoring_plugin); |
76 | } | 78 | } |
77 | this_nagios_plugin=NULL; | 79 | this_monitoring_plugin=NULL; |
78 | } | 80 | } |
79 | 81 | ||
80 | /* Hidden function to get a pointer to this_nagios_plugin for testing */ | 82 | /* Hidden function to get a pointer to this_monitoring_plugin for testing */ |
81 | void _get_nagios_plugin( nagios_plugin **pointer ){ | 83 | void _get_monitoring_plugin( monitoring_plugin **pointer ){ |
82 | *pointer = this_nagios_plugin; | 84 | *pointer = this_monitoring_plugin; |
83 | } | 85 | } |
84 | 86 | ||
85 | void | 87 | void |
@@ -89,7 +91,7 @@ die (int result, const char *fmt, ...) | |||
89 | va_start (ap, fmt); | 91 | va_start (ap, fmt); |
90 | vprintf (fmt, ap); | 92 | vprintf (fmt, ap); |
91 | va_end (ap); | 93 | va_end (ap); |
92 | if(this_nagios_plugin!=NULL) { | 94 | if(this_monitoring_plugin!=NULL) { |
93 | np_cleanup(); | 95 | np_cleanup(); |
94 | } | 96 | } |
95 | exit (result); | 97 | exit (result); |
@@ -375,14 +377,14 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { | |||
375 | char *_np_state_generate_key() { | 377 | char *_np_state_generate_key() { |
376 | struct sha1_ctx ctx; | 378 | struct sha1_ctx ctx; |
377 | int i; | 379 | int i; |
378 | char **argv = this_nagios_plugin->argv; | 380 | char **argv = this_monitoring_plugin->argv; |
379 | unsigned char result[20]; | 381 | unsigned char result[20]; |
380 | char keyname[41]; | 382 | char keyname[41]; |
381 | char *p=NULL; | 383 | char *p=NULL; |
382 | 384 | ||
383 | sha1_init_ctx(&ctx); | 385 | sha1_init_ctx(&ctx); |
384 | 386 | ||
385 | for(i=0; i<this_nagios_plugin->argc; i++) { | 387 | for(i=0; i<this_monitoring_plugin->argc; i++) { |
386 | sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); | 388 | sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); |
387 | } | 389 | } |
388 | 390 | ||
@@ -401,9 +403,9 @@ char *_np_state_generate_key() { | |||
401 | } | 403 | } |
402 | 404 | ||
403 | void _cleanup_state_data() { | 405 | void _cleanup_state_data() { |
404 | if (this_nagios_plugin->state->state_data!=NULL) { | 406 | if (this_monitoring_plugin->state->state_data!=NULL) { |
405 | np_free(this_nagios_plugin->state->state_data->data); | 407 | np_free(this_monitoring_plugin->state->state_data->data); |
406 | np_free(this_nagios_plugin->state->state_data); | 408 | np_free(this_monitoring_plugin->state->state_data); |
407 | } | 409 | } |
408 | } | 410 | } |
409 | 411 | ||
@@ -415,9 +417,18 @@ void _cleanup_state_data() { | |||
415 | char* _np_state_calculate_location_prefix(){ | 417 | char* _np_state_calculate_location_prefix(){ |
416 | char *env_dir; | 418 | char *env_dir; |
417 | 419 | ||
418 | env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); | 420 | /* Do not allow passing MP_STATE_PATH in setuid plugins |
419 | if(env_dir && env_dir[0] != '\0') | 421 | * for security reasons */ |
420 | return env_dir; | 422 | if (mp_suid() == FALSE) { |
423 | env_dir = getenv("MP_STATE_PATH"); | ||
424 | if(env_dir && env_dir[0] != '\0') | ||
425 | return env_dir; | ||
426 | /* This is the former ENV, for backward-compatibility */ | ||
427 | env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); | ||
428 | if(env_dir && env_dir[0] != '\0') | ||
429 | return env_dir; | ||
430 | } | ||
431 | |||
421 | return NP_STATE_DIR_PREFIX; | 432 | return NP_STATE_DIR_PREFIX; |
422 | } | 433 | } |
423 | 434 | ||
@@ -432,7 +443,7 @@ void np_enable_state(char *keyname, int expected_data_version) { | |||
432 | char *temp_keyname = NULL; | 443 | char *temp_keyname = NULL; |
433 | char *p=NULL; | 444 | char *p=NULL; |
434 | 445 | ||
435 | if(this_nagios_plugin==NULL) | 446 | if(this_monitoring_plugin==NULL) |
436 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | 447 | die(STATE_UNKNOWN, _("This requires np_init to be called")); |
437 | 448 | ||
438 | this_state = (state_key *) calloc(1, sizeof(state_key)); | 449 | this_state = (state_key *) calloc(1, sizeof(state_key)); |
@@ -456,15 +467,15 @@ void np_enable_state(char *keyname, int expected_data_version) { | |||
456 | p++; | 467 | p++; |
457 | } | 468 | } |
458 | this_state->name=temp_keyname; | 469 | this_state->name=temp_keyname; |
459 | this_state->plugin_name=this_nagios_plugin->plugin_name; | 470 | this_state->plugin_name=this_monitoring_plugin->plugin_name; |
460 | this_state->data_version=expected_data_version; | 471 | this_state->data_version=expected_data_version; |
461 | this_state->state_data=NULL; | 472 | this_state->state_data=NULL; |
462 | 473 | ||
463 | /* Calculate filename */ | 474 | /* Calculate filename */ |
464 | asprintf(&temp_filename, "%s/%s/%s", _np_state_calculate_location_prefix(), this_nagios_plugin->plugin_name, this_state->name); | 475 | asprintf(&temp_filename, "%s/%s/%s", _np_state_calculate_location_prefix(), this_monitoring_plugin->plugin_name, this_state->name); |
465 | this_state->_filename=temp_filename; | 476 | this_state->_filename=temp_filename; |
466 | 477 | ||
467 | this_nagios_plugin->state = this_state; | 478 | this_monitoring_plugin->state = this_state; |
468 | } | 479 | } |
469 | 480 | ||
470 | /* | 481 | /* |
@@ -479,11 +490,11 @@ state_data *np_state_read() { | |||
479 | FILE *statefile; | 490 | FILE *statefile; |
480 | int rc = FALSE; | 491 | int rc = FALSE; |
481 | 492 | ||
482 | if(this_nagios_plugin==NULL) | 493 | if(this_monitoring_plugin==NULL) |
483 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | 494 | die(STATE_UNKNOWN, _("This requires np_init to be called")); |
484 | 495 | ||
485 | /* Open file. If this fails, no previous state found */ | 496 | /* Open file. If this fails, no previous state found */ |
486 | statefile = fopen( this_nagios_plugin->state->_filename, "r" ); | 497 | statefile = fopen( this_monitoring_plugin->state->_filename, "r" ); |
487 | if(statefile!=NULL) { | 498 | if(statefile!=NULL) { |
488 | 499 | ||
489 | this_state_data = (state_data *) calloc(1, sizeof(state_data)); | 500 | this_state_data = (state_data *) calloc(1, sizeof(state_data)); |
@@ -492,7 +503,7 @@ state_data *np_state_read() { | |||
492 | strerror(errno)); | 503 | strerror(errno)); |
493 | 504 | ||
494 | this_state_data->data=NULL; | 505 | this_state_data->data=NULL; |
495 | this_nagios_plugin->state->state_data = this_state_data; | 506 | this_monitoring_plugin->state->state_data = this_state_data; |
496 | 507 | ||
497 | rc = _np_state_read_file(statefile); | 508 | rc = _np_state_read_file(statefile); |
498 | 509 | ||
@@ -503,10 +514,10 @@ state_data *np_state_read() { | |||
503 | _cleanup_state_data(); | 514 | _cleanup_state_data(); |
504 | } | 515 | } |
505 | 516 | ||
506 | return this_nagios_plugin->state->state_data; | 517 | return this_monitoring_plugin->state->state_data; |
507 | } | 518 | } |
508 | 519 | ||
509 | /* | 520 | /* |
510 | * Read the state file | 521 | * Read the state file |
511 | */ | 522 | */ |
512 | int _np_state_read_file(FILE *f) { | 523 | int _np_state_read_file(FILE *f) { |
@@ -544,7 +555,7 @@ int _np_state_read_file(FILE *f) { | |||
544 | break; | 555 | break; |
545 | case STATE_DATA_VERSION: | 556 | case STATE_DATA_VERSION: |
546 | i=atoi(line); | 557 | i=atoi(line); |
547 | if(i != this_nagios_plugin->state->data_version) | 558 | if(i != this_monitoring_plugin->state->data_version) |
548 | failure++; | 559 | failure++; |
549 | else | 560 | else |
550 | expected=STATE_DATA_TIME; | 561 | expected=STATE_DATA_TIME; |
@@ -555,13 +566,13 @@ int _np_state_read_file(FILE *f) { | |||
555 | if(data_time > current_time) | 566 | if(data_time > current_time) |
556 | failure++; | 567 | failure++; |
557 | else { | 568 | else { |
558 | this_nagios_plugin->state->state_data->time = data_time; | 569 | this_monitoring_plugin->state->state_data->time = data_time; |
559 | expected=STATE_DATA_TEXT; | 570 | expected=STATE_DATA_TEXT; |
560 | } | 571 | } |
561 | break; | 572 | break; |
562 | case STATE_DATA_TEXT: | 573 | case STATE_DATA_TEXT: |
563 | this_nagios_plugin->state->state_data->data = strdup(line); | 574 | this_monitoring_plugin->state->state_data->data = strdup(line); |
564 | if(this_nagios_plugin->state->state_data->data==NULL) | 575 | if(this_monitoring_plugin->state->state_data->data==NULL) |
565 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 576 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
566 | expected=STATE_DATA_END; | 577 | expected=STATE_DATA_END; |
567 | status=TRUE; | 578 | status=TRUE; |
@@ -596,8 +607,8 @@ void np_state_write_string(time_t data_time, char *data_string) { | |||
596 | current_time=data_time; | 607 | current_time=data_time; |
597 | 608 | ||
598 | /* If file doesn't currently exist, create directories */ | 609 | /* If file doesn't currently exist, create directories */ |
599 | if(access(this_nagios_plugin->state->_filename,F_OK)!=0) { | 610 | if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) { |
600 | asprintf(&directories, "%s", this_nagios_plugin->state->_filename); | 611 | asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); |
601 | if(directories==NULL) | 612 | if(directories==NULL) |
602 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 613 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), |
603 | strerror(errno)); | 614 | strerror(errno)); |
@@ -607,7 +618,7 @@ void np_state_write_string(time_t data_time, char *data_string) { | |||
607 | *p='\0'; | 618 | *p='\0'; |
608 | if((access(directories,F_OK)!=0) && (mkdir(directories, S_IRWXU)!=0)) { | 619 | if((access(directories,F_OK)!=0) && (mkdir(directories, S_IRWXU)!=0)) { |
609 | /* Can't free this! Otherwise error message is wrong! */ | 620 | /* Can't free this! Otherwise error message is wrong! */ |
610 | /* np_free(directories); */ | 621 | /* np_free(directories); */ |
611 | die(STATE_UNKNOWN, _("Cannot create directory: %s"), directories); | 622 | die(STATE_UNKNOWN, _("Cannot create directory: %s"), directories); |
612 | } | 623 | } |
613 | *p='/'; | 624 | *p='/'; |
@@ -616,7 +627,7 @@ void np_state_write_string(time_t data_time, char *data_string) { | |||
616 | np_free(directories); | 627 | np_free(directories); |
617 | } | 628 | } |
618 | 629 | ||
619 | asprintf(&temp_file,"%s.XXXXXX",this_nagios_plugin->state->_filename); | 630 | asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename); |
620 | if(temp_file==NULL) | 631 | if(temp_file==NULL) |
621 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 632 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), |
622 | strerror(errno)); | 633 | strerror(errno)); |
@@ -636,7 +647,7 @@ void np_state_write_string(time_t data_time, char *data_string) { | |||
636 | 647 | ||
637 | fprintf(fp,"# NP State file\n"); | 648 | fprintf(fp,"# NP State file\n"); |
638 | fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION); | 649 | fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION); |
639 | fprintf(fp,"%d\n",this_nagios_plugin->state->data_version); | 650 | fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version); |
640 | fprintf(fp,"%lu\n",current_time); | 651 | fprintf(fp,"%lu\n",current_time); |
641 | fprintf(fp,"%s\n",data_string); | 652 | fprintf(fp,"%s\n",data_string); |
642 | 653 | ||
@@ -654,7 +665,7 @@ void np_state_write_string(time_t data_time, char *data_string) { | |||
654 | die(STATE_UNKNOWN, _("Error writing temp file")); | 665 | die(STATE_UNKNOWN, _("Error writing temp file")); |
655 | } | 666 | } |
656 | 667 | ||
657 | if(rename(temp_file, this_nagios_plugin->state->_filename)!=0) { | 668 | if(rename(temp_file, this_monitoring_plugin->state->_filename)!=0) { |
658 | unlink(temp_file); | 669 | unlink(temp_file); |
659 | np_free(temp_file); | 670 | np_free(temp_file); |
660 | die(STATE_UNKNOWN, _("Cannot rename state temp file")); | 671 | die(STATE_UNKNOWN, _("Cannot rename state temp file")); |
diff --git a/lib/utils_base.h b/lib/utils_base.h index 0cb371f..b4bd92e 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
@@ -1,6 +1,6 @@ | |||
1 | #ifndef _UTILS_BASE_ | 1 | #ifndef _UTILS_BASE_ |
2 | #define _UTILS_BASE_ | 2 | #define _UTILS_BASE_ |
3 | /* Header file for nagios plugins utils_base.c */ | 3 | /* Header file for Monitoring Plugins utils_base.c */ |
4 | 4 | ||
5 | #include "sha1.h" | 5 | #include "sha1.h" |
6 | 6 | ||
@@ -52,7 +52,7 @@ typedef struct np_struct { | |||
52 | state_key *state; | 52 | state_key *state; |
53 | int argc; | 53 | int argc; |
54 | char **argv; | 54 | char **argv; |
55 | } nagios_plugin; | 55 | } monitoring_plugin; |
56 | 56 | ||
57 | range *parse_range_string (char *); | 57 | range *parse_range_string (char *); |
58 | int _set_thresholds(thresholds **, char *, char *); | 58 | int _set_thresholds(thresholds **, char *, char *); |
@@ -102,4 +102,8 @@ void np_init(char *, int argc, char **argv); | |||
102 | void np_set_args(int argc, char **argv); | 102 | void np_set_args(int argc, char **argv); |
103 | void np_cleanup(); | 103 | void np_cleanup(); |
104 | 104 | ||
105 | /* mp_suid() returns true if the real and effective uids differs, such as when | ||
106 | * running a suid plugin */ | ||
107 | #define mp_suid() (getuid() != geteuid()) | ||
108 | |||
105 | #endif /* _UTILS_BASE_ */ | 109 | #endif /* _UTILS_BASE_ */ |
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 0c853dc..4c6d0be 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
@@ -1,9 +1,9 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Nagios run command utilities | 3 | * Monitoring run command utilities |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2005-2006 Nagios Plugins Development Team | 6 | * Copyright (c) 2005-2006 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description : | 8 | * Description : |
9 | * | 9 | * |
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index 8ebb589..ebaf15b 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #define _UTILS_CMD_ | 2 | #define _UTILS_CMD_ |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * Header file for nagios plugins utils_cmd.c | 5 | * Header file for Monitoring Plugins utils_cmd.c |
6 | * | 6 | * |
7 | * | 7 | * |
8 | */ | 8 | */ |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 5be2b2c..efe35fc 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Library for check_disk | 3 | * Library for check_disk |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2007 Nagios Plugins Development Team | 6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c index 46ad7f7..b37c446 100644 --- a/lib/utils_tcp.c +++ b/lib/utils_tcp.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Library for check_tcp | 3 | * Library for check_tcp |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2013 Nagios Plugins Development Team | 6 | * Copyright (c) 1999-2013 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |