| 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 | get_root_home() { |
| 14 | local homedir=$([ -f "$1" ] && cat "$1") |
| 15 | homedir="${homedir#*:*:0:0:*:}" |
| 16 | |
| 17 | echo "${homedir%%:*}" |
| 18 | } |
| 19 | |
| 20 | has_ssh_pubkey() { |
| 21 | ( /etc/init.d/dropbear enabled 2> /dev/null && grep -qs "^ssh-" /etc/dropbear/authorized_keys ) || \ |
| 22 | ( /etc/init.d/sshd enabled 2> /dev/null && grep -qs "^ssh-" "$(get_root_home /etc/passwd)"/.ssh/authorized_keys ) |
| 23 | } |
| 24 | |
| 25 | start() { |
| 26 | if ( ! has_ssh_pubkey && \ |
| 27 | ! has_root_pwd /etc/passwd && ! has_root_pwd /etc/shadow ) || \ |
| 28 | ( ! /etc/init.d/dropbear enabled 2> /dev/null && ! /etc/init.d/sshd enabled 2> /dev/null ); |
| 29 | then |
| 30 | telnetd -l /bin/login.sh |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | stop() { |
| 35 | killall telnetd 2>/dev/null |
| 36 | } |
| 37 | |
| 38 | |