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