Module: monitoring-plugins
 Branch: master
 Commit: eb85a612a3321c57efbd672f8b11bfefbc659876
 Author: Holger Weiss <[email protected]>
   Date: Sat Jun 21 15:15:44 2014 +0200
    URL: 
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=eb85a61

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.

---

 NEWS                   | 2 ++
 lib/tests/test_utils.c | 8 ++++++--
 lib/utils_base.c       | 4 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 0a1ef95..4c51179 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,8 @@ This file documents the major additions and syntax changes 
between releases.
          been disabled because they were broken
        State retention: the NAGIOS_PLUGIN_STATE_DIRECTORY environment variable 
has been
          renamed MP_STATE_PATH. The old variable will continue to work in 
v1.6.x
+       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
        check_swap used to allow returning OK on a system without swap when 
only percent thresholds
          were used. This is no longer the case and one must now use 
-n/--no-swap=<state>
        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 356887d..f35b7e2 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -21,6 +21,7 @@
 
 #include "tap.h"
 
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -29,6 +30,7 @@
 int
 main (int argc, char **argv)
 {
+       char state_path[1024];
        range   *range;
        double  temp;
        thresholds *thresholds = NULL;
@@ -345,9 +347,10 @@ main (int argc, char **argv)
 
        np_enable_state("allowedchars_in_keyname", 77);
        temp_state_key = this_monitoring_plugin->state;
+       sprintf(state_path, 
"/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned 
long)geteuid());
        ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin 
name" );
        ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key 
name with valid chars" );
-       ok( !strcmp(temp_state_key->_filename, 
"/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal 
filename" );
+       ok( !strcmp(temp_state_key->_filename, state_path), "Got internal 
filename" );
 
 
        /* Don't do this test just yet. Will die */
@@ -359,12 +362,13 @@ main (int argc, char **argv)
 
        np_enable_state("funnykeyname", 54);
        temp_state_key = this_monitoring_plugin->state;
+       sprintf(state_path, 
"/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid());
        ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin 
name" );
        ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" );
 
 
 
-       ok( !strcmp(temp_state_key->_filename, 
"/usr/local/nagios/var/check_test/funnykeyname"), "Got internal filename" );
+       ok( !strcmp(temp_state_key->_filename, state_path), "Got internal 
filename" );
        ok( temp_state_key->data_version==54, "Version set" );
 
        temp_state_data = np_state_read();
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 04c4b4f..55d35fd 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) {
        this_state->state_data=NULL;
 
        /* Calculate filename */
-       asprintf(&temp_filename, "%s/%s/%s", 
_np_state_calculate_location_prefix(), this_monitoring_plugin->plugin_name, 
this_state->name);
+       asprintf(&temp_filename, "%s/%lu/%s/%s",
+           _np_state_calculate_location_prefix(), (unsigned long)geteuid(),
+           this_monitoring_plugin->plugin_name, this_state->name);
        this_state->_filename=temp_filename;
 
        this_monitoring_plugin->state = this_state;

Reply via email to