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 : rusers 23# 24# TEST DESCRIPTION : Basic test for the `rusers` 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/18/01 Robbie Williamson (robbiew@us.ibm.com) 32# -Written 33# 34# CMD FLAG ARGS 35# rusers 36# rusers RHOST 37# rusers -a 38# rusers -a RHOST 39# rusers -l 40# rusers -l RHOST 41# rusers bogus_host 42# rusers -bogus_flag 43#*********************************************************************** 44#Uncomment line below for debug output. 45#trace_logic=${trace_logic:-"set -x"} 46 47$trace_logic 48this_file=${0##*/} 49 50TC=rusers 51TCtmp=${TCtmp:=`pwd`} 52TCbin=${TCbin:=`pwd`} 53TCsrc=${TCsrc:=$TCbin} 54LUSER=${LUSER:=root} 55RHOST=${RHOST:=`hostname`} 56CLEANUP=${CLEANUP:="ON"} 57PID=0 58export TCID=$TC 59export TST_TOTAL=1 60export TST_COUNT=1 61 62#============================================================================= 63# FUNCTION NAME: do_test 64# 65# FUNCTION DESCRIPTION: Perform the test 66# 67# PARAMETERS: None. 68# 69# RETURNS: None. 70#============================================================================= 71do_test() 72{ 73$trace_logic 74 75echo "Checking for rusersd on $RHOST" 76 77rpcinfo -u $RHOST rusersd > /dev/null 2>&1 78if [ $? -ne 0 ]; then 79 echo "Attempting to start rusersd on $RHOST" 80 rsh -n -l root $RHOST "/usr/sbin/rpc.rusersd &" 81 [ $? -eq 0 ] || end_testcase "rusersd is inactive on $RHOST" 82 PID=`rsh -n $RHOST ps -ewf | grep rusersd | awk '{print $2 }'` 83 echo "ruserd started on $RHOST" 84fi 85 86#RHOST=`echo $RHOST | cut -d. -f1` //The use is depriciated as it fails when RHOST is set to an IP address 87# //Pointed out by "Ambar Seksena" <ambar.seksena@calsoftinc.com> 88 89echo "Test rusers with defaults...please be patient" 90# rusers with no options broadcasts over the net and reports 91# responses as it receives them. Time-out for responses is approx. 2 minutes. 92 93rusers > /dev/null 94[ $? -eq 0 ] || end_testcase "rusers with defaults - failed" 95 96echo "Test rusers with options set...please be patient" 97# Go through matrix of rusers options: 98 99rusers $RHOST > /dev/null 100[ $? -eq 0 ] || end_testcase "rusers $RHOST - failed" 101 102rusers -a $RHOST > /dev/null 103[ $? -eq 0 ] || end_testcase "rusers -a $RHOST - failed" 104 105rusers -l > /dev/null 106[ $? -eq 0 ] || end_testcase "rusers -l - failed" 107 108rusers -l $RHOST > /dev/null 109[ $? -eq 0 ] || end_testcase "rusers -l $RHOST - failed" 110 111echo "Test rusers with bad options" 112 113rusers bogushost > /dev/null 2>&1 114[ $? -eq 1 ] || end_testcase "rusers <invalid hostname> should fail" 115 116rusers -bogusflag > /dev/null 2>&1 117[ $? -eq 1 ] || end_testcase "rusers -<invalid flag> should fail" 118} 119 120#============================================================================= 121# FUNCTION NAME: do_cleanup 122# 123# FUNCTION DESCRIPTION: Clean up 124# 125# PARAMETERS: None. 126# 127# RETURNS: None. 128#============================================================================= 129do_cleanup() 130{ 131 $trace_logic 132 133 if [ "$PID" != 0 ]; then 134 # Kill rusersd on remote machine 135 rsh -n $RHOST kill -9 $PID 136 echo "rusersd daemon stopped on $RHOST" 137 fi 138} 139 140#============================================================================= 141# FUNCTION NAME: end_testcase 142# 143# FUNCTION DESCRIPTION: Clean up 144# 145# PARAMETERS: string, IF AND ONLY IF the testcase fails 146# 147# RETURNS: None. 148#============================================================================= 149 150end_testcase() 151{ 152 $trace_logic 153 echo "$this_file: doing $0." 154 if [ "$CLEANUP" = "ON" ]; then 155 do_cleanup 156 fi 157 158 [ $# = 0 ] && { tst_resm TPASS "Test Successful"; exit 0; } 159 tst_resm TFAIL "Test Failed: $@" 160 exit 1 161} 162 163#============================================================================= 164# MAIN PROCEDURE 165#============================================================================= 166 167do_test 168end_testcase 169