vishalmishra434 / rpms / openssh

Forked from rpms/openssh 3 months ago
Clone
Jakub Jelen efd1b7
From 3caa40f40c7f97ecf46969e050e530338864033e Mon Sep 17 00:00:00 2001
Jakub Jelen efd1b7
From: Jakub Jelen <jjelen@redhat.com>
Jakub Jelen efd1b7
Date: Mon, 25 May 2020 15:46:51 +0200
Jakub Jelen efd1b7
Subject: [PATCH 1/3] regress: Add more test cases
Jakub Jelen efd1b7
Jakub Jelen efd1b7
---
Jakub Jelen efd1b7
 regress/servcfginclude.sh | 36 +++++++++++++++++++++++++++++++++++-
Jakub Jelen efd1b7
 1 file changed, 35 insertions(+), 1 deletion(-)
Jakub Jelen efd1b7
Jakub Jelen efd1b7
diff --git a/regress/servcfginclude.sh b/regress/servcfginclude.sh
Jakub Jelen efd1b7
index b25c8faa..b6a9a248 100644
Jakub Jelen efd1b7
--- a/regress/servcfginclude.sh
Jakub Jelen efd1b7
+++ b/regress/servcfginclude.sh
Jakub Jelen efd1b7
@@ -146,9 +146,43 @@ Include
Jakub Jelen efd1b7
 _EOF
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 trace "disallow invalid with no argument"
Jakub Jelen efd1b7
-${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i.x \
Jakub Jelen efd1b7
+${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i.x -T \
Jakub Jelen efd1b7
     -C "host=x,user=test,addr=127.0.0.1" 2>/dev/null && \
Jakub Jelen efd1b7
 	fail "sshd allowed Include with no argument"
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
+# Ensure the Include before any Match block works as expected (bug #3122)
Jakub Jelen efd1b7
+cat > $OBJ/sshd_config.i << _EOF
Jakub Jelen efd1b7
+Banner /xx
Jakub Jelen efd1b7
+HostKey $OBJ/host.ssh-ed25519
Jakub Jelen efd1b7
+Include $OBJ/sshd_config.i.2
Jakub Jelen efd1b7
+Match host a
Jakub Jelen efd1b7
+	Banner /aaaa
Jakub Jelen efd1b7
+_EOF
Jakub Jelen efd1b7
+cat > $OBJ/sshd_config.i.2 << _EOF
Jakub Jelen efd1b7
+Match host a
Jakub Jelen efd1b7
+	Banner /aa
Jakub Jelen efd1b7
+_EOF
Jakub Jelen efd1b7
+
Jakub Jelen efd1b7
+trace "Include before match blocks"
Jakub Jelen efd1b7
+trial a /aa "included file before match blocks is properly evaluated"
Jakub Jelen efd1b7
+
Jakub Jelen efd1b7
+# Port in included file is correctly interpretted (bug #3169)
Jakub Jelen efd1b7
+cat > $OBJ/sshd_config.i << _EOF
Jakub Jelen efd1b7
+Include $OBJ/sshd_config.i.2
Jakub Jelen efd1b7
+Port 7722
Jakub Jelen efd1b7
+_EOF
Jakub Jelen efd1b7
+cat > $OBJ/sshd_config.i.2 << _EOF
Jakub Jelen efd1b7
+HostKey $OBJ/host.ssh-ed25519
Jakub Jelen efd1b7
+_EOF
Jakub Jelen efd1b7
+
Jakub Jelen efd1b7
+trace "Port after included files"
Jakub Jelen efd1b7
+${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i -T \
Jakub Jelen efd1b7
+    -C "host=x,user=test,addr=127.0.0.1" > $OBJ/sshd_config.out || \
Jakub Jelen efd1b7
+	fail "failed to parse Port after included files"
Jakub Jelen efd1b7
+_port=`grep -i '^port ' $OBJ/sshd_config.out | awk '{print $2}'`
Jakub Jelen efd1b7
+if test "x7722" != "x$_port" ; then
Jakub Jelen efd1b7
+	fail "The Port in included file was intertepretted wrongly. Expected 7722, got $_port"
Jakub Jelen efd1b7
+fi
Jakub Jelen efd1b7
+
Jakub Jelen efd1b7
 # cleanup
Jakub Jelen efd1b7
 rm -f $OBJ/sshd_config.i $OBJ/sshd_config.i.* $OBJ/sshd_config.out
Jakub Jelen efd1b7
-- 
Jakub Jelen efd1b7
2.25.4
Jakub Jelen efd1b7
Jakub Jelen efd1b7
Jakub Jelen efd1b7
From 924922fcb8f34fb4a156367de2ee33ad92a68a6a Mon Sep 17 00:00:00 2001
Jakub Jelen efd1b7
From: Jakub Jelen <jjelen@redhat.com>
Jakub Jelen efd1b7
Date: Mon, 25 May 2020 16:56:39 +0200
Jakub Jelen efd1b7
Subject: [PATCH 2/3] Do not call process_queued_listen_addrs() for every
Jakub Jelen efd1b7
 included file
Jakub Jelen efd1b7
Jakub Jelen efd1b7
Fixes #3169
Jakub Jelen efd1b7
---
Jakub Jelen efd1b7
 servconf.c | 6 +++---
Jakub Jelen efd1b7
 1 file changed, 3 insertions(+), 3 deletions(-)
Jakub Jelen efd1b7
Jakub Jelen efd1b7
diff --git a/servconf.c b/servconf.c
Jakub Jelen efd1b7
index 5bb4b1f8..78a7d87d 100644
Jakub Jelen efd1b7
--- a/servconf.c
Jakub Jelen efd1b7
+++ b/servconf.c
Jakub Jelen efd1b7
@@ -74,7 +74,7 @@ static void add_listen_addr(ServerOptions *, const char *,
Jakub Jelen efd1b7
     const char *, int);
Jakub Jelen efd1b7
 static void add_one_listen_addr(ServerOptions *, const char *,
Jakub Jelen efd1b7
     const char *, int);
Jakub Jelen efd1b7
-void parse_server_config_depth(ServerOptions *options, const char *filename,
Jakub Jelen efd1b7
+static void parse_server_config_depth(ServerOptions *options, const char *filename,
Jakub Jelen efd1b7
     struct sshbuf *conf, struct include_list *includes,
Jakub Jelen efd1b7
     struct connection_info *connectinfo, int flags, int *activep, int depth);
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
@@ -2580,7 +2580,7 @@ copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
Jakub Jelen efd1b7
 #undef M_CP_STRARRAYOPT
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 #define SERVCONF_MAX_DEPTH	16
Jakub Jelen efd1b7
-void
Jakub Jelen efd1b7
+static void
Jakub Jelen efd1b7
 parse_server_config_depth(ServerOptions *options, const char *filename,
Jakub Jelen efd1b7
     struct sshbuf *conf, struct include_list *includes,
Jakub Jelen efd1b7
     struct connection_info *connectinfo, int flags, int *activep, int depth)
Jakub Jelen efd1b7
@@ -2606,7 +2606,6 @@ parse_server_config_depth(ServerOptions *options, const char *filename,
Jakub Jelen efd1b7
 	if (bad_options > 0)
Jakub Jelen efd1b7
 		fatal("%s: terminating, %d bad configuration options",
Jakub Jelen efd1b7
 		    filename, bad_options);
Jakub Jelen efd1b7
-	process_queued_listen_addrs(options);
Jakub Jelen efd1b7
 }
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 void
Jakub Jelen efd1b7
@@ -2617,6 +2616,7 @@ parse_server_config(ServerOptions *options, const char *filename,
Jakub Jelen efd1b7
 	int active = connectinfo ? 0 : 1;
Jakub Jelen efd1b7
 	parse_server_config_depth(options, filename, conf, includes,
Jakub Jelen efd1b7
 	    connectinfo, 0, &active, 0);
Jakub Jelen efd1b7
+	process_queued_listen_addrs(options);
Jakub Jelen efd1b7
 }
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 static const char *
Jakub Jelen efd1b7
-- 
Jakub Jelen efd1b7
2.25.4
Jakub Jelen efd1b7
Jakub Jelen efd1b7
Jakub Jelen efd1b7
From 26d970b4fb373cb7bd99286e41dd095cd1eadbd0 Mon Sep 17 00:00:00 2001
Jakub Jelen efd1b7
From: Jakub Jelen <jjelen@redhat.com>
Jakub Jelen efd1b7
Date: Tue, 26 May 2020 16:25:24 +0200
Jakub Jelen efd1b7
Subject: [PATCH 3/3] servconf: Fix parsing of Match blocks in included files
Jakub Jelen efd1b7
 (#3122)
Jakub Jelen efd1b7
Jakub Jelen efd1b7
---
Jakub Jelen efd1b7
 servconf.c | 28 +++++++++++++++++++---------
Jakub Jelen efd1b7
 1 file changed, 19 insertions(+), 9 deletions(-)
Jakub Jelen efd1b7
Jakub Jelen efd1b7
diff --git a/servconf.c b/servconf.c
Jakub Jelen efd1b7
index 78a7d87d..a8541514 100644
Jakub Jelen efd1b7
--- a/servconf.c
Jakub Jelen efd1b7
+++ b/servconf.c
Jakub Jelen efd1b7
@@ -554,6 +554,7 @@ typedef enum {
Jakub Jelen efd1b7
 #define SSHCFG_MATCH		0x02	/* allowed inside a Match section */
Jakub Jelen efd1b7
 #define SSHCFG_ALL		(SSHCFG_GLOBAL|SSHCFG_MATCH)
Jakub Jelen efd1b7
 #define SSHCFG_NEVERMATCH	0x04  /* Match never matches; internal only */
Jakub Jelen efd1b7
+#define SSHCFG_MATCH_ONLY	0x08  /* Match only in conditional blocks; internal only */
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 /* Textual representation of the tokens. */
Jakub Jelen efd1b7
 static struct {
Jakub Jelen efd1b7
@@ -1265,7 +1266,7 @@ static const struct multistate multistate_tcpfwd[] = {
Jakub Jelen efd1b7
 static int
Jakub Jelen efd1b7
 process_server_config_line_depth(ServerOptions *options, char *line,
Jakub Jelen efd1b7
     const char *filename, int linenum, int *activep,
Jakub Jelen efd1b7
-    struct connection_info *connectinfo, int inc_flags, int depth,
Jakub Jelen efd1b7
+    struct connection_info *connectinfo, int *inc_flags, int depth,
Jakub Jelen efd1b7
     struct include_list *includes)
Jakub Jelen efd1b7
 {
Jakub Jelen efd1b7
 	char ch, *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
Jakub Jelen efd1b7
@@ -2012,7 +2013,9 @@ process_server_config_line_depth(ServerOptions *options, char *line,
Jakub Jelen efd1b7
 					parse_server_config_depth(options,
Jakub Jelen efd1b7
 					    item->filename, item->contents,
Jakub Jelen efd1b7
 					    includes, connectinfo,
Jakub Jelen efd1b7
-					    (oactive ? 0 : SSHCFG_NEVERMATCH),
Jakub Jelen efd1b7
+					    (*inc_flags & SSHCFG_MATCH_ONLY
Jakub Jelen efd1b7
+					        ? SSHCFG_MATCH_ONLY : (oactive
Jakub Jelen efd1b7
+					            ? 0 : SSHCFG_NEVERMATCH)),
Jakub Jelen efd1b7
 					    activep, depth + 1);
Jakub Jelen efd1b7
 				}
Jakub Jelen efd1b7
 				found = 1;
Jakub Jelen efd1b7
@@ -2060,7 +2063,9 @@ process_server_config_line_depth(ServerOptions *options, char *line,
Jakub Jelen efd1b7
 				parse_server_config_depth(options,
Jakub Jelen efd1b7
 				    item->filename, item->contents,
Jakub Jelen efd1b7
 				    includes, connectinfo,
Jakub Jelen efd1b7
-				    (oactive ? 0 : SSHCFG_NEVERMATCH),
Jakub Jelen efd1b7
+				    (*inc_flags & SSHCFG_MATCH_ONLY
Jakub Jelen efd1b7
+				        ? SSHCFG_MATCH_ONLY : (oactive
Jakub Jelen efd1b7
+				            ? 0 : SSHCFG_NEVERMATCH)),
Jakub Jelen efd1b7
 				    activep, depth + 1);
Jakub Jelen efd1b7
 				*activep = oactive;
Jakub Jelen efd1b7
 				TAILQ_INSERT_TAIL(includes, item, entry);
Jakub Jelen efd1b7
@@ -2078,11 +2083,14 @@ process_server_config_line_depth(ServerOptions *options, char *line,
Jakub Jelen efd1b7
 		if (cmdline)
Jakub Jelen efd1b7
 			fatal("Match directive not supported as a command-line "
Jakub Jelen efd1b7
 			   "option");
Jakub Jelen efd1b7
-		value = match_cfg_line(&cp, linenum, connectinfo);
Jakub Jelen efd1b7
+		value = match_cfg_line(&cp, linenum,
Jakub Jelen efd1b7
+		    (*inc_flags & SSHCFG_NEVERMATCH ? NULL : connectinfo));
Jakub Jelen efd1b7
 		if (value < 0)
Jakub Jelen efd1b7
 			fatal("%s line %d: Bad Match condition", filename,
Jakub Jelen efd1b7
 			    linenum);
Jakub Jelen efd1b7
-		*activep = (inc_flags & SSHCFG_NEVERMATCH) ? 0 : value;
Jakub Jelen efd1b7
+		*activep = (*inc_flags & SSHCFG_NEVERMATCH) ? 0 : value;
Jakub Jelen efd1b7
+		/* The MATCH_ONLY is applicable only until the first match block */
Jakub Jelen efd1b7
+		*inc_flags &= ~SSHCFG_MATCH_ONLY;
Jakub Jelen efd1b7
 		break;
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 	case sKerberosUseKuserok:
Jakub Jelen efd1b7
@@ -2385,8 +2393,9 @@ process_server_config_line(ServerOptions *options, char *line,
Jakub Jelen efd1b7
     const char *filename, int linenum, int *activep,
Jakub Jelen efd1b7
     struct connection_info *connectinfo, struct include_list *includes)
Jakub Jelen efd1b7
 {
Jakub Jelen efd1b7
+	int inc_flags = 0;
Jakub Jelen efd1b7
 	return process_server_config_line_depth(options, line, filename,
Jakub Jelen efd1b7
-	    linenum, activep, connectinfo, 0, 0, includes);
Jakub Jelen efd1b7
+	    linenum, activep, connectinfo, &inc_flags, 0, includes);
Jakub Jelen efd1b7
 }
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
@@ -2591,14 +2600,15 @@ parse_server_config_depth(ServerOptions *options, const char *filename,
Jakub Jelen efd1b7
 	if (depth < 0 || depth > SERVCONF_MAX_DEPTH)
Jakub Jelen efd1b7
 		fatal("Too many recursive configuration includes");
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
-	debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
Jakub Jelen efd1b7
+	debug2("%s: config %s len %zu%s", __func__, filename, sshbuf_len(conf),
Jakub Jelen efd1b7
+	    (flags & SSHCFG_NEVERMATCH ? " [checking syntax only]" : ""));
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
 	if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
Jakub Jelen efd1b7
 		fatal("%s: sshbuf_dup_string failed", __func__);
Jakub Jelen efd1b7
 	linenum = 1;
Jakub Jelen efd1b7
 	while ((cp = strsep(&cbuf, "\n")) != NULL) {
Jakub Jelen efd1b7
 		if (process_server_config_line_depth(options, cp,
Jakub Jelen efd1b7
-		    filename, linenum++, activep, connectinfo, flags,
Jakub Jelen efd1b7
+		    filename, linenum++, activep, connectinfo, &flags,
Jakub Jelen efd1b7
 		    depth, includes) != 0)
Jakub Jelen efd1b7
 			bad_options++;
Jakub Jelen efd1b7
 	}
Jakub Jelen efd1b7
@@ -2615,7 +2625,7 @@ parse_server_config(ServerOptions *options, const char *filename,
Jakub Jelen efd1b7
 {
Jakub Jelen efd1b7
 	int active = connectinfo ? 0 : 1;
Jakub Jelen efd1b7
 	parse_server_config_depth(options, filename, conf, includes,
Jakub Jelen efd1b7
-	    connectinfo, 0, &active, 0);
Jakub Jelen efd1b7
+	    connectinfo, (connectinfo ? SSHCFG_MATCH_ONLY : 0), &active, 0);
Jakub Jelen efd1b7
 	process_queued_listen_addrs(options);
Jakub Jelen efd1b7
 }
Jakub Jelen efd1b7
 
Jakub Jelen efd1b7
-- 
Jakub Jelen efd1b7
2.25.4
Jakub Jelen efd1b7
Jakub Jelen efd1b7