From f1b81c42c9a6e53e3ce248e40ccc33a5b3ba51bc Mon Sep 17 00:00:00 2001
From: Steve Kemp <steve@steve.org.uk>
Date: Mon, 19 Nov 2012 16:24:30 +0000
Subject:   Updated to ensure we read a banner from the remote server - before
 we test against it.

---
 lib/custodian/protocol-tests/ftp.rb    | 4 ++--
 lib/custodian/protocol-tests/jabber.rb | 4 ++--
 lib/custodian/protocol-tests/rsync.rb  | 4 ++--
 lib/custodian/protocol-tests/smtp.rb   | 4 ++--
 lib/custodian/protocol-tests/ssh.rb    | 4 ++--
 lib/custodian/protocol-tests/tcp.rb    | 4 ++--
 6 files changed, 12 insertions(+), 12 deletions(-)

(limited to 'lib')

diff --git a/lib/custodian/protocol-tests/ftp.rb b/lib/custodian/protocol-tests/ftp.rb
index 2d0700a..1ecd68a 100755
--- a/lib/custodian/protocol-tests/ftp.rb
+++ b/lib/custodian/protocol-tests/ftp.rb
@@ -81,11 +81,11 @@ class FTPTest
           socket.puts( "QUIT")
 
           banner = socket.gets(nil)
-          banner = banner[0,20]
+          banner = banner[0,20] unless( banner.nil? )
 
           socket.close()
 
-          if ( banner =~ /^220/ )
+          if ( ( !banner.nil? ) && ( banner =~ /^220/ ) )
             return true
           else
             @error = "Banner didn't report OK: #{banner}"
diff --git a/lib/custodian/protocol-tests/jabber.rb b/lib/custodian/protocol-tests/jabber.rb
index 7a0c855..a35ef28 100755
--- a/lib/custodian/protocol-tests/jabber.rb
+++ b/lib/custodian/protocol-tests/jabber.rb
@@ -82,11 +82,11 @@ class JABBERTest
           socket.puts( "QUIT")
 
           banner = socket.gets(nil)
-          banner = banner[0,20]
+          banner = banner[0,20] unless( banner.nil? )
 
           socket.close()
 
-          if ( banner =~ /xml version/i )
+          if ( ( !banner.nil? ) &&  ( banner =~ /xml version/i ) )
             puts "Jabber alive: #{banner}" if ( @test_data['verbose'] )
             return true
           else
diff --git a/lib/custodian/protocol-tests/rsync.rb b/lib/custodian/protocol-tests/rsync.rb
index d2a2f45..4493d0f 100755
--- a/lib/custodian/protocol-tests/rsync.rb
+++ b/lib/custodian/protocol-tests/rsync.rb
@@ -81,11 +81,11 @@ class RSYNCTest
           socket.puts( "QUIT")
 
           banner = socket.gets(nil)
-          banner = banner[0,20]
+          banner = banner[0,20] unless( banner.nil? )
 
           socket.close()
 
-          if ( banner =~ /rsyncd/i )
+          if ( ( !banner.nil? ) && ( banner =~ /rsyncd/i ) )
             puts "rsync alive: #{banner}" if ( @test_data['verbose'] )
             return true
           else
diff --git a/lib/custodian/protocol-tests/smtp.rb b/lib/custodian/protocol-tests/smtp.rb
index 6a3895d..5da672f 100755
--- a/lib/custodian/protocol-tests/smtp.rb
+++ b/lib/custodian/protocol-tests/smtp.rb
@@ -81,11 +81,11 @@ class SMTPTest
           socket.puts( "QUIT")
 
           banner = socket.gets(nil)
-          banner = banner[0,40]
+          banner = banner[0,40] unless( banner.nil? )
 
           socket.close()
 
-          if ( banner =~ /SMTP/i )
+          if ( ( !banner.nil? ) && ( banner =~ /SMTP/i ) )
             puts "SMTP alive: #{banner}" if ( @test_data['verbose'] )
             return true
           else
diff --git a/lib/custodian/protocol-tests/ssh.rb b/lib/custodian/protocol-tests/ssh.rb
index 801a381..4ee9974 100755
--- a/lib/custodian/protocol-tests/ssh.rb
+++ b/lib/custodian/protocol-tests/ssh.rb
@@ -80,11 +80,11 @@ class SSHTest
           socket.puts( "QUIT")
 
           banner = socket.gets(nil)
-          banner = banner[0,20]
+          banner = banner[0,20] unless( banner.nil? )
 
           socket.close()
 
-          if ( banner =~ /ssh/i )
+          if ( !banner.nil? && ( banner =~ /ssh/i ) )
             puts "ssh alive: #{banner}" if ( @test_data['verbose'] )
             return true
           else
diff --git a/lib/custodian/protocol-tests/tcp.rb b/lib/custodian/protocol-tests/tcp.rb
index 08707a5..a6770e4 100755
--- a/lib/custodian/protocol-tests/tcp.rb
+++ b/lib/custodian/protocol-tests/tcp.rb
@@ -92,7 +92,7 @@ class TCPTest
           read = socket.gets(nil)
 
           # trim to a sane length & strip newlines.
-          read = read[0,255]
+          read = read[0,255] unless ( read.nil? )
           read.gsub!(/[\n\r]/, "") unless ( read.nil? )
 
           socket.close()
@@ -102,7 +102,7 @@ class TCPTest
             return true
           else
             # test for banner
-            if ( read =~ /#{banner}/i )
+            if ( ( !read.nil? ) && ( read =~ /#{banner}/i ) )
               puts "We connected and matched the banner against '#{read}'" if ( @test_data['verbose'] )
               return true
             end
-- 
cgit v1.2.3