1#!/bin/sh 2# 3# 4# Copyright (c) International Business Machines Corp., 2000 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14# the GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19# 20# 21# 22# FILE : rpcinfo 23# 24# TEST DESCRIPTION : Basic test for the `rpcinfo` command. 25# 26# SETUP: The home directory of root on the machine exported as "RHOST" 27# MUST have a ".rhosts" file with the hostname of the machine 28# where the test is executed. 29# 30# HISTORY: 31# 04/20/01 Robbie Williamson (robbiew@us.ibm.com) 32# -Written 33# 11/20/08 Aime Le Rouzic (aime.lerouzic@bull.net) 34# - Adapt to rpcbind 35# 36# CMD FLAG ARGS 37# rpcinfo -p 38# rpcinfo -p rem_host 39# rpcinfo -b 40# rpcinfo -d prog_num ver_num 41# rpcinfo -t rem_host prog_num 42# rpcinfo -t rem_host prog_num ver_num 43# rpcinfo -t rem_host prog_name 44# rpcinfo -t rem_host prog_name ver_num 45# rpcinfo -u rem_host prog_num 46# rpcinfo -u rem_host prog_num ver_num 47# rpcinfo -u rem_host prog_name 48# rpcinfo -u rem_host prog_name ver_num 49# rpcinfo 50# rpcinfo -bogus_flag 51# rpcinfo -u rem_host 52# rpcinfo -u rem_host bogus_prog ver_num 53# rpcinfo -u rem_host prog_num bogus_num 54#*********************************************************************** 55#Uncomment line below for debug output. 56#trace_logic=${trace_logic:-"set -x"} 57 58$trace_logic 59this_file=${0##*/} 60TC=rpcinfo01 61TCtmp=${TCtmp:=`pwd`} 62TCbin=${TCbin:=`pwd`} 63TCsrc=${TCsrc:=$TCbin} 64LUSER=${LUSER:=root} 65RHOST=${RHOST:=`hostname`} 66CLEANUP=${CLEANUP:="ON"} 67PID=0 68export TCID=$TC 69export TST_TOTAL=1 70export TST_COUNT=1 71 72#============================================================================= 73# FUNCTION NAME: do_test 74# 75# FUNCTION DESCRIPTION: Perform the test 76# 77# PARAMETERS: None. 78# 79# RETURNS: None. 80#============================================================================= 81do_test() 82{ 83$trace_logic 84 85echo "Checking for portmap or rpcbind daemon on `hostname` and $RHOST" 86ps -ewf | grep portmap | grep -v grep > /dev/null 87if [ $? -eq 0 ] 88then 89 PORTMAPPER="portmap" 90else 91 ps -ewf | grep rpcbind | grep -v grep > /dev/null 92 if [ $? -eq 0 ] 93 then 94 PORTMAPPER="rpcbind" 95 else 96 echo "The portmap or rpcbind daemon is NOT running" 97 fi 98fi 99 100rsh -n $RHOST "ps -ewf" | grep portmap | grep -v grep > /dev/null 101[ $? -eq 0 ] || rsh -n $RHOST "ps -ewf" | grep rpcbind | grep -v grep > /dev/null 102[ $? -eq 0 ] || end_testcase "The portmap or rpcbind daemon is NOT running on $RHOST" 103 104echo "Test rpcinfo with default options" 105echo "rpcinfo -p" 106rpcinfo -p $RHOST | grep portmapper 107[ $? -eq 0 ] || end_testcase "rpcinfo -p failed" 108 109echo "Test rpcinfo with options" 110 111 112# Create file with 1 tcp and 1 udp line. Use for variable assignments. 113rpcinfo -p $RHOST | grep tcp | sed -n 2p > $TCtmp/rpc_out 114rpcinfo -p $RHOST | grep udp | sed -n 2p >> $TCtmp/rpc_out 115 116wc -l $TCtmp/rpc_out | grep "2" > /dev/null 117[ $? -eq 0 ] || end_testcase "Not enough programs registered on $RHOST for test" 118 119# Using "rpc_out" file created above, assign variables for rpcinfo options. 120TPNUM=`grep tcp $TCtmp/rpc_out | awk '{print $1}'` 121TVNUM=`grep tcp $TCtmp/rpc_out | awk '{print $2}'` 122TCPNAME=`grep tcp $TCtmp/rpc_out | awk '{print $5}'` 123UPNUM=`grep udp $TCtmp/rpc_out | awk '{print $1}'` 124UVNUM=`grep udp $TCtmp/rpc_out | awk '{print $2}'` 125UDPNAME=`grep udp $TCtmp/rpc_out | awk '{print $5}'` 126 127# Go through the matrix of remaining rpcinfo options 128 129# -b option 130echo "rpcinfo -b <prog num> <ver num>" 131rpcinfo -b $UPNUM $UVNUM & 132sleep 5 133[ $? -eq 0 ] || end_testcase "rpcinfo -b <prog num> <ver num> - failed" 134PID=$! 135kill -9 $PID > /dev/null 2>&1 136PID=0 137 138# -d option 139ps -ewf | grep rusersd | grep -v grep 140if [ $? = 1 ]; then 141 /usr/sbin/rpc.rusersd 142 if [ $? = 0 ]; then 143 rpcinfo -p | grep 100002 144 echo "rpcinfo -d <prog num> <ver num>" 145 rpcinfo -d 100002 3 146 rpcinfo -p | grep 100002 147 rpcinfo -p | grep 100002 | wc -l | grep "1" > /dev/null 148 [ $? = 0 ] || end_testcase "rpcinfo -d <prog num> <ver num> - failed" 149 RUSERSD_PID=`ps -ewf | grep rusersd | grep -v grep | awk '{print $2}'` 150 kill -9 $RUSERSD_PID > /dev/null 2>&1 151 else 152 echo "Could not start rusersd daemon...skipping -d option test" 153 fi 154else 155 echo "rusersd is currently running, so may be used...skipping -d option test" 156fi 157 158# -t options 159echo "rpcinfo -t <hostname> <tcp prog num>" 160rpcinfo -t $RHOST $TPNUM 161[ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog num> - failed" 162 163echo "rpcinfo -t <hostname> <tcp prog num> <ver num>" 164rpcinfo -t $RHOST $TPNUM $TVNUM 165[ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog num> <ver num> - failed" 166 167echo "rpcinfo -t <hostname> <tcp prog name>" 168rpcinfo -t $RHOST $TCPNAME 169[ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog name> - failed" 170 171echo "rpcinfo -t <hostname> <tcp prog name> <ver num>" 172rpcinfo -t $RHOST $TCPNAME $TVNUM 173[ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog name> <ver num> - failed" 174 175# -u options 176echo "rpcinfo -u <hostname> <udp prog num>" 177rpcinfo -u $RHOST 100000 178[ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog num> - failed" 179 180echo "rpcinfo -u <hostname> <udp prog num> <ver num>" 181rpcinfo -u $RHOST 100000 2 182[ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog num> <ver num> - failed" 183 184echo "rpcinfo -u <hostname> <udp prog name>" 185rpcinfo -u $RHOST portmapper 186[ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog name> - failed" 187 188echo "rpcinfo -u <hostname> <udp prog name> <ver num>" 189rpcinfo -u $RHOST portmapper 2 190[ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog name> <ver num> - failed" 191 192echo "Test rpcinfo with missing or bad options" 193 194# Check the following: noflag, bogushost, bogusflag, no prog for -u or -t, 195# bogusprog, 99999 as versnum. 196 197echo "rpcinfo <no flags>" 198case $PORTMAPPER in 199 portmap) 200 rpcinfo 201 [ $? -eq 1 ] || end_testcase "rpcinfo <no flags> should fail" 202 ;; 203 rpcbind) 204 rpcinfo 205 [ $? -eq 0 ]|| end_testcase "rpcinfo <no flags> should not fail" 206 ;; 207 *) 208 echo " portmap or rpcbind not running" 209 exit 1 210 ;; 211esac 212 213echo "rpcinfo -p <bad hostname>" 214rpcinfo -p bogushost 215[ $? -eq 1 ] || end_testcase "rpcinfo <bad hostname> should fail" 216 217echo "rpcinfo <bad flag>" 218rpcinfo -bogusflag 219[ $? -eq 1 ] || end_testcase "rpcinfo <bad flag> should fail" 220 221echo "rpcinfo -t <hostname> <no prognum>" 222rpcinfo -t $RHOST 223[ $? -eq 1 ] || end_testcase "rpcinfo -t <hostname> <no prognum> should fail" 224 225echo "rpcinfo -u <hostname> <no prognum>" 226rpcinfo -u $RHOST 227[ $? -eq 1 ] || end_testcase "rpcinfo -u <hostname> <no prognum> should fail" 228 229echo "rpcinfo -u <hostname> <bad prog name>" 230rpcinfo -u $RHOST bogusprog 231[ $? -eq 1 ] || end_testcase "rpcinfo -u <hostname> <invalid program name> should fail" 232 233echo "rpcinfo -u <hostname> <bad prog num>" 234rpcinfo -u $RHOST 11579 235[ $? -eq 1 ] || end_testcase "rpcinfo -u <hostname> 11579 should fail" 236 237echo "rpcinfo -u <hostname> <prog num> <bad ver num>" 238rpcinfo -u $RHOST 100000 5 239[ $? -eq 1 ] || end_testcase "rpcinfo -u <hostname> <prog num> <bad ver num> should fail" 240} 241 242#============================================================================= 243# FUNCTION NAME: do_cleanup 244# 245# FUNCTION DESCRIPTION: Clean up 246# 247# PARAMETERS: None. 248# 249# RETURNS: None. 250#============================================================================= 251do_cleanup() 252{ 253 $trace_logic 254 255 if [ "$PID" != 0 ]; then 256 kill -9 $PID 257 fi 258 rm -f $TCtmp/rpc_out 259} 260 261#============================================================================= 262# FUNCTION NAME: end_testcase 263# 264# FUNCTION DESCRIPTION: Clean up 265# 266# PARAMETERS: string, IF AND ONLY IF the testcase fails 267# 268# RETURNS: None. 269#============================================================================= 270 271end_testcase() 272{ 273 $trace_logic 274 echo "$this_file: doing $0." 275 if [ "$CLEANUP" = "ON" ]; then 276 do_cleanup 277 fi 278 279 [ $# = 0 ] && { tst_resm TPASS "Test Successful"; exit 0; } 280 tst_resm TFAIL "Test Failed: $@" 281 exit 1 282} 283 284#============================================================================= 285# MAIN PROCEDURE 286#============================================================================= 287 288do_test 289end_testcase 290