fix usage of smbclient

This commit is contained in:
Jan Wagner 2008-06-06 10:35:51 +00:00
parent 31be3d3d44
commit 7806d01e88
3 changed files with 157 additions and 1 deletions

4
debian/changelog vendored
View file

@ -26,13 +26,15 @@ nagios-plugins (1.4.12-1) UNRELEASED; urgency=low
informations see REQUIREMENTS)
* add 33_fix_emb_check_disk_smb.dpatch which fixes processing via embedded
perl of check_disk_smb (Closes: #478906)
* add 34_fix_smbclient_check_disk_smb.dpatch which fixes usage of smbclient
(Closes: #478942)
[ Alexander Wirt ]
* Call smbclient with -N (supress password prompt) if no password is
supplied. Thanks to Josip Rodin for the patch (Closes: #425129)
* Add myself to uploaders
-- Jan Wagner <waja@cyconet.org> Sun, 04 May 2008 14:18:55 +0200
-- Jan Wagner <waja@cyconet.org> Fri, 06 Jun 2008 12:25:59 +0200
nagios-plugins (1.4.11-2) unstable; urgency=low

View file

@ -8,4 +8,5 @@
27_check_radius_segfault.dpatch
32_check_ldap_pointer.dpatch
33_fix_emb_check_disk_smb.dpatch
34_fix_smbclient_check_disk_smb.dpatch
50_misc_typos.dpatch

View file

@ -0,0 +1,153 @@
#! /bin/sh /usr/share/dpatch/dpatch-run
## 34_fix_smbclient_check_disk_smb.dpatch by Jan Wagner <waja@cyconet.org>
## patch provided by Stephane Chazelas <stephane@artesyncp.com>
##
## DP: Fixes use of smbclient
@DPATCH@
diff -urNad nagios-plugins-1.4.12~/plugins-scripts/check_disk_smb.pl nagios-plugins-1.4.12/plugins-scripts/check_disk_smb.pl
--- nagios-plugins-1.4.12~/plugins-scripts/check_disk_smb.pl 2008-06-06 12:19:16.000000000 +0200
+++ nagios-plugins-1.4.12/plugins-scripts/check_disk_smb.pl 2008-06-06 12:19:16.000000000 +0200
@@ -26,17 +26,13 @@
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);
use vars qw($PROGNAME);
use lib utils.pm ;
-use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
+use utils qw($TIMEOUT %ERRORS &print_revision &support &usage &output_and_error_of);
sub print_help ();
sub print_usage ();
$PROGNAME = "check_disk_smb";
-$ENV{'PATH'}='';
-$ENV{'BASH_ENV'}='';
-$ENV{'ENV'}='';
-
Getopt::Long::Configure('bundling');
GetOptions
("v" => \$verbose, "verbose" => \$verbose,
@@ -59,9 +55,7 @@
if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
-my $smbclient= "$utils::PATH_TO_SMBCLIENT " ;
-my $smbclientoptions= $opt_P ? "-p $opt_P " : "";
-
+my $smbclient = $utils::PATH_TO_SMBCLIENT;
# Options checking
diff -urNad nagios-plugins-1.4.12~/plugins-scripts/check_disk_smb.pl.rej nagios-plugins-1.4.12/plugins-scripts/check_disk_smb.pl.rej
--- nagios-plugins-1.4.12~/plugins-scripts/check_disk_smb.pl.rej 1970-01-01 01:00:00.000000000 +0100
+++ nagios-plugins-1.4.12/plugins-scripts/check_disk_smb.pl.rej 2008-06-06 12:19:16.000000000 +0200
@@ -0,0 +1,66 @@
+***************
+*** 72,80 ****
+ my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9]+\$?)$/);
+ ($share) || usage("Invalid share: $opt_s\n");
+
+- ($opt_u) || ($opt_u = shift @ARGV) || ($opt_u = "guest");
+- my $user = $1 if ($opt_u =~ /^([-_.A-Za-z0-9\\]+)$/);
+- ($user) || usage("Invalid user: $opt_u\n");
+
+ ($opt_p) || ($opt_p = shift @ARGV) || ($opt_p = "");
+ my $pass = $1 if ($opt_p =~ /(.*)/);
+--- 66,74 ----
+ my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9]+\$?)$/);
+ ($share) || usage("Invalid share: $opt_s\n");
+
++ defined($opt_u) || ($opt_u = shift @ARGV) || ($opt_u = "guest");
++ my $user = $1 if ($opt_u =~ /^([-_.A-Za-z0-9\\]*)$/);
++ defined($user) || usage("Invalid user: $opt_u\n");
+
+ ($opt_p) || ($opt_p = shift @ARGV) || ($opt_p = "");
+ my $pass = $1 if ($opt_p =~ /(.*)/);
+***************
+*** 162,184 ****
+
+ # Execute an "ls" on the share using smbclient program
+ # get the results into $res
+- if (defined($workgroup)) {
+- if (defined($address)) {
+- print "$smbclient " . "\/\/$host\/$share" ." $pass -W $workgroup -U $user $smbclientoptions -I $address -c ls\n" if ($verbose);
+- $res = qx/$smbclient "\/\/$host\/$share" $pass -W $workgroup -U $user $smbclientoptions -I $address -c ls/;
+- } else {
+- print "$smbclient " . "\/\/$host\/$share" ." $pass -W $workgroup -U $user $smbclientoptions -c ls\n" if ($verbose);
+- $res = qx/$smbclient "\/\/$host\/$share" $pass -W $workgroup -U $user $smbclientoptions -c ls/;
+- }
+- } else {
+- if (defined($address)) {
+- print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -I $address -c ls\n" if ($verbose);
+- $res = qx/$smbclient "\/\/$host\/$share" $pass -U $user $smbclientoptions -I $address -c ls/;
+- } else {
+- print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -c ls\n" if ($verbose);
+- $res = qx/$smbclient "\/\/$host\/$share" $pass -U $user $smbclientoptions -c ls/;
+- }
+- }
+ #Turn off alarm
+ alarm(0);
+
+--- 156,174 ----
+
+ # Execute an "ls" on the share using smbclient program
+ # get the results into $res
++ my @cmd = (
++ $smbclient,
++ "//$host/$share",
++ "-U", "$user%$pass",
++ defined($workgroup) ? ("-W", $workgroup) : (),
++ defined($address) ? ("-I", $address) : (),
++ defined($opt_P) ? ("-p", $opt_P) : (),
++ "-c", "ls"
++ );
++
++ print join(" ", @cmd) . "\n" if ($verbose);
++ $res = output_and_error_of(@cmd) or exit $ERRORS{"UNKNOWN"};
++
+ #Turn off alarm
+ alarm(0);
+
diff -urNad nagios-plugins-1.4.12~/plugins-scripts/utils.pm.in nagios-plugins-1.4.12/plugins-scripts/utils.pm.in
--- nagios-plugins-1.4.12~/plugins-scripts/utils.pm.in 2007-07-07 13:55:48.000000000 +0200
+++ nagios-plugins-1.4.12/plugins-scripts/utils.pm.in 2008-06-06 12:21:06.000000000 +0200
@@ -8,7 +8,8 @@
require Exporter;
@ISA = qw(Exporter);
-@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage);
+@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage
+ &output_of &output_and_error_of);
#use strict;
#use vars($TIMEOUT %ERRORS);
@@ -67,4 +68,29 @@
}
}
+sub output_of {
+ local *CMD;
+ local $/ = undef;
+ if (open CMD, "-|", @_) {
+ return <CMD>;
+ close CMD;
+ }
+ return undef;
+}
+
+sub output_and_error_of {
+ local *CMD;
+ local $/ = undef;
+ my $pid = open CMD, "-|";
+ if (defined($pid)) {
+ if ($pid) {
+ return <CMD>;
+ } else {
+ open STDERR, ">&STDOUT" and exec @_;
+ exit(1);
+ }
+ }
+ return undef;
+}
+
1;