telnet 926 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2011 OpenWrt.org
  3. START=50
  4. USE_PROCD=1
  5. PROG=/usr/sbin/telnetd
  6. has_root_pwd() {
  7. local pwd=$([ -f "$1" ] && cat "$1")
  8. pwd="${pwd#*root:}"
  9. pwd="${pwd%%:*}"
  10. test -n "${pwd#[\!x]}"
  11. }
  12. get_root_home() {
  13. local homedir=$([ -f "$1" ] && cat "$1")
  14. homedir="${homedir#*:*:0:0:*:}"
  15. echo "${homedir%%:*}"
  16. }
  17. has_ssh_pubkey() {
  18. ( /etc/init.d/dropbear enabled 2> /dev/null && grep -qs "^ssh-" /etc/dropbear/authorized_keys ) || \
  19. ( /etc/init.d/sshd enabled 2> /dev/null && grep -qs "^ssh-" "$(get_root_home /etc/passwd)"/.ssh/authorized_keys )
  20. }
  21. start_service() {
  22. if ( ! has_ssh_pubkey && \
  23. ! has_root_pwd /etc/passwd && ! has_root_pwd /etc/shadow ) || \
  24. ( ! /etc/init.d/dropbear enabled 2> /dev/null && ! /etc/init.d/sshd enabled 2> /dev/null );
  25. then
  26. procd_open_instance
  27. procd_set_param command "$PROG" -F -l /bin/login.sh
  28. procd_close_instance
  29. fi
  30. }