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