1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
diff -Naur /home/qqnagio/software/nagios/nagios-plugins-1.4.11/plugins-scripts/check_mailq.pl /home/qqnagio/software/nagios/nagios-plugins-1.4.11.sudomailq/plugins-scripts/check_mailq.pl
--- /home/qqnagio/software/nagios/nagios-plugins-1.4.11/plugins-scripts/check_mailq.pl 2006-07-05 15:45:57.000000000 +0200
+++ /home/qqnagio/software/nagios/nagios-plugins-1.4.11.sudomailq/plugins-scripts/check_mailq.pl 2008-01-23 14:52:01.556368612 +0100
@@ -62,12 +62,29 @@
};
alarm($opt_t);
+# if there is an entry in the sudoers file which allows the caller of this
+# plugin to execute the $utils::PATH_TO_MAILQ command with superuser privileges
+# then prepend $utils::PATH_TO_MAILQ with "sudo "
+
+sub sudoize {
+ my $ppath_to_mailq = shift;
+ if (grep(/$$ppath_to_mailq/,
+ map { s/^\s+//g; s/\s+$//g; $_; }
+ map { split /, / }
+ map { s/^.*?://g; $_; }
+ do { local (@ARGV) = "/usr/bin/sudo -l |"; <> })) {
+ $$ppath_to_mailq = "/usr/bin/sudo ".$$ppath_to_mailq;
+ }
+}
+
+
# switch based on MTA
if ($mailq eq "sendmail") {
## open mailq
if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
+ sudoize(\$utils::PATH_TO_MAILQ);
if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
exit $ERRORS{'UNKNOWN'};
@@ -297,6 +314,7 @@
## open mailq
if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
+ sudoize(\$utils::PATH_TO_MAILQ);
if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
exit $ERRORS{'UNKNOWN'};
@@ -379,6 +397,7 @@
# open qmail-qstat
if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) {
+ sudoize(\$utils::PATH_TO_MAILQ);
if (! open (MAILQ, "$utils::PATH_TO_QMAIL_QSTAT | " ) ) {
print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
exit $ERRORS{'UNKNOWN'};
@@ -461,6 +480,7 @@
elsif ( $mailq eq "exim" ) {
## open mailq
if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
+ sudoize(\$utils::PATH_TO_MAILQ);
if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
exit $ERRORS{'UNKNOWN'};
|