diff options
author | Damien Miller <djm@mindrot.org> | 2000-03-26 05:04:51 +0200 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2000-03-26 05:04:51 +0200 |
commit | 450a7a1ff40fe7c2d84c93b83cf2df53445d807d (patch) | |
tree | db6d08bdea65edd34ba2e323a31e2b1ca5e5fbd4 /match.c | |
parent | - Better tests for OpenSSL w/ RSAref (diff) | |
download | openssh-450a7a1ff40fe7c2d84c93b83cf2df53445d807d.tar.xz openssh-450a7a1ff40fe7c2d84c93b83cf2df53445d807d.zip |
- OpenBSD CVS update
- [auth-krb4.c]
-Wall
- [auth-rh-rsa.c auth-rsa.c hostfile.c hostfile.h key.c key.h match.c]
[match.h ssh.c ssh.h sshconnect.c sshd.c]
initial support for DSA keys. ok deraadt@, niels@
- [cipher.c cipher.h]
remove unused cipher_attack_detected code
- [scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh.1 sshd.8]
Fix some formatting problems I missed before.
- [ssh.1 sshd.8]
fix spelling errors, From: FreeBSD
- [ssh.c]
switch to raw mode only if he _get_ a pty (not if we _want_ a pty).
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 61 |
1 files changed, 60 insertions, 1 deletions
@@ -14,7 +14,7 @@ */ #include "includes.h" -RCSID("$Id: match.c,v 1.3 1999/11/25 00:54:59 damien Exp $"); +RCSID("$Id: match.c,v 1.4 2000/03/26 03:04:53 damien Exp $"); #include "ssh.h" @@ -80,3 +80,62 @@ match_pattern(const char *s, const char *pattern) } /* NOTREACHED */ } + +/* + * Tries to match the host name (which must be in all lowercase) against the + * comma-separated sequence of subpatterns (each possibly preceded by ! to + * indicate negation). Returns true if there is a positive match; zero + * otherwise. + */ + +int +match_hostname(const char *host, const char *pattern, unsigned int len) +{ + char sub[1024]; + int negated; + int got_positive; + unsigned int i, subi; + + got_positive = 0; + for (i = 0; i < len;) { + /* Check if the subpattern is negated. */ + if (pattern[i] == '!') { + negated = 1; + i++; + } else + negated = 0; + + /* + * Extract the subpattern up to a comma or end. Convert the + * subpattern to lowercase. + */ + for (subi = 0; + i < len && subi < sizeof(sub) - 1 && pattern[i] != ','; + subi++, i++) + sub[subi] = isupper(pattern[i]) ? tolower(pattern[i]) : pattern[i]; + /* If subpattern too long, return failure (no match). */ + if (subi >= sizeof(sub) - 1) + return 0; + + /* If the subpattern was terminated by a comma, skip the comma. */ + if (i < len && pattern[i] == ',') + i++; + + /* Null-terminate the subpattern. */ + sub[subi] = '\0'; + + /* Try to match the subpattern against the host name. */ + if (match_pattern(host, sub)) { + if (negated) + return 0; /* Fail */ + else + got_positive = 1; + } + } + + /* + * Return success if got a positive match. If there was a negative + * match, we have already returned zero and never get here. + */ + return got_positive; +} |