f294c5590bd1e4d179eddf1a06564728c853a939
[openwrt.git] / package / busybox / files / telnet
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2011 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         ( /etc/init.d/dropbear enabled 2> /dev/null && grep -qs "^ssh-" /etc/dropbear/authorized_keys ) || \
15         ( /etc/init.d/sshd enabled 2> /dev/null && 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            ( ! /etc/init.d/dropbear enabled 2> /dev/null && ! /etc/init.d/sshd enabled 2> /dev/null );
22         then
23                 telnetd -l /bin/login.sh
24         fi
25 }
26
27 stop() {
28         killall telnetd 2>/dev/null
29 }
30