2006-10-04 20:05:48 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2011-02-07 21:45:02 +00:00
|
|
|
# Copyright (C) 2006-2011 OpenWrt.org
|
2011-11-07 22:58:39 +00:00
|
|
|
|
2007-05-10 10:38:53 +00:00
|
|
|
START=50
|
2006-06-27 00:36:13 +00:00
|
|
|
|
2010-07-18 18:36:12 +00:00
|
|
|
has_root_pwd() {
|
|
|
|
local pwd=$([ -f "$1" ] && cat "$1")
|
|
|
|
pwd="${pwd#*root:}"
|
|
|
|
pwd="${pwd%%:*}"
|
|
|
|
|
2011-11-16 13:17:35 +00:00
|
|
|
test -n "${pwd#[\!x]}"
|
2010-07-18 18:36:12 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 01:01:17 +00:00
|
|
|
get_root_home() {
|
|
|
|
local homedir=$([ -f "$1" ] && cat "$1")
|
|
|
|
homedir="${homedir#*:*:0:0:*:}"
|
|
|
|
|
|
|
|
echo "${homedir%%:*}"
|
|
|
|
}
|
|
|
|
|
2011-02-02 18:50:50 +00:00
|
|
|
has_ssh_pubkey() {
|
2011-02-07 21:45:02 +00:00
|
|
|
( /etc/init.d/dropbear enabled 2> /dev/null && grep -qs "^ssh-" /etc/dropbear/authorized_keys ) || \
|
2011-02-08 01:01:17 +00:00
|
|
|
( /etc/init.d/sshd enabled 2> /dev/null && grep -qs "^ssh-" "$(get_root_home /etc/passwd)"/.ssh/authorized_keys )
|
2011-02-02 18:50:50 +00:00
|
|
|
}
|
|
|
|
|
2006-10-04 20:05:48 +00:00
|
|
|
start() {
|
2011-02-02 18:50:50 +00:00
|
|
|
if ( ! has_ssh_pubkey && \
|
|
|
|
! has_root_pwd /etc/passwd && ! has_root_pwd /etc/shadow ) || \
|
2011-02-07 21:45:02 +00:00
|
|
|
( ! /etc/init.d/dropbear enabled 2> /dev/null && ! /etc/init.d/sshd enabled 2> /dev/null );
|
2010-07-18 18:36:12 +00:00
|
|
|
then
|
2011-11-07 22:58:39 +00:00
|
|
|
service_start /usr/sbin/telnetd -l /bin/login.sh
|
2007-01-08 21:31:29 +00:00
|
|
|
fi
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2011-11-07 22:58:39 +00:00
|
|
|
service_stop /usr/sbin/telnetd
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|