From 3e5555fb124486ecdd17bee34ef93e69f61c8848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Boraty=C5=84ski?= Date: Tue, 22 Mar 2016 23:53:58 +0100 Subject: [PATCH 1/3] Added listening function. Listening functions checks whether there exist a service listening on specified protocol and port. --- include/functions | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/functions b/include/functions index 82fa195f..8ef50d2b 100644 --- a/include/functions +++ b/include/functions @@ -49,6 +49,7 @@ # IsWorldExecutable Check if a file is world executable # IsWorldReadable Check if a file is world readable # IsWorldWritable Check if a file is world writable +# IsTcpUdpListening Check if machine is listening on specified protocol and port # LogText Log text strings to logfile, prefixed with date/time # ParseNginx Parse nginx configuration lines # Progress Show progress on screen @@ -118,6 +119,30 @@ } + ################################################################################ + # Name : IsTcpUdpListening() + # Description : Check if machine is listening on specified protocol and port + # Returns : 0 or 1 + ################################################################################ + + IsTcpUdpListening() + { + LISTENING=0 + if [ $# -eq 2 ] && [ $1 = "TCP" -o $1 = "UDP" ]; then + LogText "Test: find service listening on $1:$2" + FIND=`lsof -i${1} -s${1}:LISTEN | grep "${2}" | wc -l` + if [ ! "${FIND}" = "" ]; then + LogText "Result: found service listening on $1:$2" + LISTENING=1 + else + LogText "Result: did not find service listening on $1:$2" + fi + else + ReportException ${TEST_NO} "Error in function call to IsTcpUdpListening" + return 1 + fi + } + ################################################################################ # Name : CheckItem() # Description : Check if a specific item exists in the report From 232419df8c0c4d9dee887a119d9fb11d14b17ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Boraty=C5=84ski?= Date: Tue, 22 Mar 2016 23:54:38 +0100 Subject: [PATCH 2/3] Modified SSH service checking. --- include/tests_ssh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/tests_ssh b/include/tests_ssh index 15948550..72c5732a 100644 --- a/include/tests_ssh +++ b/include/tests_ssh @@ -39,7 +39,8 @@ if [ ${SKIPTEST} -eq 0 ]; then LogText "Test: Searching for a SSH daemon" IsRunning sshd - if [ ${RUNNING} -eq 1 ]; then + IsTcpUdpListening "TCP" 22 + if [ ${RUNNING} -eq 1 ] || [ ${LISTENING} -eq 1 ]; then SSH_DAEMON_RUNNING=1 Display --indent 2 --text "- Checking running SSH daemon" --result FOUND --color GREEN else From 1f320f68c2e742c98d0850c5d569850f91cc1fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Boraty=C5=84ski?= Date: Tue, 22 Mar 2016 23:57:09 +0100 Subject: [PATCH 3/3] Fixed IsTcpUdpListening function --- include/functions | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/functions b/include/functions index 8ef50d2b..bed754ea 100644 --- a/include/functions +++ b/include/functions @@ -122,7 +122,7 @@ ################################################################################ # Name : IsTcpUdpListening() # Description : Check if machine is listening on specified protocol and port - # Returns : 0 or 1 + # Returns : LISTENING (0 or 1) ################################################################################ IsTcpUdpListening() @@ -139,7 +139,6 @@ fi else ReportException ${TEST_NO} "Error in function call to IsTcpUdpListening" - return 1 fi }