aredn/patches/704-enable-telnet.patch

117 lines
3.1 KiB
Diff

--- a/package/base-files/files/lib/preinit/99_10_failsafe_login
+++ b/package/base-files/files/lib/preinit/99_10_failsafe_login
@@ -1,6 +1,10 @@
# Copyright (C) 2006-2015 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
+failsafe_netlogin () {
+ telnetd -l /bin/login.sh <> /dev/null 2>&1
+}
+
failsafe_shell() {
local console="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | head -1 | sed -e 's/^console=//' -e 's/,.*//')"
[ -n "$console" ] || console=console
@@ -11,4 +15,5 @@ failsafe_shell() {
done &
}
+boot_hook_add failsafe failsafe_netlogin
boot_hook_add failsafe failsafe_shell
--- a/package/utils/busybox/Config-defaults.in
+++ b/package/utils/busybox/Config-defaults.in
@@ -2552,10 +2552,10 @@ config BUSYBOX_DEFAULT_UDPSVD
default n
config BUSYBOX_DEFAULT_TELNET
bool
- default n
+ default y
config BUSYBOX_DEFAULT_FEATURE_TELNET_TTYPE
bool
- default n
+ default y
config BUSYBOX_DEFAULT_FEATURE_TELNET_AUTOLOGIN
bool
default n
@@ -2564,10 +2564,10 @@ config BUSYBOX_DEFAULT_FEATURE_TELNET_WI
default n
config BUSYBOX_DEFAULT_TELNETD
bool
- default n
+ default y
config BUSYBOX_DEFAULT_FEATURE_TELNETD_STANDALONE
bool
- default n
+ default y
config BUSYBOX_DEFAULT_FEATURE_TELNETD_PORT_DEFAULT
int
default 23
--- a/package/utils/busybox/Makefile
+++ b/package/utils/busybox/Makefile
@@ -148,6 +148,8 @@ ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_C
$(INSTALL_BIN) ./files/cron $(1)/etc/init.d/cron
$(INSTALL_DIR) $(1)/etc/crontabs
endif
+ $(INSTALL_BIN) ./files/telnet $(1)/etc/init.d/telnet
+ $(INSTALL_BIN) ./files/login.sh $(1)/bin/login.sh
ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_NTPD),)
$(INSTALL_BIN) ./files/sysntpd $(1)/etc/init.d/sysntpd
$(INSTALL_BIN) ./files/ntpd-hotplug $(1)/usr/sbin/ntpd-hotplug
--- /dev/null
+++ b/package/utils/busybox/files/telnet
@@ -0,0 +1,33 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006-2011 OpenWrt.org
+
+START=50
+
+USE_PROCD=1
+PROG=/usr/sbin/telnetd
+
+has_root_pwd() {
+ local pwd=$([ -f "$1" ] && cat "$1")
+ pwd="${pwd#*root:}"
+ pwd="${pwd%%:*}"
+
+ test -n "${pwd#[\!x]}"
+}
+
+get_root_home() {
+ local homedir=$([ -f "$1" ] && cat "$1")
+ homedir="${homedir#*:*:0:0:*:}"
+
+ echo "${homedir%%:*}"
+}
+
+has_ssh_pubkey() {
+ ( /etc/init.d/dropbear enabled 2> /dev/null && grep -qs "^ssh-" /etc/dropbear/authorized_keys ) || \
+ ( /etc/init.d/sshd enabled 2> /dev/null && grep -qs "^ssh-" "$(get_root_home /etc/passwd)"/.ssh/authorized_keys )
+}
+
+start_service() {
+ procd_open_instance
+ procd_set_param command "$PROG" -F -l /bin/login.sh
+ procd_close_instance
+}
--- /dev/null
+++ b/package/utils/busybox/files/login.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+# Copyright (C) 2006-2011 OpenWrt.org
+
+if ( ! grep -qs '^root:[!x]\?:' /etc/shadow || \
+ ! grep -qs '^root:[!x]\?:' /etc/passwd ) && \
+ [ -z "$FAILSAFE" ]
+then
+ echo "WARNING: passwords are sent unencrypted."
+ busybox login
+else
+cat << EOF
+ === IMPORTANT ============================
+ Use 'passwd' to set your login password
+ this will enable telnet login with password
+ ------------------------------------------
+EOF
+
+exec /bin/ash --login
+fi