2006-10-04 20:05:48 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2010-02-10 00:34:32 +00:00
|
|
|
# Copyright (C) 2006-2010 OpenWrt.org
|
2006-10-29 05:53:13 +00:00
|
|
|
# Copyright (C) 2006 Carlos Sobrinho
|
|
|
|
|
2018-12-18 18:40:31 +00:00
|
|
|
START=19
|
2010-01-30 18:19:42 +00:00
|
|
|
STOP=50
|
2011-11-07 22:58:50 +00:00
|
|
|
|
2012-12-22 18:56:13 +00:00
|
|
|
USE_PROCD=1
|
2011-11-07 22:58:50 +00:00
|
|
|
PROG=/usr/sbin/dropbear
|
2013-09-23 21:58:36 +00:00
|
|
|
NAME=dropbear
|
2009-08-03 22:19:51 +00:00
|
|
|
PIDCOUNT=0
|
2020-07-24 07:33:59 +00:00
|
|
|
|
|
|
|
extra_command "killclients" "Kill ${NAME} processes except servers and yourself"
|
2009-08-03 22:19:51 +00:00
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
# most of time real_stat() will be failing
|
|
|
|
# due to missing "stat" binary (by default)
|
|
|
|
real_stat() { env stat -L "$@" 2>/dev/null ; }
|
|
|
|
dumb_stat() { ls -Ldln "$1" | tr -s '\t ' ' ' ; }
|
|
|
|
stat_perm() { real_stat -c '%A' "$1" || dumb_stat "$1" | cut -d ' ' -f 1 ; }
|
|
|
|
stat_owner() { real_stat -c '%u' "$1" || dumb_stat "$1" | cut -d ' ' -f 3 ; }
|
|
|
|
|
2019-03-25 18:42:01 +00:00
|
|
|
_dropbearkey()
|
|
|
|
{
|
2024-01-09 00:40:02 +00:00
|
|
|
/usr/bin/dropbearkey "$@" </dev/null >/dev/null 2>&1
|
2019-03-25 18:42:01 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
# $1 - file name (host key or config)
|
|
|
|
file_verify()
|
2019-03-25 18:42:01 +00:00
|
|
|
{
|
|
|
|
[ -f "$1" ] || return 1
|
2024-01-09 00:40:02 +00:00
|
|
|
# checking file ownership
|
|
|
|
[ "$(stat_owner "$1")" = "0" ] || {
|
|
|
|
chown 0 "$1"
|
|
|
|
[ "$(stat_owner "$1")" = "0" ] || return 2
|
|
|
|
}
|
|
|
|
# checking file permissions
|
|
|
|
[ "$(stat_perm "$1")" = "-rw-------" ] || {
|
|
|
|
chmod 0600 "$1"
|
|
|
|
[ "$(stat_perm "$1")" = "-rw-------" ] || return 3
|
|
|
|
}
|
|
|
|
# file is host key or not?
|
|
|
|
# if $2 is empty string - file is "host key"
|
|
|
|
# if $2 is non-empty string - file is "config"
|
|
|
|
[ -z "$2" ] || return 0
|
|
|
|
# checking file contents (finally)
|
|
|
|
[ -s "$1" ] || return 4
|
|
|
|
_dropbearkey -y -f "$1" || return 5
|
2019-03-25 18:42:01 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
# $1 - file_verify() return code
|
|
|
|
file_errmsg()
|
2019-03-25 18:42:01 +00:00
|
|
|
{
|
|
|
|
case "$1" in
|
|
|
|
0) ;;
|
|
|
|
1) echo "file does not exist" ;;
|
2024-01-09 00:40:02 +00:00
|
|
|
2) echo "file has wrong owner (must be owned by root)" ;;
|
|
|
|
3) echo "file has wrong permissions (must not have group/other write bit)" ;;
|
|
|
|
4) echo "file has zero length" ;;
|
|
|
|
5) echo "file is not valid host key or not supported" ;;
|
2019-03-25 18:42:01 +00:00
|
|
|
*) echo "unknown error" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# $1 - config option
|
|
|
|
# $2 - host key file name
|
|
|
|
hk_config()
|
|
|
|
{
|
|
|
|
local x m
|
2024-01-09 00:40:02 +00:00
|
|
|
file_verify "$2" ; x=$?
|
|
|
|
if [ "$x" = 0 ] ; then
|
|
|
|
procd_append_param command -r "$2"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
m=$(file_errmsg "$x")
|
|
|
|
logger -s -t "${NAME}" -p daemon.warn \
|
|
|
|
"Option '$1', skipping '$2': $m"
|
2019-03-25 18:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1 - host key file name
|
2024-01-09 00:40:02 +00:00
|
|
|
hk_config__keyfile() { hk_config keyfile "$1" ; }
|
|
|
|
|
|
|
|
ktype_all='ed25519 ecdsa rsa'
|
2019-03-25 18:42:01 +00:00
|
|
|
|
2019-03-25 18:59:47 +00:00
|
|
|
hk_generate_as_needed()
|
|
|
|
{
|
2024-01-09 00:40:02 +00:00
|
|
|
local hk_cfg_dir kgen ktype kfile hk_tmp_dir
|
|
|
|
hk_cfg_dir='/etc/dropbear'
|
|
|
|
|
|
|
|
[ -d "${hk_cfg_dir}" ] || mkdir -p "${hk_cfg_dir}"
|
2019-03-25 18:59:47 +00:00
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
kgen=
|
|
|
|
for ktype in ${ktype_all} ; do
|
|
|
|
kfile="${hk_cfg_dir}/dropbear_${ktype}_host_key"
|
2019-03-25 18:59:47 +00:00
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
if file_verify "${kfile}" ; then continue ; fi
|
|
|
|
|
|
|
|
kgen="${kgen}${kgen:+ }${ktype}"
|
2019-03-25 18:59:47 +00:00
|
|
|
done
|
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
# all keys are sane?
|
|
|
|
[ -n "${kgen}" ] || return 0
|
|
|
|
|
|
|
|
hk_tmp_dir=$(mktemp -d)
|
|
|
|
# system in bad state?
|
|
|
|
[ -n "${hk_tmp_dir}" ] || return 1
|
2019-03-25 18:59:47 +00:00
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
chmod 0700 "${hk_tmp_dir}"
|
2019-03-25 18:59:47 +00:00
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
for ktype in ${kgen} ; do
|
|
|
|
kfile="${hk_tmp_dir}/dropbear_${ktype}_host_key"
|
2019-03-25 18:59:47 +00:00
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
if ! _dropbearkey -t ${ktype} -f "${kfile}" ; then
|
2019-03-25 18:59:47 +00:00
|
|
|
# unsupported key type
|
2024-01-09 00:40:02 +00:00
|
|
|
rm -f "${kfile}"
|
2019-03-25 18:59:47 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
chmod 0600 "${kfile}"
|
|
|
|
done
|
|
|
|
|
|
|
|
kgen=
|
|
|
|
for ktype in ${ktype_all} ; do
|
|
|
|
kfile="${hk_tmp_dir}/dropbear_${ktype}_host_key"
|
|
|
|
|
|
|
|
[ -s "${kfile}" ] || continue
|
|
|
|
|
|
|
|
kgen="${kgen}${kgen:+ }${ktype}"
|
2019-03-25 18:59:47 +00:00
|
|
|
done
|
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
if [ -n "${kgen}" ] ; then
|
|
|
|
for ktype in ${kgen} ; do
|
|
|
|
kfile="${hk_tmp_dir}/dropbear_${ktype}_host_key"
|
|
|
|
[ -s "${kfile}" ] || continue
|
|
|
|
mv -f "${kfile}" "${hk_cfg_dir}/"
|
|
|
|
done
|
2019-03-25 18:59:47 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-09 00:40:02 +00:00
|
|
|
rm -rf "${hk_tmp_dir}"
|
|
|
|
|
|
|
|
# cleanup empty files
|
|
|
|
for ktype in ${ktype_all} ; do
|
|
|
|
kfile="${hk_cfg_dir}/dropbear_${ktype}_host_key"
|
|
|
|
|
|
|
|
[ -s "${kfile}" ] || rm -f "${kfile}"
|
|
|
|
done
|
2019-03-25 18:59:47 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 07:38:59 +00:00
|
|
|
# $1 - list with whitespace-separated elements
|
|
|
|
normalize_list()
|
2009-08-03 22:19:51 +00:00
|
|
|
{
|
2024-01-15 07:38:59 +00:00
|
|
|
printf '%s' "$1" | tr -s ' \r\n\t' ' ' | sed -E 's/^ //;s/ $//'
|
|
|
|
}
|
2011-07-31 12:05:54 +00:00
|
|
|
|
2024-01-15 07:38:59 +00:00
|
|
|
warn_multiple_interfaces()
|
|
|
|
{
|
|
|
|
logger -t "${NAME}" -p daemon.warn \
|
|
|
|
"Option '$1' should specify SINGLE interface but instead it lists interfaces: $2"
|
|
|
|
logger -t "${NAME}" -p daemon.warn \
|
|
|
|
"Consider creating per-interface instances instead!"
|
2013-11-13 10:49:41 +00:00
|
|
|
}
|
2011-07-31 12:05:54 +00:00
|
|
|
|
2013-11-13 10:49:41 +00:00
|
|
|
validate_section_dropbear()
|
|
|
|
{
|
2019-01-12 18:14:22 +00:00
|
|
|
uci_load_validate dropbear dropbear "$1" "$2" \
|
2013-11-13 10:49:41 +00:00
|
|
|
'PasswordAuth:bool:1' \
|
|
|
|
'enable:bool:1' \
|
2024-01-15 07:38:59 +00:00
|
|
|
'DirectInterface:string' \
|
2013-11-13 10:49:41 +00:00
|
|
|
'Interface:string' \
|
2013-11-13 11:07:24 +00:00
|
|
|
'GatewayPorts:bool:0' \
|
2023-03-29 12:15:13 +00:00
|
|
|
'ForceCommand:string' \
|
2013-11-13 10:49:41 +00:00
|
|
|
'RootPasswordAuth:bool:1' \
|
|
|
|
'RootLogin:bool:1' \
|
|
|
|
'rsakeyfile:file' \
|
2019-03-25 18:42:01 +00:00
|
|
|
'keyfile:list(file)' \
|
2013-11-13 10:49:41 +00:00
|
|
|
'BannerFile:file' \
|
2019-03-25 18:42:09 +00:00
|
|
|
'Port:port:22' \
|
2014-03-29 17:05:35 +00:00
|
|
|
'SSHKeepAlive:uinteger:300' \
|
2014-08-29 18:16:41 +00:00
|
|
|
'IdleTimeout:uinteger:0' \
|
2017-06-27 20:30:01 +00:00
|
|
|
'MaxAuthTries:uinteger:3' \
|
2024-01-09 00:40:02 +00:00
|
|
|
'RecvWindowSize:uinteger:262144' \
|
2016-08-25 11:48:30 +00:00
|
|
|
'mdns:bool:1'
|
2013-11-13 10:49:41 +00:00
|
|
|
}
|
2009-08-03 22:19:51 +00:00
|
|
|
|
2013-11-13 10:49:41 +00:00
|
|
|
dropbear_instance()
|
|
|
|
{
|
2019-01-12 18:14:22 +00:00
|
|
|
[ "$2" = 0 ] || {
|
2013-11-13 10:49:41 +00:00
|
|
|
echo "validation failed"
|
|
|
|
return 1
|
|
|
|
}
|
2009-08-03 22:19:51 +00:00
|
|
|
|
2024-01-15 07:38:59 +00:00
|
|
|
[ "${enable}" = "1" ] || return 1
|
2018-12-18 18:40:31 +00:00
|
|
|
|
2024-01-15 07:38:59 +00:00
|
|
|
local iface ndev ipaddrs
|
|
|
|
|
|
|
|
# 'DirectInterface' should specify single interface
|
|
|
|
# but end users may misinterpret this setting
|
|
|
|
DirectInterface=$(normalize_list "${DirectInterface}")
|
|
|
|
|
|
|
|
# 'Interface' should specify single interface
|
|
|
|
# but end users are often misinterpret this setting
|
|
|
|
Interface=$(normalize_list "${Interface}")
|
|
|
|
|
|
|
|
if [ -n "${Interface}" ] ; then
|
|
|
|
if [ -n "${DirectInterface}" ] ; then
|
|
|
|
logger -t "${NAME}" -p daemon.warn \
|
|
|
|
"Option 'DirectInterface' takes precedence over 'Interface'"
|
|
|
|
else
|
|
|
|
logger -t "${NAME}" -p daemon.info \
|
|
|
|
"Option 'Interface' binds to address(es) but not to interface"
|
|
|
|
logger -t "${NAME}" -p daemon.info \
|
|
|
|
"Consider using option 'DirectInterface' to bind directly to interface"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# handle 'DirectInterface'
|
|
|
|
iface=$(echo "${DirectInterface}" | awk '{print $1}')
|
|
|
|
case "${DirectInterface}" in
|
|
|
|
*\ *)
|
|
|
|
warn_multiple_interfaces DirectInterface "${DirectInterface}"
|
|
|
|
logger -t "${NAME}" -p daemon.warn \
|
|
|
|
"Using network interface '${iface}' for direct binding"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
while [ -n "${iface}" ] ; do
|
|
|
|
# if network is available (even during boot) - proceed
|
|
|
|
if network_is_up "${iface}" ; then break ; fi
|
|
|
|
# skip during boot
|
|
|
|
[ -z "${BOOT}" ] || return 0
|
|
|
|
|
|
|
|
logger -t "${NAME}" -p daemon.crit \
|
|
|
|
"Network interface '${iface}' is not available!"
|
|
|
|
return 1
|
|
|
|
done
|
|
|
|
while [ -n "${iface}" ] ; do
|
|
|
|
# ${iface} is logical (higher level) interface name
|
|
|
|
# ${ndev} is 'real' interface name
|
|
|
|
# e.g.: if ${iface} is 'lan' (default LAN interface) then ${ndev} is 'br-lan'
|
|
|
|
network_get_device ndev "${iface}"
|
|
|
|
[ -z "${ndev}" ] || break
|
|
|
|
|
|
|
|
logger -t "${NAME}" -p daemon.crit \
|
|
|
|
"Missing network device for network interface '${iface}'!"
|
|
|
|
return 1
|
|
|
|
done
|
|
|
|
if [ -n "${iface}" ] ; then
|
|
|
|
logger -t "${NAME}" -p daemon.info \
|
|
|
|
"Using network interface '${iface}' (network device '${ndev}') for direct binding"
|
|
|
|
fi
|
|
|
|
# handle 'Interface'
|
|
|
|
while [ -z "${iface}" ] ; do
|
|
|
|
[ -n "${Interface}" ] || break
|
|
|
|
|
|
|
|
# skip during boot
|
|
|
|
[ -z "${BOOT}" ] || return 0
|
|
|
|
|
|
|
|
case "${Interface}" in
|
|
|
|
*\ *)
|
|
|
|
warn_multiple_interfaces Interface "${Interface}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
local c=0
|
2024-05-06 13:20:16 +00:00
|
|
|
# src/sysoptions.h
|
2024-01-15 07:38:59 +00:00
|
|
|
local DROPBEAR_MAX_PORTS=10
|
|
|
|
|
|
|
|
local a n if_ipaddrs
|
|
|
|
for n in ${Interface} ; do
|
|
|
|
[ -n "$n" ] || continue
|
|
|
|
|
|
|
|
if_ipaddrs=
|
|
|
|
network_get_ipaddrs_all if_ipaddrs "$n"
|
|
|
|
[ -n "${if_ipaddrs}" ] || {
|
|
|
|
logger -s -t "${NAME}" -p daemon.err \
|
|
|
|
"Network interface '$n' has no suitable IP address(es)!"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
[ $c -le ${DROPBEAR_MAX_PORTS} ] || {
|
|
|
|
logger -s -t "${NAME}" -p daemon.err \
|
|
|
|
"Network interface '$n' is NOT listened due to option limit exceed!"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for a in ${if_ipaddrs} ; do
|
|
|
|
[ -n "$a" ] || continue
|
|
|
|
|
|
|
|
c=$((c+1))
|
|
|
|
if [ $c -le ${DROPBEAR_MAX_PORTS} ] ; then
|
|
|
|
ipaddrs="${ipaddrs} $a"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
logger -t "${NAME}" -p daemon.err \
|
|
|
|
"Endpoint '$a:${Port}' on network interface '$n' is NOT listened due to option limit exceed!"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
break
|
|
|
|
done
|
2014-10-09 07:16:35 +00:00
|
|
|
|
2013-11-13 10:49:41 +00:00
|
|
|
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
|
2011-11-07 22:58:50 +00:00
|
|
|
local pid_file="/var/run/${NAME}.${PIDCOUNT}.pid"
|
2012-12-22 18:56:13 +00:00
|
|
|
|
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command "$PROG" -F -P "$pid_file"
|
2024-01-15 07:38:59 +00:00
|
|
|
if [ -n "${iface}" ] ; then
|
|
|
|
# if ${iface} is non-empty then ${ndev} is non-empty too
|
|
|
|
procd_append_param command -l "${ndev}" -p "${Port}"
|
|
|
|
else
|
|
|
|
if [ -z "${ipaddrs}" ] ; then
|
|
|
|
procd_append_param command -p "${Port}"
|
|
|
|
else
|
|
|
|
local a
|
|
|
|
for a in ${ipaddrs} ; do
|
|
|
|
[ -n "$a" ] || continue
|
|
|
|
procd_append_param command -p "$a:${Port}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
2013-11-13 10:49:41 +00:00
|
|
|
[ "${PasswordAuth}" -eq 0 ] && procd_append_param command -s
|
|
|
|
[ "${GatewayPorts}" -eq 1 ] && procd_append_param command -a
|
2023-03-29 12:15:13 +00:00
|
|
|
[ -n "${ForceCommand}" ] && procd_append_param command -c "${ForceCommand}"
|
2013-11-13 10:49:41 +00:00
|
|
|
[ "${RootPasswordAuth}" -eq 0 ] && procd_append_param command -g
|
|
|
|
[ "${RootLogin}" -eq 0 ] && procd_append_param command -w
|
2024-01-09 00:40:02 +00:00
|
|
|
config_list_foreach "$1" 'keyfile' hk_config__keyfile
|
2019-03-25 18:42:01 +00:00
|
|
|
if [ -n "${rsakeyfile}" ]; then
|
2024-01-09 00:40:02 +00:00
|
|
|
logger -s -t "${NAME}" -p daemon.crit \
|
|
|
|
"Option 'rsakeyfile' is considered to be DEPRECATED and will be REMOVED in future releases, use 'keyfile' list instead"
|
|
|
|
sed -i.before-upgrade -E -e 's/option(\s+)rsakeyfile/list keyfile/' \
|
|
|
|
"/etc/config/${NAME}"
|
|
|
|
logger -s -t "${NAME}" -p daemon.crit \
|
|
|
|
"Auto-transition 'option rsakeyfile' => 'list keyfile' in /etc/config/${NAME} is done, please verify your configuration"
|
2019-03-25 18:42:01 +00:00
|
|
|
hk_config 'rsakeyfile' "${rsakeyfile}"
|
|
|
|
fi
|
2013-11-13 10:49:41 +00:00
|
|
|
[ -n "${BannerFile}" ] && procd_append_param command -b "${BannerFile}"
|
2014-03-29 17:05:35 +00:00
|
|
|
[ "${IdleTimeout}" -ne 0 ] && procd_append_param command -I "${IdleTimeout}"
|
|
|
|
[ "${SSHKeepAlive}" -ne 0 ] && procd_append_param command -K "${SSHKeepAlive}"
|
2017-06-27 20:30:01 +00:00
|
|
|
[ "${MaxAuthTries}" -ne 0 ] && procd_append_param command -T "${MaxAuthTries}"
|
2024-01-09 00:40:02 +00:00
|
|
|
[ "${RecvWindowSize}" -gt 0 ] && {
|
|
|
|
# NB: OpenWrt increases receive window size to increase throughput on high latency links
|
|
|
|
# ref: validate_section_dropbear()
|
|
|
|
# default receive window size is 24576 (DEFAULT_RECV_WINDOW in default_options.h)
|
|
|
|
|
2024-05-06 13:20:16 +00:00
|
|
|
# src/sysoptions.h
|
2024-01-09 00:40:02 +00:00
|
|
|
local MAX_RECV_WINDOW=10485760
|
|
|
|
if [ "${RecvWindowSize}" -gt ${MAX_RECV_WINDOW} ] ; then
|
|
|
|
# separate logging is required because syslog misses dropbear's message
|
|
|
|
# Bad recv window '${RecvWindowSize}', using ${MAX_RECV_WINDOW}
|
|
|
|
# it's probably dropbear issue but we should handle this and notify user
|
|
|
|
logger -s -t "${NAME}" -p daemon.warn \
|
|
|
|
"Option 'RecvWindowSize' is too high (${RecvWindowSize}), limiting to ${MAX_RECV_WINDOW}"
|
|
|
|
RecvWindowSize=${MAX_RECV_WINDOW}
|
|
|
|
fi
|
2018-02-18 00:15:58 +00:00
|
|
|
procd_append_param command -W "${RecvWindowSize}"
|
2024-01-09 00:40:02 +00:00
|
|
|
}
|
2014-08-29 18:16:41 +00:00
|
|
|
[ "${mdns}" -ne 0 ] && procd_add_mdns "ssh" "tcp" "$Port" "daemon=dropbear"
|
2015-09-24 08:37:40 +00:00
|
|
|
procd_set_param respawn
|
2012-12-22 18:56:13 +00:00
|
|
|
procd_close_instance
|
2006-10-29 05:53:13 +00:00
|
|
|
}
|
2005-03-06 03:53:29 +00:00
|
|
|
|
2016-04-27 09:14:00 +00:00
|
|
|
load_interfaces()
|
|
|
|
{
|
2024-01-15 07:38:59 +00:00
|
|
|
local enable
|
2017-04-26 14:44:02 +00:00
|
|
|
config_get enable "$1" enable 1
|
2024-01-15 07:38:59 +00:00
|
|
|
[ "${enable}" = "1" ] || return 0
|
|
|
|
|
|
|
|
local direct_iface iface
|
|
|
|
config_get direct_iface "$1" DirectInterface
|
|
|
|
direct_iface=$(normalize_list "${direct_iface}")
|
|
|
|
# 'DirectInterface' takes precedence over 'Interface'
|
|
|
|
if [ -n "${direct_iface}" ] ; then
|
|
|
|
iface=$(echo "${direct_iface}" | awk '{print $1}')
|
|
|
|
else
|
|
|
|
config_get iface "$1" Interface
|
|
|
|
iface=$(normalize_list "${iface}")
|
|
|
|
fi
|
|
|
|
interfaces="${interfaces} ${iface}"
|
2016-04-27 09:14:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 18:40:31 +00:00
|
|
|
boot()
|
|
|
|
{
|
|
|
|
BOOT=1
|
|
|
|
start "$@"
|
|
|
|
}
|
|
|
|
|
2012-12-22 18:56:13 +00:00
|
|
|
start_service()
|
2009-08-03 22:19:51 +00:00
|
|
|
{
|
2019-03-25 18:59:47 +00:00
|
|
|
hk_generate_as_needed
|
2024-01-09 00:40:02 +00:00
|
|
|
file_verify /etc/dropbear/authorized_keys config
|
2009-08-03 22:19:51 +00:00
|
|
|
|
2012-12-22 18:55:57 +00:00
|
|
|
. /lib/functions.sh
|
|
|
|
. /lib/functions/network.sh
|
|
|
|
|
2009-08-03 22:19:51 +00:00
|
|
|
config_load "${NAME}"
|
2019-01-12 18:14:22 +00:00
|
|
|
config_foreach validate_section_dropbear dropbear dropbear_instance
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
2006-10-07 19:11:19 +00:00
|
|
|
|
2013-07-11 17:00:40 +00:00
|
|
|
service_triggers()
|
|
|
|
{
|
2016-04-27 09:14:00 +00:00
|
|
|
local interfaces
|
|
|
|
|
2024-01-15 07:38:59 +00:00
|
|
|
procd_add_config_trigger "config.change" "${NAME}" /etc/init.d/dropbear reload
|
2016-04-27 09:14:00 +00:00
|
|
|
|
|
|
|
config_load "${NAME}"
|
2024-01-15 07:38:59 +00:00
|
|
|
config_foreach load_interfaces "${NAME}"
|
2016-04-27 09:14:00 +00:00
|
|
|
|
2017-06-15 11:58:25 +00:00
|
|
|
[ -n "${interfaces}" ] && {
|
2024-01-15 07:38:59 +00:00
|
|
|
local n
|
|
|
|
for n in $(printf '%s\n' ${interfaces} | sort -u) ; do
|
2016-04-27 09:14:00 +00:00
|
|
|
procd_add_interface_trigger "interface.*" $n /etc/init.d/dropbear reload
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-11-13 10:49:41 +00:00
|
|
|
procd_add_validation validate_section_dropbear
|
2013-07-11 17:00:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 02:36:03 +00:00
|
|
|
shutdown() {
|
|
|
|
# close all open connections
|
|
|
|
killall dropbear
|
|
|
|
}
|
|
|
|
|
2009-08-03 22:19:51 +00:00
|
|
|
killclients()
|
|
|
|
{
|
|
|
|
local ignore=''
|
|
|
|
local server
|
|
|
|
local pid
|
|
|
|
|
|
|
|
# if this script is run from inside a client session, then ignore that session
|
|
|
|
pid="$$"
|
|
|
|
while [ "${pid}" -ne 0 ]
|
|
|
|
do
|
|
|
|
# get parent process id
|
2020-06-30 16:22:10 +00:00
|
|
|
pid=$(cut -d ' ' -f 4 "/proc/${pid}/stat")
|
2009-08-03 22:19:51 +00:00
|
|
|
[ "${pid}" -eq 0 ] && break
|
|
|
|
|
|
|
|
# check if client connection
|
2010-02-10 00:34:32 +00:00
|
|
|
grep -F -q -e "${PROG}" "/proc/${pid}/cmdline" && {
|
2009-08-03 22:19:51 +00:00
|
|
|
append ignore "${pid}"
|
|
|
|
break
|
2010-02-10 00:34:32 +00:00
|
|
|
}
|
2009-08-03 22:19:51 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# get all server pids that should be ignored
|
2020-06-30 16:22:10 +00:00
|
|
|
for server in $(cat /var/run/${NAME}.*.pid)
|
2009-08-03 22:19:51 +00:00
|
|
|
do
|
|
|
|
append ignore "${server}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# get all running pids and kill client connections
|
|
|
|
local skip
|
2020-06-30 16:22:10 +00:00
|
|
|
for pid in $(pidof "${NAME}")
|
2009-08-03 22:19:51 +00:00
|
|
|
do
|
2010-02-10 00:34:32 +00:00
|
|
|
# check if correct program, otherwise process next pid
|
|
|
|
grep -F -q -e "${PROG}" "/proc/${pid}/cmdline" || {
|
|
|
|
continue
|
|
|
|
}
|
2009-08-03 22:19:51 +00:00
|
|
|
|
|
|
|
# check if pid should be ignored (servers, ourself)
|
|
|
|
skip=0
|
|
|
|
for server in ${ignore}
|
|
|
|
do
|
2014-10-14 12:21:11 +00:00
|
|
|
if [ "${pid}" = "${server}" ]
|
2009-08-03 22:19:51 +00:00
|
|
|
then
|
|
|
|
skip=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
[ "${skip}" -ne 0 ] && continue
|
|
|
|
|
|
|
|
# kill process
|
|
|
|
echo "${initscript}: Killing ${pid}..."
|
|
|
|
kill -KILL ${pid}
|
|
|
|
done
|
2006-10-07 19:11:19 +00:00
|
|
|
}
|