1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2009 OpenWrt.org
3 # Copyright (C) 2006 Carlos Sobrinho
6 PROG
=/usr
/sbin
/dropbear
9 EXTRA_COMMANDS
="killclients"
10 EXTRA_HELP
=" killclients Kill ${NAME} processes except servers and yourself"
16 # check if section is enabled (default)
18 config_get_bool enabled
"${section}" enable 1
19 [ "${enabled}" -eq 0 ] && return 1
23 config_get_bool verbosed
"${section}" verbose
0
25 # increase pid file count to handle multiple instances correctly
26 PIDCOUNT
="$(( ${PIDCOUNT} + 1))"
29 # A) password authentication
32 config_get_bool passauth
"${section}" PasswordAuth
1
33 [ "${passauth}" -eq 0 ] && nopasswd
=1
36 config_get port
"${section}" Port
39 config_get bannerfile
${section} BannerFile
40 [ -f $bannerfile ] || bannerfile
=''
42 # concatenate parameters
44 args
="${nopasswd:+-s }${port:+-p ${port} }${bannerfile:+-b $bannerfile }-P /var/run/${NAME}.${PIDCOUNT}.pid"
46 # execute program and return its exit code
47 [ "${verbosed}" -ne 0 ] && echo "${initscript}: section ${section} starting ${PROG} ${args}"
54 for keytype
in rsa dss
; do
56 key
=dropbear
/dropbear_
${keytype}_host_key
57 [ -f /tmp
/$key -o -s /etc
/$key ] ||
{
58 # generate missing keys
59 mkdir
-p /tmp
/dropbear
60 [ -x /usr
/bin
/dropbearkey
] && {
61 /usr
/bin
/dropbearkey
-t $keytype -f /tmp
/$key 2>&- >&- && exec /etc
/rc.common
"$initscript" start
67 lock
/tmp
/.switch2jffs
68 mkdir
-p /etc
/dropbear
69 mv /tmp
/dropbear
/dropbear_
* /etc
/dropbear
/
70 lock
-u /tmp
/.switch2jffs
71 chown root
/etc
/dropbear
72 chmod 0700 /etc
/dropbear
77 [ -s /etc
/dropbear
/dropbear_rsa_host_key
-a \
78 -s /etc
/dropbear
/dropbear_dss_host_key
] || keygen
81 config_foreach dropbear_start dropbear
86 # killing all server processes
88 for pidfile
in `ls /var/run/${NAME}.*.pid`
90 start-stop-daemon
-K -s KILL
-p "${pidfile}" -n "${NAME}" >/dev
/null
93 [ -z "${pidfile}" ] && echo "${initscript}: no pid files, if you get problems with start then try killclients"
102 # if this script is run from inside a client session, then ignore that session
104 while [ "${pid}" -ne 0 ]
106 # get parent process id
107 pid
=`cut -d ' ' -f 4 "/proc/${pid}/stat"`
108 [ "${pid}" -eq 0 ] && break
110 # check if client connection
111 ps |
grep -e "^[ ]*${pid} " |
grep "${PROG}" >/dev
/null
114 append ignore
"${pid}"
119 # get all server pids that should be ignored
120 for server
in `cat /var/run/${NAME}.*.pid`
122 append ignore
"${server}"
125 # get all running pids and kill client connections
127 for pid
in `pidof "${NAME}"`
129 # check if correct program
130 ps |
grep -e "^[ ]*${pid} " |
grep "${PROG}" >/dev
/null
131 [ $?
-ne 0 ] && continue
133 # check if pid should be ignored (servers, ourself)
135 for server
in ${ignore}
137 if [ "${pid}" == "${server}" ]
143 [ "${skip}" -ne 0 ] && continue
146 echo "${initscript}: Killing ${pid}..."