summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3f5fbd9)
raw | patch | inline | side by side (parent: 3f5fbd9)
author | M. Sean Finney <seanius@users.sourceforge.net> | |
Sun, 27 May 2007 13:46:32 +0000 (13:46 +0000) | ||
committer | M. Sean Finney <seanius@users.sourceforge.net> | |
Sun, 27 May 2007 13:46:32 +0000 (13:46 +0000) |
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.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1718 f882894a-f735-0410-b71e-b25c423dba1c
np_warn_if_not_root() - uses the above to print an informative warning
added uses of these functions to check_dhcp and check_icmp.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1718 f882894a-f735-0410-b71e-b25c423dba1c
lib/utils_base.c | patch | blob | history | |
lib/utils_base.h | patch | blob | history | |
plugins-root/check_dhcp.c | patch | blob | history | |
plugins-root/check_icmp.c | patch | blob | history |
diff --git a/lib/utils_base.c b/lib/utils_base.c
index db21ea15b47a746d0762fddca98129a4b1ce589b..da281286d80332624d54bae62f22bf41dd39e7ca 100644 (file)
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
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;
+}
diff --git a/lib/utils_base.h b/lib/utils_base.h
index b722d0eccc2dc04903faf8f4c0aef90030011ac4..bda765959ba2f72821665b705424a4b0edf01e24 100644 (file)
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
#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_ */
index 8559d634e62545fce4fde4663f5c1b0a3603b2c4..7cb2d30052d34aeaad82f218869e6f2a2169303e 100644 (file)
int dhcp_socket;
int result = STATE_UNKNOWN;
+ /* this plugin almost certainly needs root permissions. */
+ np_warn_if_not_root();
+
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
-
+
if(process_arguments(argc,argv)!=OK){
usage4 (_("Could not parse arguments"));
}
index 7e3b00f36a0a2f6b887e0433ef4868f7b453ff74..7f9160c43c7527cfcccc7b8a563401f63218f482 100644 (file)
int result;
struct rta_host *host;
+ /* print a helpful error message if geteuid != 0 */
+ np_warn_if_not_root();
+
/* we only need to be setsuid when we get the sockets, so do
* that before pointer magic (esp. on network data) */
icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0;