dropbear: fix dropbear startup issue
[openwrt/openwrt.git] / package / network / services / dropbear / files / dropbear.init
index 2d23ebd04568cff2d98ff9f6cae6c800d50c8152..eef2643c14ac6b916bebb49e835186502afecce1 100755 (executable)
@@ -2,7 +2,7 @@
 # Copyright (C) 2006-2010 OpenWrt.org
 # Copyright (C) 2006 Carlos Sobrinho
 
-START=50
+START=19
 STOP=50
 
 USE_PROCD=1
@@ -41,6 +41,8 @@ validate_section_dropbear()
                'Port:list(port):22' \
                'SSHKeepAlive:uinteger:300' \
                'IdleTimeout:uinteger:0' \
+               'MaxAuthTries:uinteger:3' \
+               'RecvWindowSize:uinteger:0' \
                'mdns:bool:1'
 }
 
@@ -49,7 +51,7 @@ dropbear_instance()
        local PasswordAuth enable Interface GatewayPorts \
                RootPasswordAuth RootLogin rsakeyfile \
                BannerFile Port SSHKeepAlive IdleTimeout \
-               mdns ipaddrs
+               MaxAuthTries RecvWindowSize mdns ipaddrs
 
        validate_section_dropbear "${1}" || {
                echo "validation failed"
@@ -57,6 +59,8 @@ dropbear_instance()
        }
 
        [ -n "${Interface}" ] && {
+               [ -n "${BOOT}" ] && return 0
+
                network_get_ipaddrs_all ipaddrs "${Interface}" || {
                        echo "interface ${Interface} has no physdev or physdev has no suitable ip"
                        return 1
@@ -78,6 +82,9 @@ dropbear_instance()
        append_ports "${ipaddrs}" "${Port}"
        [ "${IdleTimeout}" -ne 0 ] && procd_append_param command -I "${IdleTimeout}"
        [ "${SSHKeepAlive}" -ne 0 ] && procd_append_param command -K "${SSHKeepAlive}"
+       [ "${MaxAuthTries}" -ne 0 ] && procd_append_param command -T "${MaxAuthTries}"
+       [ "${RecvWindowSize}" -gt 0 -a "${RecvWindowSize}" -le 1048576 ] && \
+               procd_append_param command -W "${RecvWindowSize}"
        [ "${mdns}" -ne 0 ] && procd_add_mdns "ssh" "tcp" "$Port" "daemon=dropbear"
        procd_set_param respawn
        procd_close_instance
@@ -114,6 +121,12 @@ load_interfaces()
        [ "${enable}" = "1" ] && interfaces=" ${interface} ${interfaces}"
 }
 
+boot()
+{
+       BOOT=1
+       start "$@"
+}
+
 start_service()
 {
        [ -s /etc/dropbear/dropbear_rsa_host_key ] || keygen
@@ -143,6 +156,11 @@ service_triggers()
        procd_add_validation validate_section_dropbear
 }
 
+shutdown() {
+       # close all open connections
+       killall dropbear
+}
+
 killclients()
 {
        local ignore=''