diff options
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: match.c,v 1.30 2015/05/04 06:10:48 djm Exp $ */ | 1 | /* $OpenBSD: match.c,v 1.33 2016/11/06 05:46:37 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 |
@@ -191,11 +191,10 @@ match_host_and_ip(const char *host, const char *ipaddr, | |||
191 | { | 191 | { |
192 | int mhost, mip; | 192 | int mhost, mip; |
193 | 193 | ||
194 | /* error in ipaddr match */ | ||
195 | if ((mip = addr_match_list(ipaddr, patterns)) == -2) | 194 | if ((mip = addr_match_list(ipaddr, patterns)) == -2) |
196 | return -1; | 195 | return -1; /* error in ipaddr match */ |
197 | else if (mip == -1) /* negative ip address match */ | 196 | else if (host == NULL || ipaddr == NULL || mip == -1) |
198 | return 0; | 197 | return 0; /* negative ip address match, or testing pattern */ |
199 | 198 | ||
200 | /* negative hostname match */ | 199 | /* negative hostname match */ |
201 | if ((mhost = match_hostname(host, patterns)) == -1) | 200 | if ((mhost = match_hostname(host, patterns)) == -1) |
@@ -207,7 +206,9 @@ match_host_and_ip(const char *host, const char *ipaddr, | |||
207 | } | 206 | } |
208 | 207 | ||
209 | /* | 208 | /* |
210 | * match user, user@host_or_ip, user@host_or_ip_list against pattern | 209 | * Match user, user@host_or_ip, user@host_or_ip_list against pattern. |
210 | * If user, host and ipaddr are all NULL then validate pattern/ | ||
211 | * Returns -1 on invalid pattern, 0 on no match, 1 on match. | ||
211 | */ | 212 | */ |
212 | int | 213 | int |
213 | match_user(const char *user, const char *host, const char *ipaddr, | 214 | match_user(const char *user, const char *host, const char *ipaddr, |
@@ -216,6 +217,14 @@ match_user(const char *user, const char *host, const char *ipaddr, | |||
216 | char *p, *pat; | 217 | char *p, *pat; |
217 | int ret; | 218 | int ret; |
218 | 219 | ||
220 | /* test mode */ | ||
221 | if (user == NULL && host == NULL && ipaddr == NULL) { | ||
222 | if ((p = strchr(pattern, '@')) != NULL && | ||
223 | match_host_and_ip(NULL, NULL, p + 1) < 0) | ||
224 | return -1; | ||
225 | return 0; | ||
226 | } | ||
227 | |||
219 | if ((p = strchr(pattern,'@')) == NULL) | 228 | if ((p = strchr(pattern,'@')) == NULL) |
220 | return match_pattern(user, pattern); | 229 | return match_pattern(user, pattern); |
221 | 230 | ||