1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2010 OpenWrt.org
3 # Copyright (C) 2006 Carlos Sobrinho
9 PROG
=/usr
/sbin
/dropbear
12 EXTRA_COMMANDS
="killclients"
13 EXTRA_HELP
=" killclients Kill ${NAME} processes except servers and yourself"
20 grep -qs "^ *$ifname:" /proc
/net
/dev ||
{
21 procd_append_param
command -p "$port"
26 ifconfig
"$ifname" |
sed -ne '
27 /addr: *fe[89ab][0-9a-f]:/d
28 s/.* addr: *\([0-9a-f:\.]*\).*/\1/p
31 procd_append_param
command -p "$addr:$port"
35 validate_section_dropbear
()
37 uci_validate_section dropbear dropbear
"${1}" \
38 'PasswordAuth:bool:1' \
41 'GatewayPorts:bool:0' \
42 'RootPasswordAuth:bool:1' \
53 local PasswordAuth
enable Interface GatewayPorts \
54 RootPasswordAuth RootLogin rsakeyfile \
55 dsskeyfile BannerFile Port
57 validate_section_dropbear
"${1}" ||
{
58 echo "validation failed"
62 [ "${enable}" = "0" ] && return 1
63 PIDCOUNT
="$(( ${PIDCOUNT} + 1))"
64 local pid_file
="/var/run/${NAME}.${PIDCOUNT}.pid"
67 procd_set_param
command "$PROG" -F -P "$pid_file"
68 [ "${PasswordAuth}" -eq 0 ] && procd_append_param
command -s
69 [ "${GatewayPorts}" -eq 1 ] && procd_append_param
command -a
70 [ "${RootPasswordAuth}" -eq 0 ] && procd_append_param
command -g
71 [ "${RootLogin}" -eq 0 ] && procd_append_param
command -w
72 [ -n "${rsakeyfile}" ] && procd_append_param
command -r "${rsakeyfile}"
73 [ -n "${dsskeyfile}" ] && procd_append_param
command -d "${dsskeyfile}"
74 [ -n "${BannerFile}" ] && procd_append_param
command -b "${BannerFile}"
75 [ -n "${interface}" ] && network_get_device interface
"${interface}"
76 append_ports
"${interface}" "${Port}"
82 for keytype
in rsa dss
; do
84 key
=dropbear
/dropbear_
${keytype}_host_key
85 [ -f /tmp
/$key -o -s /etc
/$key ] ||
{
86 # generate missing keys
87 mkdir
-p /tmp
/dropbear
88 [ -x /usr
/bin
/dropbearkey
] && {
89 /usr
/bin
/dropbearkey
-t $keytype -f /tmp
/$key 2>&- >&- && exec /etc
/rc.common
"$initscript" start
95 lock
/tmp
/.switch2jffs
96 mkdir
-p /etc
/dropbear
97 mv /tmp
/dropbear
/dropbear_
* /etc
/dropbear
/
98 lock
-u /tmp
/.switch2jffs
99 chown root
/etc
/dropbear
100 chmod 0700 /etc
/dropbear
105 [ -s /etc
/dropbear
/dropbear_rsa_host_key
-a \
106 -s /etc
/dropbear
/dropbear_dss_host_key
] || keygen
109 .
/lib
/functions
/network.sh
111 config_load
"${NAME}"
112 config_foreach dropbear_instance dropbear
117 procd_add_reload_trigger
"dropbear"
118 procd_add_validation validate_section_dropbear
127 # if this script is run from inside a client session, then ignore that session
129 while [ "${pid}" -ne 0 ]
131 # get parent process id
132 pid
=`cut -d ' ' -f 4 "/proc/${pid}/stat"`
133 [ "${pid}" -eq 0 ] && break
135 # check if client connection
136 grep -F -q -e "${PROG}" "/proc/${pid}/cmdline" && {
137 append ignore
"${pid}"
142 # get all server pids that should be ignored
143 for server
in `cat /var/run/${NAME}.*.pid`
145 append ignore
"${server}"
148 # get all running pids and kill client connections
150 for pid
in `pidof "${NAME}"`
152 # check if correct program, otherwise process next pid
153 grep -F -q -e "${PROG}" "/proc/${pid}/cmdline" ||
{
157 # check if pid should be ignored (servers, ourself)
159 for server
in ${ignore}
161 if [ "${pid}" == "${server}" ]
167 [ "${skip}" -ne 0 ] && continue
170 echo "${initscript}: Killing ${pid}..."