You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
851 B

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2011 OpenWrt.org
  3. START=50
  4. STOP=50
  5. USE_PROCD=1
  6. PROG=/usr/sbin/sshd
  7. start_service() {
  8. for type in rsa ecdsa ed25519; do {
  9. # check for keys
  10. key=/etc/ssh/ssh_host_${type}_key
  11. [ ! -f $key ] && {
  12. # generate missing keys
  13. [ -x /usr/bin/ssh-keygen ] && {
  14. /usr/bin/ssh-keygen -N '' -t $type -f $key 2>&- >&-
  15. }
  16. }
  17. }; done
  18. mkdir -m 0700 -p /var/empty
  19. local lport=`grep ^Port /etc/ssh/sshd_config | cut -d " " -f 2`
  20. [ -z $lport ] && lport=22
  21. procd_open_instance
  22. procd_add_mdns "ssh" "tcp" "$lport"
  23. procd_set_param command $PROG -D
  24. procd_close_instance
  25. }
  26. shutdown() {
  27. local pid
  28. local pids
  29. local pid_mine
  30. stop
  31. # kill active clients
  32. pid_mine="$$"
  33. pids="$(pidof sshd)"
  34. for pid in $pids; do
  35. [ "$pid" = "$pid_mine" ] && continue
  36. [ -e "/proc/$pid/stat" ] && kill $pid
  37. done
  38. }