summaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-11-25 00:26:21 +1100
committerDamien Miller <djm@mindrot.org>1999-11-25 00:26:21 +1100
commit95def09838fc61b37b6ea7cd5c234a465b4b129b (patch)
tree042744f76f40a326b873cb1c3690a6d7d966bc3e /match.c
parent4d2f15f895f4c795afc008aeff3fd2ceffbc44f4 (diff)
- Merged very large OpenBSD source code reformat
- OpenBSD CVS updates - [channels.c cipher.c compat.c log-client.c scp.c serverloop.c] [ssh.h sshd.8 sshd.c] syslog changes: * Unified Logmessage for all auth-types, for success and for failed * Standard connections get only ONE line in the LOG when level==LOG: Auth-attempts are logged only, if authentication is: a) successfull or b) with passwd or c) we had more than AUTH_FAIL_LOG failues * many log() became verbose() * old behaviour with level=VERBOSE - [readconf.c readconf.h ssh.1 ssh.h sshconnect.c sshd.c] tranfer s/key challenge/response data in SSH_SMSG_AUTH_TIS_CHALLENGE messages. allows use of s/key in windows (ttssh, securecrt) and ssh-1.2.27 clients without 'ssh -v', ok: niels@ - [sshd.8] -V, for fallback to openssh in SSH2 compatibility mode - [sshd.c] fix sigchld race; cjc5@po.cwru.edu
Diffstat (limited to 'match.c')
-rw-r--r--match.c125
1 files changed, 62 insertions, 63 deletions
diff --git a/match.c b/match.c
index b7a7d3389..c0729dd8d 100644
--- a/match.c
+++ b/match.c
@@ -1,78 +1,77 @@
1/* 1/*
2 2 *
3match.c 3 * match.c
4 4 *
5Author: Tatu Ylonen <ylo@cs.hut.fi> 5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
6 6 *
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 All rights reserved 8 * All rights reserved
9 9 *
10Created: Thu Jun 22 01:17:50 1995 ylo 10 * Created: Thu Jun 22 01:17:50 1995 ylo
11 11 *
12Simple pattern matching, with '*' and '?' as wildcards. 12 * Simple pattern matching, with '*' and '?' as wildcards.
13 13 *
14*/ 14 */
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$Id: match.c,v 1.1 1999/10/27 03:42:44 damien Exp $"); 17RCSID("$Id: match.c,v 1.2 1999/11/24 13:26:22 damien Exp $");
18 18
19#include "ssh.h" 19#include "ssh.h"
20 20
21/* Returns true if the given string matches the pattern (which may contain 21/* Returns true if the given string matches the pattern (which may contain
22 ? and * as wildcards), and zero if it does not match. */ 22 ? and * as wildcards), and zero if it does not match. */
23
24int match_pattern(const char *s, const char *pattern)
25{
26 while (1)
27 {
28 /* If at end of pattern, accept if also at end of string. */
29 if (!*pattern)
30 return !*s;
31 23
32 /* Process '*'. */ 24int
33 if (*pattern == '*') 25match_pattern(const char *s, const char *pattern)
34 { 26{
35 /* Skip the asterisk. */ 27 for (;;) {
36 pattern++; 28 /* If at end of pattern, accept if also at end of string. */
29 if (!*pattern)
30 return !*s;
37 31
38 /* If at end of pattern, accept immediately. */ 32 /* Process '*'. */
39 if (!*pattern) 33 if (*pattern == '*') {
40 return 1; 34 /* Skip the asterisk. */
35 pattern++;
41 36
42 /* If next character in pattern is known, optimize. */ 37 /* If at end of pattern, accept immediately. */
43 if (*pattern != '?' && *pattern != '*') 38 if (!*pattern)
44 { 39 return 1;
45 /* Look instances of the next character in pattern, and try
46 to match starting from those. */
47 for (; *s; s++)
48 if (*s == *pattern &&
49 match_pattern(s + 1, pattern + 1))
50 return 1;
51 /* Failed. */
52 return 0;
53 }
54 40
55 /* Move ahead one character at a time and try to match at each 41 /* If next character in pattern is known, optimize. */
56 position. */ 42 if (*pattern != '?' && *pattern != '*') {
57 for (; *s; s++) 43 /* Look instances of the next character in
58 if (match_pattern(s, pattern)) 44 pattern, and try to match starting from
59 return 1; 45 those. */
60 /* Failed. */ 46 for (; *s; s++)
61 return 0; 47 if (*s == *pattern &&
62 } 48 match_pattern(s + 1, pattern + 1))
49 return 1;
50 /* Failed. */
51 return 0;
52 }
53 /* Move ahead one character at a time and try to
54 match at each position. */
55 for (; *s; s++)
56 if (match_pattern(s, pattern))
57 return 1;
58 /* Failed. */
59 return 0;
60 }
61 /* There must be at least one more character in the
62 string. If we are at the end, fail. */
63 if (!*s)
64 return 0;
63 65
64 /* There must be at least one more character in the string. If we are 66 /* Check if the next character of the string is
65 at the end, fail. */ 67 acceptable. */
66 if (!*s) 68 if (*pattern != '?' && *pattern != *s)
67 return 0; 69 return 0;
68 70
69 /* Check if the next character of the string is acceptable. */ 71 /* Move to the next character, both in string and in
70 if (*pattern != '?' && *pattern != *s) 72 pattern. */
71 return 0; 73 s++;
72 74 pattern++;
73 /* Move to the next character, both in string and in pattern. */ 75 }
74 s++; 76 /* NOTREACHED */
75 pattern++;
76 }
77 /*NOTREACHED*/
78} 77}