1#!/bin/sh 2# Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved. 3# Copyright (c) International Business Machines Corp., 2001 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License as 7# published by the Free Software Foundation; either version 2 of 8# the License, or (at your option) any later version. 9# 10# This program is distributed in the hope that it would be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# 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, see <http://www.gnu.org/licenses/>. 17 18TCID=xinetd 19TST_TOTAL=2 20TST_CLEANUP="cleanup" 21 22. daemonlib.sh 23TST_USE_LEGACY_API=1 24. tst_net.sh 25 26setup() 27{ 28 [ -f "/usr/lib/systemd/system/telnet.socket" ] && \ 29 tst_brkm TCONF "xinetd doesn't manage telnet" 30 31 tst_tmpdir 32 33 tst_test_cmds xinetd diff telnet 34 35 check_addr="127.0.0.1" 36 ip a | grep -q inet6 && check_addr="$check_addr ::1" 37 38 # Create custom xinetd.conf file. 39 # tst_xinetd.conf.1 config file has telnet service disabled. 40 cat > tst_xinetd.conf.1 <<-EOF 41defaults 42{ 43 instances = 25 44 log_type = FILE /var/log/servicelog 45 log_on_success = HOST PID 46 log_on_failure = HOST 47 disabled = telnet 48} 49EOF 50 51 cat > tst_xinetd.conf.2 <<-EOF 52defaults 53{ 54 instances = 25 55 log_type = FILE /var/log/servicelog 56 log_on_success = HOST PID 57 log_on_failure = HOST 58 # disabled = telnet 59} 60 61service telnet 62{ 63 socket_type = stream 64 protocol = tcp 65 wait = no 66 user = root 67 server = /usr/sbin/in.telnetd 68 server_args = -n 69 no_access = 70 flags = IPv6 71} 72EOF 73 74 # create a backup of the original xinetd.conf file. 75 ROD mv /etc/xinetd.conf xinetd.conf.orig 76} 77 78cleanup() 79{ 80 # restore the original xinetd.conf if a back up exits. 81 [ -f xinetd.conf.orig ] && \ 82 mv xinetd.conf.orig /etc/xinetd.conf 83 84 # restoring original services 85 restart_daemon xinetd 86 87 tst_rmdir 88} 89 90restart_xinetd() 91{ 92 tst_resm TINFO "restart xinetd" 93 # restart xinetd to re-start the services 94 restart_daemon xinetd > tst_xinetd.out 2>&1 95 if [ $? -ne 0 ]; then 96 cat tst_xinetd.out 97 tst_brkm TBROK "unable to restart service with telnet disabled" 98 fi 99 100 # even if xinetd restart has zero exit value, 101 # make certain there was no failure. 102 grep -qi "fail" tst_xinetd.out && \ 103 tst_brkm TBROK "xinetd failed to restart" 104} 105 106# Description: - Test that xinetd reads the configuration file and starts or 107# stops services. 108# - restart xinetd with configuration file with telnet disabled. 109# - telnet to locahost should fail. 110# - restart xinetd with configuration file with telnet enabled. 111# - telnet to locahost should work. 112test01() 113{ 114 tst_resm TINFO "install the new config file with telnet disabled" 115 ROD mv tst_xinetd.conf.1 /etc/xinetd.conf 116 restart_xinetd 117 118 for a in $check_addr; do 119 echo '' | telnet $a 2>&1 | grep -qi \ 120 "telnet: connect to address $a: Connection refused" 121 [ $? -ne 0 ] && \ 122 tst_brkm TFAIL "not expected output for 'telnet $a'" 123 done 124 125 tst_resm TPASS "expected output with telnet disabled" 126 127 tst_resm TINFO "install the xinetd config file with telnet enabled" 128 ROD mv tst_xinetd.conf.2 /etc/xinetd.conf 129 restart_xinetd 130 131 for a in $check_addr; do 132 echo '' | telnet $a 2>&1 | grep -qi \ 133 "Connection closed by foreign host" 134 [ $? -ne 0 ] && \ 135 tst_brkm TFAIL "not expected output for 'telnet $a'" 136 done 137 138 tst_resm TPASS "expected output with telnet enabled" 139} 140 141setup 142 143test01 144 145tst_exit 146