diff options
author | Colin Watson <cjwatson@debian.org> | 2018-08-24 12:49:36 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2018-08-30 00:57:27 +0100 |
commit | 816386e17654ca36834bebbf351419e460fad8f6 (patch) | |
tree | 3dc79d831cb73bc25b92f5a4d18f8e328c0c570a /match.c | |
parent | 3e6f76c7039d3df22b1d0a3a5f30150efb09b69d (diff) | |
parent | 16a47fc4b04977a14f44dd433c8da1499fa80671 (diff) |
New upstream release (7.8p1)
Closes: #907534
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 36 |
1 files changed, 30 insertions, 6 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: match.c,v 1.37 2017/03/10 04:24:55 djm Exp $ */ | 1 | /* $OpenBSD: match.c,v 1.38 2018/07/04 13:49:31 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * 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) | |||
294 | } | 294 | } |
295 | 295 | ||
296 | /* | 296 | /* |
297 | * Filters a comma-separated list of strings, excluding any entry matching | 297 | * Filter proposal using pattern-list filter. |
298 | * the 'filter' pattern list. Caller must free returned string. | 298 | * "blacklist" determines sense of filter: |
299 | * non-zero indicates that items matching filter should be excluded. | ||
300 | * zero indicates that only items matching filter should be included. | ||
301 | * returns NULL on allocation error, otherwise caller must free result. | ||
299 | */ | 302 | */ |
300 | char * | 303 | static char * |
301 | match_filter_list(const char *proposal, const char *filter) | 304 | filter_list(const char *proposal, const char *filter, int blacklist) |
302 | { | 305 | { |
303 | size_t len = strlen(proposal) + 1; | 306 | size_t len = strlen(proposal) + 1; |
304 | char *fix_prop = malloc(len); | 307 | char *fix_prop = malloc(len); |
305 | char *orig_prop = strdup(proposal); | 308 | char *orig_prop = strdup(proposal); |
306 | char *cp, *tmp; | 309 | char *cp, *tmp; |
310 | int r; | ||
307 | 311 | ||
308 | if (fix_prop == NULL || orig_prop == NULL) { | 312 | if (fix_prop == NULL || orig_prop == NULL) { |
309 | free(orig_prop); | 313 | free(orig_prop); |
@@ -314,7 +318,8 @@ match_filter_list(const char *proposal, const char *filter) | |||
314 | tmp = orig_prop; | 318 | tmp = orig_prop; |
315 | *fix_prop = '\0'; | 319 | *fix_prop = '\0'; |
316 | while ((cp = strsep(&tmp, ",")) != NULL) { | 320 | while ((cp = strsep(&tmp, ",")) != NULL) { |
317 | if (match_pattern_list(cp, filter, 0) != 1) { | 321 | r = match_pattern_list(cp, filter, 0); |
322 | if ((blacklist && r != 1) || (!blacklist && r == 1)) { | ||
318 | if (*fix_prop != '\0') | 323 | if (*fix_prop != '\0') |
319 | strlcat(fix_prop, ",", len); | 324 | strlcat(fix_prop, ",", len); |
320 | strlcat(fix_prop, cp, len); | 325 | strlcat(fix_prop, cp, len); |
@@ -324,3 +329,22 @@ match_filter_list(const char *proposal, const char *filter) | |||
324 | return fix_prop; | 329 | return fix_prop; |
325 | } | 330 | } |
326 | 331 | ||
332 | /* | ||
333 | * Filters a comma-separated list of strings, excluding any entry matching | ||
334 | * the 'filter' pattern list. Caller must free returned string. | ||
335 | */ | ||
336 | char * | ||
337 | match_filter_blacklist(const char *proposal, const char *filter) | ||
338 | { | ||
339 | return filter_list(proposal, filter, 1); | ||
340 | } | ||
341 | |||
342 | /* | ||
343 | * Filters a comma-separated list of strings, including only entries matching | ||
344 | * the 'filter' pattern list. Caller must free returned string. | ||
345 | */ | ||
346 | char * | ||
347 | match_filter_whitelist(const char *proposal, const char *filter) | ||
348 | { | ||
349 | return filter_list(proposal, filter, 0); | ||
350 | } | ||