From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Tue, 27 Sep 2016 03:55:55 +0200
Subject: dropbear: add a failsafe mode that will always allow password-less root login

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>

diff --git a/package/network/services/dropbear/patches/700-failsafe-mode.patch b/package/network/services/dropbear/patches/700-failsafe-mode.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d379da0d0a7890e0a25d87e227c2e065cd2750ee
--- /dev/null
+++ b/package/network/services/dropbear/patches/700-failsafe-mode.patch
@@ -0,0 +1,57 @@
+--- a/runopts.h
++++ b/runopts.h
+@@ -98,6 +98,8 @@ typedef struct svr_runopts {
+ 	int allowblankpass;
+ 	unsigned int maxauthtries;
+ 
++	int failsafe_mode;
++
+ #ifdef ENABLE_SVR_REMOTETCPFWD
+ 	int noremotetcp;
+ #endif
+--- a/svr-auth.c
++++ b/svr-auth.c
+@@ -149,10 +149,11 @@ void recv_msg_userauth_request() {
+ 				AUTH_METHOD_NONE_LEN) == 0) {
+ 		TRACE(("recv_msg_userauth_request: 'none' request"))
+ 		if (valid_user
+-				&& (svr_opts.allowblankpass || !strcmp(ses.authstate.pw_name, "root"))
+-				&& !svr_opts.noauthpass
+-				&& !(svr_opts.norootpass && ses.authstate.pw_uid == 0) 
+-				&& ses.authstate.pw_passwd[0] == '\0') 
++				&& ((svr_opts.failsafe_mode && !strcmp(ses.authstate.pw_name, "root"))
++				|| ((svr_opts.allowblankpass || !strcmp(ses.authstate.pw_name, "root"))
++					&& !svr_opts.noauthpass
++					&& !(svr_opts.norootpass && ses.authstate.pw_uid == 0)
++					&& ses.authstate.pw_passwd[0] == '\0')))
+ 		{
+ 			dropbear_log(LOG_NOTICE, 
+ 					"Auth succeeded with blank password for '%s' from %s",
+--- a/svr-runopts.c
++++ b/svr-runopts.c
+@@ -72,6 +72,7 @@ static void printhelp(const char * progn
+ 					"-s		Disable password logins\n"
+ 					"-g		Disable password logins for root\n"
+ 					"-B		Allow blank password logins\n"
++					"-f		Failsafe mode: always allow password-less root login\n"
+ #endif
+ 					"-T <1 to %d> 	Maximum authentication tries (default %d)\n"
+ #ifdef ENABLE_SVR_LOCALTCPFWD
+@@ -133,6 +134,7 @@ void svr_getopts(int argc, char ** argv)
+ 	svr_opts.noauthpass = 0;
+ 	svr_opts.norootpass = 0;
+ 	svr_opts.allowblankpass = 0;
++	svr_opts.failsafe_mode = 0;
+ 	svr_opts.maxauthtries = DEFAULT_AUTH_TRIES;
+ 	svr_opts.inetdmode = 0;
+ 	svr_opts.portcount = 0;
+@@ -251,6 +253,9 @@ void svr_getopts(int argc, char ** argv)
+ 				case 'B':
+ 					svr_opts.allowblankpass = 1;
+ 					break;
++				case 'f':
++					svr_opts.failsafe_mode = 1;
++					break;
+ #endif
+ 				case 'h':
+ 					printhelp(argv[0]);
