Home | History | Annotate | Download | only in rpcinfo
      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 (at] us.ibm.com)
     32 #      -Written
     33 #    11/20/08 Aime Le Rouzic (aime.lerouzic (at] 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
     59 this_file=${0##*/}
     60 TC=rpcinfo01
     61 TCtmp=${TCtmp:=`pwd`}
     62 TCbin=${TCbin:=`pwd`}
     63 TCsrc=${TCsrc:=$TCbin}
     64 LUSER=${LUSER:=root}
     65 RHOST=${RHOST:=`hostname`}
     66 CLEANUP=${CLEANUP:="ON"}
     67 PID=0
     68 export TCID=$TC
     69 export TST_TOTAL=1
     70 export 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 #=============================================================================
     81 do_test()
     82 {
     83 $trace_logic
     84 
     85 echo "Checking for portmap or rpcbind daemon on `hostname` and $RHOST"
     86 ps -ewf | grep portmap | grep -v grep > /dev/null
     87 if [ $? -eq 0 ]
     88 then
     89 	PORTMAPPER="portmap"
     90 else
     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
     98 fi
     99 
    100 rsh -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 
    104 echo "Test rpcinfo with default options"
    105 echo "rpcinfo -p"
    106 rpcinfo -p $RHOST | grep portmapper
    107 [ $? -eq 0 ] || end_testcase "rpcinfo -p failed"
    108 
    109 echo "Test rpcinfo with options"
    110 
    111 
    112 # Create file with 1 tcp and 1 udp line. Use for variable assignments.
    113 rpcinfo -p $RHOST | grep tcp | sed -n 2p > $TCtmp/rpc_out
    114 rpcinfo -p $RHOST | grep udp | sed -n 2p >> $TCtmp/rpc_out
    115 
    116 wc -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.
    120 TPNUM=`grep tcp $TCtmp/rpc_out | awk '{print $1}'`
    121 TVNUM=`grep tcp $TCtmp/rpc_out | awk '{print $2}'`
    122 TCPNAME=`grep tcp $TCtmp/rpc_out | awk '{print $5}'`
    123 UPNUM=`grep udp $TCtmp/rpc_out | awk '{print $1}'`
    124 UVNUM=`grep udp $TCtmp/rpc_out | awk '{print $2}'`
    125 UDPNAME=`grep udp $TCtmp/rpc_out | awk '{print $5}'`
    126 
    127 # Go through the matrix of remaining rpcinfo options
    128 
    129 # -b option
    130 echo "rpcinfo -b <prog num> <ver num>"
    131 rpcinfo -b $UPNUM $UVNUM &
    132 sleep 5
    133 [ $? -eq 0 ] || end_testcase "rpcinfo -b <prog num> <ver num> - failed"
    134 PID=$!
    135 kill -9 $PID > /dev/null 2>&1
    136 PID=0
    137 
    138 # -d option
    139 ps -ewf | grep rusersd | grep -v grep
    140 if [ $? = 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
    154 else
    155   echo "rusersd is currently running, so may be used...skipping -d option test"
    156 fi
    157 
    158 # -t options
    159 echo "rpcinfo -t <hostname> <tcp prog num>"
    160 rpcinfo -t $RHOST $TPNUM
    161 [ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog num> - failed"
    162 
    163 echo "rpcinfo -t <hostname> <tcp prog num> <ver num>"
    164 rpcinfo -t $RHOST $TPNUM $TVNUM
    165 [ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog num> <ver num> - failed"
    166 
    167 echo "rpcinfo -t <hostname> <tcp prog name>"
    168 rpcinfo -t $RHOST $TCPNAME
    169 [ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog name> -  failed"
    170 
    171 echo "rpcinfo -t <hostname> <tcp prog name> <ver num>"
    172 rpcinfo -t $RHOST $TCPNAME $TVNUM
    173 [ $? -eq 0 ] || end_testcase "rpcinfo -t <hostname> <tcp prog name> <ver num> - failed"
    174 
    175 # -u options
    176 echo "rpcinfo -u <hostname> <udp prog num>"
    177 rpcinfo -u $RHOST 100000
    178 [ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog num> - failed"
    179 
    180 echo "rpcinfo -u <hostname> <udp prog num> <ver num>"
    181 rpcinfo -u $RHOST 100000 2
    182 [ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog num> <ver num> - failed"
    183 
    184 echo "rpcinfo -u <hostname> <udp prog name>"
    185 rpcinfo -u $RHOST portmapper
    186 [ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog name> - failed"
    187 
    188 echo "rpcinfo -u <hostname> <udp prog name> <ver num>"
    189 rpcinfo -u $RHOST portmapper 2
    190 [ $? -eq 0 ] || end_testcase "rpcinfo -u <hostname> <udp prog name> <ver num> - failed"
    191 
    192 echo "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 
    197 echo "rpcinfo <no flags>"
    198 case $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 		;;
    211 esac
    212 
    213 echo "rpcinfo -p <bad hostname>"
    214 rpcinfo -p bogushost
    215 [ $? -eq 1 ] || end_testcase "rpcinfo <bad hostname> should fail"
    216 
    217 echo "rpcinfo <bad flag>"
    218 rpcinfo -bogusflag
    219 [ $? -eq 1 ] || end_testcase "rpcinfo <bad flag> should fail"
    220 
    221 echo "rpcinfo -t <hostname> <no prognum>"
    222 rpcinfo -t $RHOST
    223 [ $? -eq 1 ] || end_testcase "rpcinfo -t <hostname> <no prognum> should fail"
    224 
    225 echo "rpcinfo -u <hostname> <no prognum>"
    226 rpcinfo -u $RHOST
    227 [ $? -eq 1 ] || end_testcase "rpcinfo -u <hostname> <no prognum> should fail"
    228 
    229 echo "rpcinfo -u <hostname> <bad prog name>"
    230 rpcinfo -u $RHOST bogusprog
    231 [ $? -eq 1 ] || end_testcase "rpcinfo -u <hostname> <invalid program name> should fail"
    232 
    233 echo "rpcinfo -u <hostname> <bad prog num>"
    234 rpcinfo -u $RHOST 11579
    235 [ $? -eq 1 ] || end_testcase "rpcinfo -u <hostname> 11579 should fail"
    236 
    237 echo "rpcinfo -u <hostname> <prog num> <bad ver num>"
    238 rpcinfo -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 #=============================================================================
    251 do_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 
    271 end_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 
    288 do_test
    289 end_testcase
    290