blob: 25ec91d26c847ff6cc258fb8cae781c44d49ae1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
# Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
# Copyright (c) International Business Machines Corp., 2001
TST_SETUP="setup"
TST_CLEANUP="cleanup"
TST_NEEDS_CMDS="diff telnet in.telnetd xinetd"
TST_NEEDS_TMPDIR=1
TST_TESTFUNC="do_test"
TST_CNT=2
. daemonlib.sh
setup()
{
[ -f "/usr/lib/systemd/system/telnet.socket" ] && \
tst_brk TCONF "xinetd doesn't manage telnet"
check_addr="127.0.0.1"
ip a | grep -q inet6 && check_addr="$check_addr ::1"
cat > tst_xinetd.conf.1 <<-EOF
defaults
{
instances = 25
log_type = FILE /var/log/servicelog
log_on_success = HOST PID
log_on_failure = HOST
disabled = telnet
}
EOF
cat > tst_xinetd.conf.2 <<-EOF
defaults
{
instances = 25
log_type = FILE /var/log/servicelog
log_on_success = HOST PID
log_on_failure = HOST
# disabled = telnet
}
service telnet
{
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/in.telnetd
server_args = -n
no_access =
flags = IPv6
}
EOF
ROD mv /etc/xinetd.conf xinetd.conf.orig
}
cleanup()
{
[ -f xinetd.conf.orig ] && \
mv xinetd.conf.orig /etc/xinetd.conf
restart_daemon xinetd
}
restart_xinetd()
{
tst_res TINFO "restart xinetd"
restart_daemon xinetd > tst_xinetd.out 2>&1
if [ $? -ne 0 ]; then
cat tst_xinetd.out
tst_brk TBROK "unable to restart service with telnet disabled"
fi
grep -qi "fail" tst_xinetd.out && \
tst_brk TBROK "xinetd failed to restart"
}
xinetd_test()
{
local cnt=$1
local desc="$2"
local pattern="$3"
local a p
tst_res TINFO "install the new config file with telnet $desc"
ROD mv tst_xinetd.conf.$cnt /etc/xinetd.conf
restart_xinetd
for a in $check_addr; do
p=$(echo $pattern | sed "s/ADDR/$a/")
if ! echo '' | telnet $a 2>&1 | grep -qiE "$p"; then
tst_res TFAIL "not expected output for 'telnet $a'"
return
fi
done
tst_res TPASS "expected output with telnet $desc"
}
do_test()
{
case $1 in
1) xinetd_test $1 "disabled" \
"telnet: (connect to address ADDR|Unable to connect to remote host): Connection refused";;
2) xinetd_test $1 "enabled" \
"Connection closed by foreign host";;
esac
}
. tst_net.sh
tst_run
|