[Nagiosplug-checkins] nagiosplug/lib utils_base.c, 1.4, 1.5 utils_base.h, 1.4, 1.5

M. Sean Finney seanius at users.sourceforge.net
Sun May 27 15:46:34 CEST 2007


Update of /cvsroot/nagiosplug/nagiosplug/lib
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13507/lib

Modified Files:
	utils_base.c utils_base.h 
Log Message:
added functions to utils_base:
  np_check_if_root() - returns nonzero if geteuid()==0
  np_warn_if_not_root() - uses the above to print an informative warning
added uses of these functions to check_dhcp and check_icmp.


Index: utils_base.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/lib/utils_base.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- utils_base.c	27 Jan 2007 17:49:08 -0000	1.4
+++ utils_base.c	27 May 2007 13:46:32 -0000	1.5
@@ -228,3 +228,18 @@
 	data[j] = '\0';
 	return data;
 }
+
+int np_check_if_root(void) { return (geteuid() == 0); }
+
+int np_warn_if_not_root(void) {
+	int status = np_check_if_root();
+	if(!status) {
+		printf(_("Warning: "));
+		printf(_("This plugin must be either run as root or setuid root.\n"));
+		printf(_("To run as root, you can use a tool like sudo.\n"));
+		printf(_("To set the setuid permissions, use the command:\n"));
+		// XXX could we use something like progname?
+		printf("\tchmod u+s yourpluginfile\n");
+	}
+	return status;
+}

Index: utils_base.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/lib/utils_base.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- utils_base.h	20 Apr 2007 17:45:44 -0000	1.4
+++ utils_base.h	27 May 2007 13:46:32 -0000	1.5
@@ -43,4 +43,11 @@
 #define NP_RANGE_UNPARSEABLE 1
 #define NP_WARN_WITHIN_CRIT 2
 
+/* a simple check to see if we're running as root.  
+ * returns zero on failure, nonzero on success */
+int np_check_if_root(void);
+/* and a helpful wrapper around that.  it returns the same status
+ * code from the above function, in case it's helpful for testing */
+int np_warn_if_not_root(void);
+
 #endif /* _UTILS_BASE_ */





More information about the Commits mailing list