diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2014-06-21 15:15:44 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2014-06-21 15:15:44 +0200 |
commit | eb85a612a3321c57efbd672f8b11bfefbc659876 (patch) | |
tree | 6ac50ffdffff6926da7e4412559970dba823f376 | |
parent | 8a932865eb6082a66d2ceb73354bd6bb5a2b90ab (diff) | |
download | monitoring-plugins-eb85a61.tar.gz |
Add UID to state retention file path
Add the UID of the invoking user to the state retention file path. This
helps solving permission issues when different users run the same
plugin.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | lib/tests/test_utils.c | 8 | ||||
-rw-r--r-- | lib/utils_base.c | 4 |
3 files changed, 11 insertions, 3 deletions
@@ -23,6 +23,8 @@ This file documents the major additions and syntax changes between releases. | |||
23 | been disabled because they were broken | 23 | been disabled because they were broken |
24 | State retention: the NAGIOS_PLUGIN_STATE_DIRECTORY environment variable has been | 24 | State retention: the NAGIOS_PLUGIN_STATE_DIRECTORY environment variable has been |
25 | renamed MP_STATE_PATH. The old variable will continue to work in v1.6.x | 25 | renamed MP_STATE_PATH. The old variable will continue to work in v1.6.x |
26 | Add the UID of the invoking user to the state retention file path. This helps solving | ||
27 | permission issues when different users run the same plugin | ||
26 | check_swap used to allow returning OK on a system without swap when only percent thresholds | 28 | check_swap used to allow returning OK on a system without swap when only percent thresholds |
27 | were used. This is no longer the case and one must now use -n/--no-swap=<state> | 29 | were used. This is no longer the case and one must now use -n/--no-swap=<state> |
28 | The Perl and Shell plugins now use the PATH specified via ./configure's --trusted-path | 30 | The Perl and Shell plugins now use the PATH specified via ./configure's --trusted-path |
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 356887d5..f35b7e27 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "tap.h" | 22 | #include "tap.h" |
23 | 23 | ||
24 | #include <unistd.h> | ||
24 | #include <sys/types.h> | 25 | #include <sys/types.h> |
25 | #include <sys/stat.h> | 26 | #include <sys/stat.h> |
26 | 27 | ||
@@ -29,6 +30,7 @@ | |||
29 | int | 30 | int |
30 | main (int argc, char **argv) | 31 | main (int argc, char **argv) |
31 | { | 32 | { |
33 | char state_path[1024]; | ||
32 | range *range; | 34 | range *range; |
33 | double temp; | 35 | double temp; |
34 | thresholds *thresholds = NULL; | 36 | thresholds *thresholds = NULL; |
@@ -345,9 +347,10 @@ main (int argc, char **argv) | |||
345 | 347 | ||
346 | np_enable_state("allowedchars_in_keyname", 77); | 348 | np_enable_state("allowedchars_in_keyname", 77); |
347 | temp_state_key = this_monitoring_plugin->state; | 349 | temp_state_key = this_monitoring_plugin->state; |
350 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned long)geteuid()); | ||
348 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 351 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
349 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); | 352 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); |
350 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" ); | 353 | ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); |
351 | 354 | ||
352 | 355 | ||
353 | /* Don't do this test just yet. Will die */ | 356 | /* Don't do this test just yet. Will die */ |
@@ -359,12 +362,13 @@ main (int argc, char **argv) | |||
359 | 362 | ||
360 | np_enable_state("funnykeyname", 54); | 363 | np_enable_state("funnykeyname", 54); |
361 | temp_state_key = this_monitoring_plugin->state; | 364 | temp_state_key = this_monitoring_plugin->state; |
365 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid()); | ||
362 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 366 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
363 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); | 367 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); |
364 | 368 | ||
365 | 369 | ||
366 | 370 | ||
367 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/funnykeyname"), "Got internal filename" ); | 371 | ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); |
368 | ok( temp_state_key->data_version==54, "Version set" ); | 372 | ok( temp_state_key->data_version==54, "Version set" ); |
369 | 373 | ||
370 | temp_state_data = np_state_read(); | 374 | temp_state_data = np_state_read(); |
diff --git a/lib/utils_base.c b/lib/utils_base.c index 04c4b4f9..55d35fdd 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -489,7 +489,9 @@ void np_enable_state(char *keyname, int expected_data_version) { | |||
489 | this_state->state_data=NULL; | 489 | this_state->state_data=NULL; |
490 | 490 | ||
491 | /* Calculate filename */ | 491 | /* Calculate filename */ |
492 | asprintf(&temp_filename, "%s/%s/%s", _np_state_calculate_location_prefix(), this_monitoring_plugin->plugin_name, this_state->name); | 492 | asprintf(&temp_filename, "%s/%lu/%s/%s", |
493 | _np_state_calculate_location_prefix(), (unsigned long)geteuid(), | ||
494 | this_monitoring_plugin->plugin_name, this_state->name); | ||
493 | this_state->_filename=temp_filename; | 495 | this_state->_filename=temp_filename; |
494 | 496 | ||
495 | this_monitoring_plugin->state = this_state; | 497 | this_monitoring_plugin->state = this_state; |