[package] busybox: Disable telnet if an SSH public key for root exists (#8760)
[openwrt/svn-archive/archive.git] / package / busybox / files / telnet
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2010 OpenWrt.org
3 START=50
4
5 has_root_pwd() {
6 local pwd=$([ -f "$1" ] && cat "$1")
7 pwd="${pwd#*root:}"
8 pwd="${pwd%%:*}"
9
10 test -n "${pwd#!}"
11 }
12
13 has_ssh_pubkey() {
14 ( test -x /usr/sbin/dropbear && grep -qs "^ssh-" /etc/dropbear/authorized_keys ) || \
15 ( test -x /usr/sbin/sshd && grep -qs "^ssh-" /root/.ssh/authorized_keys )
16 }
17
18 start() {
19 if ( ! has_ssh_pubkey && \
20 ! has_root_pwd /etc/passwd && ! has_root_pwd /etc/shadow ) || \
21 ( [ ! -x /usr/sbin/dropbear ] && [ ! -x /usr/sbin/sshd ] );
22 then
23 telnetd -l /bin/login.sh
24 fi
25 }
26
27 stop() {
28 killall telnetd 2>/dev/null
29 }
30