Home | History | Annotate | Download | only in finger
      1 #!/bin/sh
      2 #
      3 #   Copyright (c) International Business Machines  Corp., 2000
      4 #
      5 #   This program is free software;  you can redistribute it and/or modify
      6 #   it under the terms of the GNU General Public License as published by
      7 #   the Free Software Foundation; either version 2 of the License, or
      8 #   (at your option) any later version.
      9 #
     10 #   This program is distributed in the hope that it will be useful,
     11 #   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13 #   the GNU General Public License for more details.
     14 #
     15 #   You should have received a copy of the GNU General Public License
     16 #   along with this program;  if not, write to the Free Software
     17 #   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18 #
     19 #
     20 #
     21 #  FILE   : finger
     22 #
     23 #  PURPOSE: To test the basic functionality of the `finger` command.
     24 #
     25 #  SETUP: The home directory of root on the machine exported as "RHOST"
     26 #         MUST have a ".rhosts" file with the hostname of the machine
     27 #         where the test is executed. Also, both machines MUST have
     28 #         the fingerd daemon active (see inetd or xinetd config file).
     29 #
     30 #  HISTORY:
     31 #    06/06/03 Manoj Iyer - manjo (at] mail.utexas.edu
     32 #      - Ported tests to use test macro
     33 #    03/01 Robbie Williamson (robbiew (at] us.ibm.com)
     34 #      -Ported
     35 #
     36 #-----------------------------------------------------------------------
     37 
     38 #-----------------------------------------------------------------------
     39 #
     40 # FUNCTION:  do_setup
     41 #
     42 #-----------------------------------------------------------------------
     43 
     44 do_setup()
     45 {
     46 
     47     # Start fingerd locally and remotely.
     48     export TST_TOTAL=3
     49 
     50     tst_setup
     51 
     52     exists awk finger hostname netstat rsh whoami
     53 
     54     LHOST=$(hostname)
     55     LUSER=$(whoami)
     56     RUSER=root
     57     RHOST=${RHOST:-$(hostname)}
     58     SLEEPTIME=${SLEEPTIME:-1}
     59 
     60     exists awk finger netstat rsh whoami
     61 
     62     [ "$LUSER" = "root" ] || end_testcase "MUST BE root to run the test!"
     63 
     64     FINGER=$(netstat -a | grep ":finger" |awk '{print $6}')
     65     if [ "$FINGER" != "LISTEN" ]; then
     66         end_testcase "Please start fingerd locally."
     67     fi
     68 
     69     FINGER=$(rsh -n $RHOST netstat -a |grep ":finger"|awk '{print $6}')
     70     if [ "$FINGER" != "LISTEN" ]; then
     71         end_testcase "Please start fingerd on remote host."
     72     fi
     73 }
     74 
     75 #-----------------------------------------------------------------------
     76 # FUNCTION: do_test1
     77 # PURPOSE: Run finger with no flags
     78 # INPUT:    None.
     79 # OUTPUT:   Error messages are logged for all discrepancies found.
     80 #-----------------------------------------------------------------------
     81 
     82 do_test1()
     83 {
     84     tst_resm TINFO "finger: do_test1 started"
     85 
     86     finger @$LHOST  2>&1 1>/dev/null
     87     [ $? = 0 ] || end_testcase "finger @$LHOST"
     88     finger @$RHOST  2>&1 1>/dev/null
     89     [ $? = 0 ] || end_testcase "finger @$RHOST"
     90 
     91     # Testing finger command with user argument
     92 
     93     finger $LUSER 2>&1 1>/dev/null || end_testcase "finger $LUSER"
     94     if ! finger $LUSER@$LHOST  2>&1 1>/dev/null; then
     95         end_testcase "finger $LUSER@$LHOST"
     96     fi
     97     finger $RUSER@$RHOST 2>&1 1>/dev/null || end_testcase "finger @$RUSER"
     98 }
     99 
    100 #-----------------------------------------------------------------------
    101 # FUNCTION: do_test2
    102 # PURPOSE:  To run the "finger User@host" commands and verify that the
    103 #           "finger" command is functioning properly.
    104 # INPUT:    None.
    105 # OUTPUT:   Error messages are logged for all discrepancies found.
    106 #-----------------------------------------------------------------------
    107 
    108 do_test2()
    109 {
    110     tst_resm TINFO "finger: do_test2 (-bad flag) started"
    111     BADUSER="uuuu"
    112     BADHOST="xxxx"
    113 
    114     tst_resm TINFO "finger -badflag default "
    115     finger -x 2> /dev/null && end_testcase "finger -x should fail"
    116 
    117     tst_resm TINFO "finger -bad user "
    118     [ "$(finger $BADUSER 2>&1 1>/dev/null)" ] || end_testcase "finger $BADUSER"
    119     [ "$(finger @$BADHOST 2>&1 1>/dev/null)" ] || \
    120         end_testcase "finger @$BADHOST"
    121     [ "$(finger $BADUSER@$BADHOST 2>&1 1>/dev/null)" ] || \
    122         end_testcase "finger $BADUSER@$BADHOST"
    123 }
    124 
    125 #-----------------------------------------------------------------------
    126 # FUNCTION: do_test3
    127 # PURPOSE:  To run the "finger -flag User@Host" commands and verify that the
    128 #           "finger" command is functioning properly.
    129 # INPUT:    None.
    130 # OUTPUT:   Error messages are logged for all discrepancies found.
    131 #-----------------------------------------------------------------------
    132 
    133 do_test3()
    134 {
    135     tst_resm TINFO "finger: do_test3 (-f flag) started"
    136 
    137     tst_resm TINFO "finger -l : gives a long listing"
    138     finger -l  2>&1 1>/dev/null || end_testcase "finger -l"
    139     finger -l $LUSER 2>&1 1>/dev/null || end_testcase "finger -l $LUSER"
    140     finger -l @$LHOST 2>&1 1>/dev/null || end_testcase "finger -l @$LHOST"
    141     if ! finger -l $LUSER@$LHOST 2>&1 1>/dev/null; then
    142         end_testcase "finger -l $LUSER@$LHOST"
    143     fi
    144     finger -l @$RHOST  2>&1 1>/dev/null || end_testcase "finger -l @$RHOST"
    145     if ! finger -l $RUSER@$RHOST  2>&1 1>/dev/null; then
    146         end_testcase "finger -l $RUSER@$RHOST"
    147     fi
    148 
    149     tst_resm TINFO "finger -m : assures that user is a user ID discretionary"
    150     finger -m 2>&1 1>/dev/null || end_testcase "finger -m"
    151     finger -m $LUSER 2>&1 1>/dev/null || end_testcase "finger -m $LUSER"
    152     finger -m @$LHOST 2>&1 1>/dev/null || end_testcase "finger -m @$LHOST"
    153     if ! finger -m $LUSER@$LHOST 2>&1 1>/dev/null; then
    154         end_testcase "finger -m $LUSER@$LHOST"
    155     fi
    156     finger -m @$RHOST 2>&1 1>/dev/null || end_testcase "finger -m @$RHOST"
    157     if ! finger -m $RUSER@$RHOST  2>&1 1>/dev/null; then
    158         end_testcase "finger -m $RUSER@$RHOST"
    159     fi
    160 
    161     tst_resm TINFO "finger -p : suppresses printing of .plan files on long and \
    162         brief long formats"
    163     finger -p  2>&1 1>/dev/null || end_testcase "finger -p"
    164     finger -p $LUSER  2>&1 1>/dev/null || end_testcase "finger -p $LUSER"
    165     finger -p @$LHOST  2>&1 1>/dev/null || end_testcase "finger -p @$LHOST"
    166     if ! finger -p $LUSER@$LHOST  2>&1 1>/dev/null; then
    167         end_testcase "finger -p $LUSER@$LHOST"
    168     fi
    169     finger -p @$RHOST  2>&1 1>/dev/null || end_testcase "finger -p @$RHOST"
    170     if ! finger -p $RUSER@$RHOST 2>&1 1>/dev/null; then
    171         end_testcase "finger -p $RUSER@$RHOST"
    172     fi
    173 
    174     tst_resm TINFO "finger -s : gives a short format list"
    175     finger -s  2>&1 1>/dev/null || end_testcase "finger -s"
    176     finger -s $LUSER 2>&1 1>/dev/null || end_testcase "finger -s $LUSER "
    177     finger -s @$LHOST 2>&1 1>/dev/null || end_testcase "finger -s @$LHOST"
    178     if ! finger -s $LUSER@$LHOST 2>&1 1>/dev/null; then
    179         end_testcase "finger -s $LUSER@$LHOST"
    180     fi
    181     finger -s @$RHOST 2>&1 1>/dev/null || end_testcase "finger -s @$RHOST"
    182     if ! finger -s $RUSER@$RHOST 2>&1 1>/dev/null; then
    183         end_testcase "finger -s $RUSER@$RHOST"
    184     fi
    185 
    186 }
    187 
    188 #-----------------------------------------------------------------------
    189 # FUNCTION: MAIN
    190 # PURPOSE:  To invoke the functions to perform the tasks outlined in the
    191 #           prologue.
    192 # INPUT:    None.
    193 # OUTPUT:   None.
    194 #-----------------------------------------------------------------------
    195 . net_cmdlib.sh
    196 
    197 read_opts $*
    198 do_setup
    199 for TST_COUNT in 1 2 3; do
    200     eval "do_test$TST_COUNT"
    201     sleep $SLEEPTIME
    202 done
    203 end_testcase
    204