ipq40xx: fix dts error in LED color/function conversion
[openwrt/staging/robimarko.git] / package / network / services / dropbear / patches / 001-fix-MAX_UNAUTH_CLIENTS-regression.patch
1 From: Matt Johnston <matt@ucc.asn.au>
2 Date: Wed, 8 Jun 2022 21:26:20 +0800
3 Subject: Fix MAX_UNAUTH_CLIENTS regression
4
5 Since re-exec change in 2022.82 Dropbear count
6 treat authenticated sessions towards the unauthenticated
7 session limit. This is fixed by passing the childpipe FD
8 through to the re-execed process.
9 ---
10 runopts.h | 5 +++--
11 svr-main.c | 21 +++++++++++----------
12 svr-runopts.c | 15 ++++++++++++---
13 3 files changed, 26 insertions(+), 15 deletions(-)
14
15 --- a/runopts.h
16 +++ b/runopts.h
17 @@ -79,8 +79,9 @@ typedef struct svr_runopts {
18 char *addresses[DROPBEAR_MAX_PORTS];
19
20 int inetdmode;
21 - /* Hidden "-2" flag indicates it's re-executing itself */
22 - int reexec_child;
23 + /* Hidden "-2 childpipe_fd" flag indicates it's re-executing itself,
24 + stores the childpipe preauth file descriptor. Set to -1 otherwise. */
25 + int reexec_childpipe;
26
27 /* Flags indicating whether to use ipv4 and ipv6 */
28 /* not used yet
29 --- a/svr-main.c
30 +++ b/svr-main.c
31 @@ -71,7 +71,7 @@ int main(int argc, char ** argv)
32 #endif
33
34 #if DROPBEAR_DO_REEXEC
35 - if (svr_opts.reexec_child) {
36 + if (svr_opts.reexec_childpipe >= 0) {
37 #ifdef PR_SET_NAME
38 /* Fix the "Name:" in /proc/pid/status, otherwise it's
39 a FD number from fexecve.
40 @@ -102,7 +102,7 @@ static void main_inetd() {
41
42 seedrandom();
43
44 - if (!svr_opts.reexec_child) {
45 + if (svr_opts.reexec_childpipe < 0) {
46 /* In case our inetd was lax in logging source addresses */
47 get_socket_address(0, NULL, NULL, &host, &port, 0);
48 dropbear_log(LOG_INFO, "Child connection from %s:%s", host, port);
49 @@ -115,10 +115,8 @@ static void main_inetd() {
50 setsid();
51 }
52
53 - /* Start service program
54 - * -1 is a dummy childpipe, just something we can close() without
55 - * mattering. */
56 - svr_session(0, -1);
57 + /* -1 for childpipe in the inetd case is discarded */
58 + svr_session(0, svr_opts.reexec_childpipe);
59
60 /* notreached */
61 }
62 @@ -347,9 +345,10 @@ static void main_noinetd(int argc, char
63
64 if (execfd >= 0) {
65 #if DROPBEAR_DO_REEXEC
66 - /* Add "-2" to the args and re-execute ourself. */
67 - char **new_argv = m_malloc(sizeof(char*) * (argc+3));
68 - int pos0 = 0, new_argc = argc+1;
69 + /* Add "-2 childpipe[1]" to the args and re-execute ourself. */
70 + char **new_argv = m_malloc(sizeof(char*) * (argc+4));
71 + char buf[10];
72 + int pos0 = 0, new_argc = argc+2;
73
74 /* We need to specially handle "dropbearmulti dropbear". */
75 if (multipath) {
76 @@ -359,7 +358,9 @@ static void main_noinetd(int argc, char
77 }
78
79 memcpy(&new_argv[pos0], argv, sizeof(char*) * argc);
80 - new_argv[new_argc-1] = "-2";
81 + new_argv[new_argc-2] = "-2";
82 + snprintf(buf, sizeof(buf), "%d", childpipe[1]);
83 + new_argv[new_argc-1] = buf;
84 new_argv[new_argc] = NULL;
85
86 if ((dup2(childsock, STDIN_FILENO) < 0)) {
87 --- a/svr-runopts.c
88 +++ b/svr-runopts.c
89 @@ -138,6 +138,7 @@ void svr_getopts(int argc, char ** argv)
90 char* keepalive_arg = NULL;
91 char* idle_timeout_arg = NULL;
92 char* maxauthtries_arg = NULL;
93 + char* reexec_fd_arg = NULL;
94 char* keyfile = NULL;
95 char c;
96 #if DROPBEAR_PLUGIN
97 @@ -175,6 +176,7 @@ void svr_getopts(int argc, char ** argv)
98 svr_opts.pubkey_plugin_options = NULL;
99 #endif
100 svr_opts.pass_on_env = 0;
101 + svr_opts.reexec_childpipe = -1;
102
103 #ifndef DISABLE_ZLIB
104 opts.compress_mode = DROPBEAR_COMPRESS_DELAYED;
105 @@ -250,12 +252,12 @@ void svr_getopts(int argc, char ** argv)
106 #if DROPBEAR_DO_REEXEC && NON_INETD_MODE
107 /* For internal use by re-exec */
108 case '2':
109 - svr_opts.reexec_child = 1;
110 + next = &reexec_fd_arg;
111 break;
112 #endif
113 case 'p':
114 - nextisport = 1;
115 - break;
116 + nextisport = 1;
117 + break;
118 case 'P':
119 next = &svr_opts.pidfile;
120 break;
121 @@ -426,6 +428,13 @@ void svr_getopts(int argc, char ** argv)
122 dropbear_log(LOG_INFO, "Forced command set to '%s'", svr_opts.forced_command);
123 }
124
125 + if (reexec_fd_arg) {
126 + if (m_str_to_uint(reexec_fd_arg, &svr_opts.reexec_childpipe) == DROPBEAR_FAILURE
127 + || svr_opts.reexec_childpipe < 0) {
128 + dropbear_exit("Bad -2");
129 + }
130 + }
131 +
132 #if INETD_MODE
133 if (svr_opts.inetdmode && (
134 opts.usingsyslog == 0