jonathancammack / rpms / openssh

Forked from rpms/openssh 8 months ago
Clone
b85a86
diff --git a/servconf.c b/servconf.c
b85a86
index ffac5d2c..340045b2 100644
b85a86
--- a/servconf.c
b85a86
+++ b/servconf.c
b85a86
@@ -1042,7 +1042,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
b85a86
 			return -1;
b85a86
 		}
b85a86
 		if (strcasecmp(attrib, "user") == 0) {
b85a86
-			if (ci == NULL) {
b85a86
+			if (ci == NULL || (ci->test && ci->user == NULL)) {
b85a86
 				result = 0;
b85a86
 				continue;
b85a86
 			}
b85a86
@@ -1054,7 +1054,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
b85a86
 				debug("user %.100s matched 'User %.100s' at "
b85a86
 				    "line %d", ci->user, arg, line);
b85a86
 		} else if (strcasecmp(attrib, "group") == 0) {
b85a86
-			if (ci == NULL) {
b85a86
+			if (ci == NULL || (ci->test && ci->user == NULL)) {
b85a86
 				result = 0;
b85a86
 				continue;
b85a86
 			}
b85a86
@@ -1067,7 +1067,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
b85a86
 				result = 0;
b85a86
 			}
b85a86
 		} else if (strcasecmp(attrib, "host") == 0) {
b85a86
-			if (ci == NULL) {
b85a86
+			if (ci == NULL || (ci->test && ci->host == NULL)) {
b85a86
 				result = 0;
b85a86
 				continue;
b85a86
 			}
b85a86
@@ -1079,7 +1079,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
b85a86
 				debug("connection from %.100s matched 'Host "
b85a86
 				    "%.100s' at line %d", ci->host, arg, line);
b85a86
 		} else if (strcasecmp(attrib, "address") == 0) {
b85a86
-			if (ci == NULL) {
b85a86
+			if (ci == NULL || (ci->test && ci->address == NULL)) {
b85a86
 				result = 0;
b85a86
 				continue;
b85a86
 			}
b85a86
@@ -1098,7 +1098,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
b85a86
 				return -1;
b85a86
 			}
b85a86
 		} else if (strcasecmp(attrib, "localaddress") == 0){
b85a86
-			if (ci == NULL) {
b85a86
+			if (ci == NULL || (ci->test && ci->laddress == NULL)) {
b85a86
 				result = 0;
b85a86
 				continue;
b85a86
 			}
b85a86
@@ -1124,7 +1124,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
b85a86
 				    arg);
b85a86
 				return -1;
b85a86
 			}
b85a86
-			if (ci == NULL) {
b85a86
+			if (ci == NULL || (ci->test && ci->lport == -1)) {
b85a86
 				result = 0;
b85a86
 				continue;
b85a86
 			}
b85a86
@@ -1138,10 +1138,12 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
b85a86
 			else
b85a86
 				result = 0;
b85a86
 		} else if (strcasecmp(attrib, "rdomain") == 0) {
b85a86
-			if (ci == NULL || ci->rdomain == NULL) {
b85a86
+			if (ci == NULL || (ci->test && ci->rdomain == NULL)) {
b85a86
 				result = 0;
b85a86
 				continue;
b85a86
 			}
b85a86
+			if (ci->rdomain == NULL)
b85a86
+				match_test_missing_fatal("RDomain", "rdomain");
b85a86
 			if (match_pattern_list(ci->rdomain, arg, 0) != 1)
b85a86
 				result = 0;
b85a86
 			else
b85a86
diff --git a/servconf.h b/servconf.h
b85a86
index 54e0a8d8..5483da05 100644
b85a86
--- a/servconf.h
b85a86
+++ b/servconf.h
b85a86
@@ -221,6 +221,8 @@ struct connection_info {
b85a86
 	const char *laddress;	/* local address */
b85a86
 	int lport;		/* local port */
b85a86
 	const char *rdomain;	/* routing domain if available */
b85a86
+	int test;		/* test mode, allow some attributes to be
b85a86
+				 * unspecified */
b85a86
 };
b85a86
 
b85a86
 
b85a86
diff --git a/sshd.c b/sshd.c
b85a86
index cbd3bce9..1fcde502 100644
b85a86
--- a/sshd.c
b85a86
+++ b/sshd.c
b85a86
@@ -1843,6 +1843,7 @@ main(int ac, char **av)
b85a86
 		 */
b85a86
 		if (connection_info == NULL)
b85a86
 			connection_info = get_connection_info(ssh, 0, 0);
b85a86
+		connection_info->test = 1;
b85a86
 		parse_server_match_config(&options, connection_info);
b85a86
 		dump_config(&options);
b85a86
 	}