diff options
author | djm@openbsd.org <djm@openbsd.org> | 2016-11-06 06:46:37 +0100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2016-11-06 06:48:29 +0100 |
commit | 010359b32659f455fddd2bd85fd7cc4d7a3b994a (patch) | |
tree | 3e7256e7255cac73e3ab1e9e3bde697a66b60865 /match.c | |
parent | upstream commit (diff) | |
download | openssh-010359b32659f455fddd2bd85fd7cc4d7a3b994a.tar.xz openssh-010359b32659f455fddd2bd85fd7cc4d7a3b994a.zip |
upstream commit
Validate address ranges for AllowUser/DenyUsers at
configuration load time and refuse to accept bad ones. It was previously
possible to specify invalid CIDR address ranges (e.g. djm@127.1.2.3/55) and
these would always match.
Thanks to Laurence Parry for a detailed bug report. ok markus (for
a previous diff version)
Upstream-ID: 9dfcdd9672b06e65233ea4434c38226680d40bfb
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: match.c,v 1.32 2016/09/21 16:55:42 djm Exp $ */ +/* $OpenBSD: match.c,v 1.33 2016/11/06 05:46:37 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * 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, { int mhost, mip; - /* error in ipaddr match */ if ((mip = addr_match_list(ipaddr, patterns)) == -2) - return -1; - else if (mip == -1) /* negative ip address match */ - return 0; + return -1; /* error in ipaddr match */ + else if (host == NULL || ipaddr == NULL || mip == -1) + return 0; /* negative ip address match, or testing pattern */ /* negative hostname match */ if ((mhost = match_hostname(host, patterns)) == -1) @@ -207,7 +206,9 @@ match_host_and_ip(const char *host, const char *ipaddr, } /* - * match user, user@host_or_ip, user@host_or_ip_list against pattern + * Match user, user@host_or_ip, user@host_or_ip_list against pattern. + * If user, host and ipaddr are all NULL then validate pattern/ + * Returns -1 on invalid pattern, 0 on no match, 1 on match. */ int 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, char *p, *pat; int ret; + /* test mode */ + if (user == NULL && host == NULL && ipaddr == NULL) { + if ((p = strchr(pattern, '@')) != NULL && + match_host_and_ip(NULL, NULL, p + 1) < 0) + return -1; + return 0; + } + if ((p = strchr(pattern,'@')) == NULL) return match_pattern(user, pattern); |