diff options
Diffstat (limited to 'web/attachments/284178-34_fix_smbclient_check_disk_smb.dpatch')
-rw-r--r-- | web/attachments/284178-34_fix_smbclient_check_disk_smb.dpatch | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/web/attachments/284178-34_fix_smbclient_check_disk_smb.dpatch b/web/attachments/284178-34_fix_smbclient_check_disk_smb.dpatch new file mode 100644 index 0000000..0e53eb1 --- /dev/null +++ b/web/attachments/284178-34_fix_smbclient_check_disk_smb.dpatch | |||
@@ -0,0 +1,138 @@ | |||
1 | #! /bin/sh /usr/share/dpatch/dpatch-run | ||
2 | ## 34_fix_smbclient_check_disk_smb.dpatch by Jan Wagner <waja@cyconet.org> | ||
3 | ## patch provided by Stephane Chazelas <stephane@artesyncp.com> | ||
4 | ## | ||
5 | ## DP: Fixes use of smbclient | ||
6 | |||
7 | @DPATCH@ | ||
8 | diff -urNad nagios-plugins-1.4.12~/plugins-scripts/check_disk_smb.pl nagios-plugins-1.4.12/plugins-scripts/check_disk_smb.pl | ||
9 | --- nagios-plugins-1.4.12~/plugins-scripts/check_disk_smb.pl 2008-07-02 23:08:03.000000000 +0200 | ||
10 | +++ nagios-plugins-1.4.12/plugins-scripts/check_disk_smb.pl 2008-07-02 23:10:42.000000000 +0200 | ||
11 | @@ -26,17 +26,13 @@ | ||
12 | use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $opt_a $verbose); | ||
13 | use vars qw($PROGNAME); | ||
14 | use lib utils.pm ; | ||
15 | -use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); | ||
16 | +use utils qw($TIMEOUT %ERRORS &print_revision &support &usage &output_and_error_of); | ||
17 | |||
18 | sub print_help (); | ||
19 | sub print_usage (); | ||
20 | |||
21 | $PROGNAME = "check_disk_smb"; | ||
22 | |||
23 | -$ENV{'PATH'}=''; | ||
24 | -$ENV{'BASH_ENV'}=''; | ||
25 | -$ENV{'ENV'}=''; | ||
26 | - | ||
27 | Getopt::Long::Configure('bundling'); | ||
28 | GetOptions | ||
29 | ("v" => \$verbose, "verbose" => \$verbose, | ||
30 | @@ -59,9 +55,7 @@ | ||
31 | |||
32 | if ($opt_h) {print_help(); exit $ERRORS{'OK'};} | ||
33 | |||
34 | -my $smbclient= "$utils::PATH_TO_SMBCLIENT " ; | ||
35 | -my $smbclientoptions= $opt_P ? "-p $opt_P " : ""; | ||
36 | - | ||
37 | +my $smbclient = $utils::PATH_TO_SMBCLIENT; | ||
38 | |||
39 | # Options checking | ||
40 | |||
41 | @@ -73,13 +67,12 @@ | ||
42 | my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9]+\$?)$/); | ||
43 | ($share) || usage("Invalid share: $opt_s\n"); | ||
44 | |||
45 | -($opt_u) || ($opt_u = shift @ARGV) || ($opt_u = "guest"); | ||
46 | -my $user = $1 if ($opt_u =~ /^([-_.A-Za-z0-9\\]+)$/); | ||
47 | -($user) || usage("Invalid user: $opt_u\n"); | ||
48 | +defined($opt_u) || ($opt_u = shift @ARGV) || ($opt_u = "guest"); | ||
49 | +my $user = $1 if ($opt_u =~ /^([-_.A-Za-z0-9\\]*)$/); | ||
50 | +defined($user) || usage("Invalid user: $opt_u\n"); | ||
51 | |||
52 | -($opt_p) || ($opt_p = shift @ARGV) || ($opt_p = ""); | ||
53 | +defined($opt_p) || ($opt_p = shift @ARGV) || ($opt_p = ""); | ||
54 | my $pass = $1 if ($opt_p =~ /(.*)/); | ||
55 | -$pass = "-N" if ($opt_p eq ""); | ||
56 | |||
57 | ($opt_w) || ($opt_w = shift @ARGV) || ($opt_w = 85); | ||
58 | my $warn = $1 if ($opt_w =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); | ||
59 | @@ -163,23 +156,19 @@ | ||
60 | |||
61 | # Execute an "ls" on the share using smbclient program | ||
62 | # get the results into $res | ||
63 | -if (defined($workgroup)) { | ||
64 | - if (defined($address)) { | ||
65 | - print "$smbclient " . "\/\/$host\/$share" ." $pass -W $workgroup -U $user $smbclientoptions -I $address -c ls\n" if ($verbose); | ||
66 | - $res = qx/$smbclient "\/\/$host\/$share" $pass -W $workgroup -U $user $smbclientoptions -I $address -c ls/; | ||
67 | - } else { | ||
68 | - print "$smbclient " . "\/\/$host\/$share" ." $pass -W $workgroup -U $user $smbclientoptions -c ls\n" if ($verbose); | ||
69 | - $res = qx/$smbclient "\/\/$host\/$share" $pass -W $workgroup -U $user $smbclientoptions -c ls/; | ||
70 | - } | ||
71 | -} else { | ||
72 | - if (defined($address)) { | ||
73 | - print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -I $address -c ls\n" if ($verbose); | ||
74 | - $res = qx/$smbclient "\/\/$host\/$share" $pass -U $user $smbclientoptions -I $address -c ls/; | ||
75 | - } else { | ||
76 | - print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -c ls\n" if ($verbose); | ||
77 | - $res = qx/$smbclient "\/\/$host\/$share" $pass -U $user $smbclientoptions -c ls/; | ||
78 | - } | ||
79 | -} | ||
80 | +my @cmd = ( | ||
81 | + $smbclient, | ||
82 | + "//$host/$share", | ||
83 | + "-U", "$user%$pass", | ||
84 | + defined($workgroup) ? ("-W", $workgroup) : (), | ||
85 | + defined($address) ? ("-I", $address) : (), | ||
86 | + defined($opt_P) ? ("-p", $opt_P) : (), | ||
87 | + "-c", "ls" | ||
88 | +); | ||
89 | + | ||
90 | +print join(" ", @cmd) . "\n" if ($verbose); | ||
91 | +$res = output_and_error_of(@cmd) or exit $ERRORS{"UNKNOWN"}; | ||
92 | + | ||
93 | #Turn off alarm | ||
94 | alarm(0); | ||
95 | |||
96 | diff -urNad nagios-plugins-1.4.12~/plugins-scripts/utils.pm.in nagios-plugins-1.4.12/plugins-scripts/utils.pm.in | ||
97 | --- nagios-plugins-1.4.12~/plugins-scripts/utils.pm.in 2007-07-07 13:55:48.000000000 +0200 | ||
98 | +++ nagios-plugins-1.4.12/plugins-scripts/utils.pm.in 2008-07-02 23:08:04.000000000 +0200 | ||
99 | @@ -8,7 +8,8 @@ | ||
100 | |||
101 | require Exporter; | ||
102 | @ISA = qw(Exporter); | ||
103 | -@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage); | ||
104 | +@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage | ||
105 | + &output_of &output_and_error_of); | ||
106 | |||
107 | #use strict; | ||
108 | #use vars($TIMEOUT %ERRORS); | ||
109 | @@ -67,4 +68,29 @@ | ||
110 | } | ||
111 | } | ||
112 | |||
113 | +sub output_of { | ||
114 | + local *CMD; | ||
115 | + local $/ = undef; | ||
116 | + if (open CMD, "-|", @_) { | ||
117 | + return <CMD>; | ||
118 | + close CMD; | ||
119 | + } | ||
120 | + return undef; | ||
121 | +} | ||
122 | + | ||
123 | +sub output_and_error_of { | ||
124 | + local *CMD; | ||
125 | + local $/ = undef; | ||
126 | + my $pid = open CMD, "-|"; | ||
127 | + if (defined($pid)) { | ||
128 | + if ($pid) { | ||
129 | + return <CMD>; | ||
130 | + } else { | ||
131 | + open STDERR, ">&STDOUT" and exec @_; | ||
132 | + exit(1); | ||
133 | + } | ||
134 | + } | ||
135 | + return undef; | ||
136 | +} | ||
137 | + | ||
138 | 1; | ||