aboutsummaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2018-08-28 10:47:58 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2018-08-28 10:47:58 +0000
commitd46065df2d60bfbd08939733bd79b2a440d6fbc8 (patch)
tree720921fc9471de3c67f5b8dc1404c8f6c6a02cb1 /match.c
parent3d0e42005d3bf786341ab96cfa1788bc601faa12 (diff)
downloadsrc-d46065df2d60bfbd08939733bd79b2a440d6fbc8.tar.gz
src-d46065df2d60bfbd08939733bd79b2a440d6fbc8.zip
Vendor import of OpenSSH 7.8p1.vendor/openssh/7.8p1
Notes
Notes: svn path=/vendor-crypto/openssh/dist/; revision=338344 svn path=/vendor-crypto/openssh/7.8p1/; revision=338345; tag=vendor/openssh/7.8p1
Diffstat (limited to 'match.c')
-rw-r--r--match.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/match.c b/match.c
index 3cf40306b025..bb3e95f678ca 100644
--- a/match.c
+++ b/match.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: match.c,v 1.37 2017/03/10 04:24:55 djm Exp $ */
+/* $OpenBSD: match.c,v 1.38 2018/07/04 13:49:31 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -294,16 +294,20 @@ match_list(const char *client, const char *server, u_int *next)
}
/*
- * Filters a comma-separated list of strings, excluding any entry matching
- * the 'filter' pattern list. Caller must free returned string.
+ * Filter proposal using pattern-list filter.
+ * "blacklist" determines sense of filter:
+ * non-zero indicates that items matching filter should be excluded.
+ * zero indicates that only items matching filter should be included.
+ * returns NULL on allocation error, otherwise caller must free result.
*/
-char *
-match_filter_list(const char *proposal, const char *filter)
+static char *
+filter_list(const char *proposal, const char *filter, int blacklist)
{
size_t len = strlen(proposal) + 1;
char *fix_prop = malloc(len);
char *orig_prop = strdup(proposal);
char *cp, *tmp;
+ int r;
if (fix_prop == NULL || orig_prop == NULL) {
free(orig_prop);
@@ -314,7 +318,8 @@ match_filter_list(const char *proposal, const char *filter)
tmp = orig_prop;
*fix_prop = '\0';
while ((cp = strsep(&tmp, ",")) != NULL) {
- if (match_pattern_list(cp, filter, 0) != 1) {
+ r = match_pattern_list(cp, filter, 0);
+ if ((blacklist && r != 1) || (!blacklist && r == 1)) {
if (*fix_prop != '\0')
strlcat(fix_prop, ",", len);
strlcat(fix_prop, cp, len);
@@ -324,3 +329,22 @@ match_filter_list(const char *proposal, const char *filter)
return fix_prop;
}
+/*
+ * Filters a comma-separated list of strings, excluding any entry matching
+ * the 'filter' pattern list. Caller must free returned string.
+ */
+char *
+match_filter_blacklist(const char *proposal, const char *filter)
+{
+ return filter_list(proposal, filter, 1);
+}
+
+/*
+ * Filters a comma-separated list of strings, including only entries matching
+ * the 'filter' pattern list. Caller must free returned string.
+ */
+char *
+match_filter_whitelist(const char *proposal, const char *filter)
+{
+ return filter_list(proposal, filter, 0);
+}