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
=''
43 config_get_bool gatewayports
"${section}" GatewayPorts
0
44 [ "${gatewayports}" -eq 1 ] || gatewayports
=''
45 # concatenate parameters
47 args
="${nopasswd:+-s }${port:+-p ${port} }${bannerfile:+-b $bannerfile }${gatewayports:+-a }-P /var/run/${NAME}.${PIDCOUNT}.pid"
49 # execute program and return its exit code
50 [ "${verbosed}" -ne 0 ] && echo "${initscript}: section ${section} starting ${PROG} ${args}"
57 for keytype
in rsa dss
; do
59 key
=dropbear
/dropbear_
${keytype}_host_key
60 [ -f /tmp
/$key -o -s /etc
/$key ] ||
{
61 # generate missing keys
62 mkdir
-p /tmp
/dropbear
63 [ -x /usr
/bin
/dropbearkey
] && {
64 /usr
/bin
/dropbearkey
-t $keytype -f /tmp
/$key 2>&- >&- && exec /etc
/rc.common
"$initscript" start
70 lock
/tmp
/.switch2jffs
71 mkdir
-p /etc
/dropbear
72 mv /tmp
/dropbear
/dropbear_
* /etc
/dropbear
/
73 lock
-u /tmp
/.switch2jffs
74 chown root
/etc
/dropbear
75 chmod 0700 /etc
/dropbear
80 [ -s /etc
/dropbear
/dropbear_rsa_host_key
-a \
81 -s /etc
/dropbear
/dropbear_dss_host_key
] || keygen
84 config_foreach dropbear_start dropbear
89 # killing all server processes
91 for pidfile
in `ls /var/run/${NAME}.*.pid`
93 start-stop-daemon
-K -s KILL
-p "${pidfile}" -n "${NAME}" >/dev
/null
96 [ -z "${pidfile}" ] && echo "${initscript}: no pid files, if you get problems with start then try killclients"
105 # if this script is run from inside a client session, then ignore that session
107 while [ "${pid}" -ne 0 ]
109 # get parent process id
110 pid
=`cut -d ' ' -f 4 "/proc/${pid}/stat"`
111 [ "${pid}" -eq 0 ] && break
113 # check if client connection
114 ps |
grep -e "^[ ]*${pid} " |
grep "${PROG}" >/dev
/null
117 append ignore
"${pid}"
122 # get all server pids that should be ignored
123 for server
in `cat /var/run/${NAME}.*.pid`
125 append ignore
"${server}"
128 # get all running pids and kill client connections
130 for pid
in `pidof "${NAME}"`
132 # check if correct program
133 ps |
grep -e "^[ ]*${pid} " |
grep "${PROG}" >/dev
/null
134 [ $?
-ne 0 ] && continue
136 # check if pid should be ignored (servers, ourself)
138 for server
in ${ignore}
140 if [ "${pid}" == "${server}" ]
146 [ "${skip}" -ne 0 ] && continue
149 echo "${initscript}: Killing ${pid}..."