Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | #include "includes.h" | - |
39 | | - |
40 | #include <sys/types.h> | - |
41 | | - |
42 | #include <ctype.h> | - |
43 | #include <stdlib.h> | - |
44 | #include <string.h> | - |
45 | #include <stdio.h> | - |
46 | | - |
47 | #include "xmalloc.h" | - |
48 | #include "match.h" | - |
49 | #include "misc.h" | - |
50 | | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | int | - |
57 | match_pattern(const char *s, const char *pattern) | - |
58 | { | - |
59 | for (;;) { | - |
60 | | - |
61 | if (!*pattern)TRUE | evaluated 162 times by 2 tests | FALSE | evaluated 16225 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 162-16225 |
62 | return !*s;executed 162 times by 2 tests: return !*s; | 162 |
63 | | - |
64 | if (*pattern == '*') {TRUE | evaluated 250 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 15975 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 250-15975 |
65 | | - |
66 | pattern++; | - |
67 | | - |
68 | | - |
69 | if (!*pattern)TRUE | evaluated 117 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 133 times by 2 tests |
| 117-133 |
70 | return 1;executed 117 times by 3 tests: return 1; Executed by:- test_hostkeys
- test_kex
- test_match
| 117 |
71 | | - |
72 | | - |
73 | if (*pattern != '?' && *pattern != '*') {TRUE | evaluated 133 times by 2 tests | FALSE | never evaluated |
TRUE | evaluated 132 times by 2 tests | FALSE | evaluated 1 time by 1 test |
| 0-133 |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | for (; *s; s++)TRUE | evaluated 1664 times by 2 tests | FALSE | evaluated 91 times by 2 tests |
| 91-1664 |
80 | if (*s == *pattern &&TRUE | evaluated 198 times by 2 tests | FALSE | evaluated 1466 times by 2 tests |
| 198-1466 |
81 | match_pattern(s + 1, pattern + 1))TRUE | evaluated 41 times by 2 tests | FALSE | evaluated 157 times by 2 tests |
| 41-157 |
82 | return 1;executed 41 times by 2 tests: return 1; | 41 |
83 | | - |
84 | return 0;executed 91 times by 2 tests: return 0; | 91 |
85 | } | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | for (; *s; s++)TRUE | evaluated 1 time by 1 test | FALSE | never evaluated |
| 0-1 |
91 | if (match_pattern(s, pattern))TRUE | evaluated 1 time by 1 test | FALSE | never evaluated |
| 0-1 |
92 | return 1;executed 1 time by 1 test: return 1; | 1 |
93 | | - |
94 | return 0; never executed: return 0; | 0 |
95 | } | - |
96 | | - |
97 | | - |
98 | | - |
99 | | - |
100 | if (!*s)TRUE | evaluated 8 times by 1 test | FALSE | evaluated 15967 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 8-15967 |
101 | return 0;executed 8 times by 1 test: return 0; | 8 |
102 | | - |
103 | | - |
104 | if (*pattern != '?' && *pattern != *s)TRUE | evaluated 15962 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 5 times by 1 test |
TRUE | evaluated 2154 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 13808 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 5-15962 |
105 | return 0;executed 2154 times by 3 tests: return 0; Executed by:- test_hostkeys
- test_kex
- test_match
| 2154 |
106 | | - |
107 | | - |
108 | s++; | - |
109 | pattern++; | - |
110 | }executed 13813 times by 3 tests: end of block Executed by:- test_hostkeys
- test_kex
- test_match
| 13813 |
111 | | - |
112 | } never executed: end of block | 0 |
113 | | - |
114 | | - |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | | - |
120 | int | - |
121 | match_pattern_list(const char *string, const char *pattern, int dolower) | - |
122 | { | - |
123 | char sub[1024]; | - |
124 | int negated; | - |
125 | int got_positive; | - |
126 | u_int i, subi, len = strlen(pattern); | - |
127 | | - |
128 | got_positive = 0; | - |
129 | for (i = 0; i < len;) {TRUE | evaluated 2356 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 1136 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 1136-2356 |
130 | | - |
131 | if (pattern[i] == '!') {TRUE | evaluated 16 times by 1 test | FALSE | evaluated 2340 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 16-2340 |
132 | negated = 1; | - |
133 | i++; | - |
134 | } elseexecuted 16 times by 1 test: end of block | 16 |
135 | negated = 0;executed 2340 times by 3 tests: negated = 0; Executed by:- test_hostkeys
- test_kex
- test_match
| 2340 |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | for (subi = 0; | - |
142 | i < len && subi < sizeof(sub) - 1 && pattern[i] != ',';TRUE | evaluated 30155 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 1139 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
TRUE | evaluated 30155 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | never evaluated |
TRUE | evaluated 28938 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 1217 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 0-30155 |
143 | subi++, i++) | - |
144 | sub[subi] = dolower && isupper((u_char)pattern[i]) ?executed 28938 times by 3 tests: sub[subi] = dolower && ((*__ctype_b_loc ())[(int) (( (u_char)pattern[i] ))] & (unsigned short int) _ISupper) ? (__extension__ ({ int __res; if (sizeof ( (u_char)pattern[i] ) > 1) { if (__builtin_constant_p ( (u_char)pattern[i] )) { int __c = ( (u_char)pattern[i] ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( (u_char)pattern[i] ); } else __res = (*__ctype_tolower_loc ())[(int) ( (u_char)pattern[i] )]; __res; })) : pattern[i]; Executed by:- test_hostkeys
- test_kex
- test_match
TRUE | evaluated 13500 times by 2 tests | FALSE | evaluated 15438 times by 2 tests |
TRUE | evaluated 3 times by 1 test | FALSE | evaluated 13497 times by 2 tests |
| 3-28938 |
145 | tolower((u_char)pattern[i]) : pattern[i];executed 28938 times by 3 tests: sub[subi] = dolower && ((*__ctype_b_loc ())[(int) (( (u_char)pattern[i] ))] & (unsigned short int) _ISupper) ? (__extension__ ({ int __res; if (sizeof ( (u_char)pattern[i] ) > 1) { if (__builtin_constant_p ( (u_char)pattern[i] )) { int __c = ( (u_char)pattern[i] ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( (u_char)pattern[i] ); } else __res = (*__ctype_tolower_loc ())[(int) ( (u_char)pattern[i] )]; __res; })) : pattern[i]; Executed by:- test_hostkeys
- test_kex
- test_match
never executed: end of block never executed: __res = tolower ( (u_char)pattern[i] ); executed 3 times by 1 test: __res = (*__ctype_tolower_loc ())[(int) ( (u_char)pattern[i] )]; TRUE | never evaluated | FALSE | evaluated 3 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-28938 |
146 | | - |
147 | if (subi >= sizeof(sub) - 1)TRUE | never evaluated | FALSE | evaluated 2356 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 0-2356 |
148 | return 0; never executed: return 0; | 0 |
149 | | - |
150 | | - |
151 | if (i < len && pattern[i] == ',')TRUE | evaluated 1217 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 1139 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
TRUE | evaluated 1217 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | never evaluated |
| 0-1217 |
152 | i++;executed 1217 times by 3 tests: i++; Executed by:- test_hostkeys
- test_kex
- test_match
| 1217 |
153 | | - |
154 | | - |
155 | sub[subi] = '\0'; | - |
156 | | - |
157 | | - |
158 | if (match_pattern(string, sub)) {TRUE | evaluated 264 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
| FALSE | evaluated 2092 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 264-2092 |
159 | if (negated)TRUE | evaluated 12 times by 1 test | FALSE | evaluated 252 times by 3 testsEvaluated by:- test_hostkeys
- test_kex
- test_match
|
| 12-252 |
160 | return -1; executed 12 times by 1 test: return -1; | 12 |
161 | else | - |
162 | got_positive = 1; executed 252 times by 3 tests: got_positive = 1; Executed by:- test_hostkeys
- test_kex
- test_match
| 252 |
163 | } | - |
164 | }executed 2344 times by 3 tests: end of block Executed by:- test_hostkeys
- test_kex
- test_match
| 2344 |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | return got_positive;executed 1136 times by 3 tests: return got_positive; Executed by:- test_hostkeys
- test_kex
- test_match
| 1136 |
171 | } | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | int | - |
180 | match_hostname(const char *host, const char *pattern) | - |
181 | { | - |
182 | char *hostcopy = xstrdup(host); | - |
183 | int r; | - |
184 | | - |
185 | lowercase(hostcopy); | - |
186 | r = match_pattern_list(hostcopy, pattern, 1); | - |
187 | free(hostcopy); | - |
188 | return r;executed 520 times by 1 test: return r; | 520 |
189 | } | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | | - |
195 | | - |
196 | int | - |
197 | match_host_and_ip(const char *host, const char *ipaddr, | - |
198 | const char *patterns) | - |
199 | { | - |
200 | int mhost, mip; | - |
201 | | - |
202 | if ((mip = addr_match_list(ipaddr, patterns)) == -2)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
203 | return -1; never executed: return -1; | 0 |
204 | else if (host == NULL || ipaddr == NULL || mip == -1)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
205 | return 0; never executed: return 0; | 0 |
206 | | - |
207 | | - |
208 | if ((mhost = match_hostname(host, patterns)) == -1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
209 | return 0; never executed: return 0; | 0 |
210 | | - |
211 | if (mhost == 0 && mip == 0)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
212 | return 0; never executed: return 0; | 0 |
213 | return 1; never executed: return 1; | 0 |
214 | } | - |
215 | | - |
216 | | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | int | - |
222 | match_user(const char *user, const char *host, const char *ipaddr, | - |
223 | const char *pattern) | - |
224 | { | - |
225 | char *p, *pat; | - |
226 | int ret; | - |
227 | | - |
228 | | - |
229 | if (user == NULL && host == NULL && ipaddr == NULL) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
230 | if ((p = strchr(pattern, '@')) != NULL &&TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
231 | match_host_and_ip(NULL, NULL, p + 1) < 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
232 | return -1; never executed: return -1; | 0 |
233 | return 0; never executed: return 0; | 0 |
234 | } | - |
235 | | - |
236 | if ((p = strchr(pattern,'@')) == NULL)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
237 | return match_pattern(user, pattern); never executed: return match_pattern(user, pattern); | 0 |
238 | | - |
239 | pat = xstrdup(pattern); | - |
240 | p = strchr(pat, '@');TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
241 | *p++ = '\0'; | - |
242 | | - |
243 | if ((ret = match_pattern(user, pat)) == 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
244 | ret = match_host_and_ip(host, ipaddr, p); never executed: ret = match_host_and_ip(host, ipaddr, p); | 0 |
245 | free(pat); | - |
246 | | - |
247 | return ret; never executed: return ret; | 0 |
248 | } | - |
249 | | - |
250 | | - |
251 | | - |
252 | | - |
253 | | - |
254 | #define MAX_PROP 40 | - |
255 | #define SEP "," | - |
256 | char * | - |
257 | match_list(const char *client, const char *server, u_int *next) | - |
258 | { | - |
259 | char *sproposals[MAX_PROP]; | - |
260 | char *c, *s, *p, *ret, *cp, *sp; | - |
261 | int i, j, nproposals; | - |
262 | | - |
263 | c = cp = xstrdup(client); | - |
264 | s = sp = xstrdup(server); | - |
265 | | - |
266 | for ((p = strsep(&sp, SEP)), i=0; p && *p != '\0';TRUE | evaluated 5920 times by 1 test | FALSE | evaluated 2080 times by 1 test |
TRUE | evaluated 5920 times by 1 test | FALSE | never evaluated |
| 0-5920 |
267 | (p = strsep(&sp, SEP)), i++) { | - |
268 | if (i < MAX_PROP)TRUE | evaluated 5920 times by 1 test | FALSE | never evaluated |
| 0-5920 |
269 | sproposals[i] = p;executed 5920 times by 1 test: sproposals[i] = p; | 5920 |
270 | else | - |
271 | break; never executed: break; | 0 |
272 | } | - |
273 | nproposals = i; | - |
274 | | - |
275 | for ((p = strsep(&cp, SEP)), i=0; p && *p != '\0';TRUE | evaluated 2080 times by 1 test | FALSE | evaluated 160 times by 1 test |
TRUE | evaluated 2080 times by 1 test | FALSE | never evaluated |
| 0-2080 |
276 | (p = strsep(&cp, SEP)), i++) { | - |
277 | for (j = 0; j < nproposals; j++) {TRUE | evaluated 2080 times by 1 test | FALSE | evaluated 160 times by 1 test |
| 160-2080 |
278 | if (strcmp(p, sproposals[j]) == 0) { never executed: __result = (((const unsigned char *) (const char *) ( p ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( sproposals[j] ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | evaluated 1920 times by 1 test | FALSE | evaluated 160 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-1920 |
279 | ret = xstrdup(p); | - |
280 | if (next != NULL)TRUE | never evaluated | FALSE | evaluated 1920 times by 1 test |
| 0-1920 |
281 | *next = (cp == NULL) ? never executed: *next = (cp == ((void *)0) ) ? strlen(c) : (u_int)(cp - c); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
282 | strlen(c) : (u_int)(cp - c); never executed: *next = (cp == ((void *)0) ) ? strlen(c) : (u_int)(cp - c); | 0 |
283 | free(c); | - |
284 | free(s); | - |
285 | return ret;executed 1920 times by 1 test: return ret; | 1920 |
286 | } | - |
287 | }executed 160 times by 1 test: end of block | 160 |
288 | }executed 160 times by 1 test: end of block | 160 |
289 | if (next != NULL)TRUE | never evaluated | FALSE | evaluated 160 times by 1 test |
| 0-160 |
290 | *next = strlen(c); never executed: *next = strlen(c); | 0 |
291 | free(c); | - |
292 | free(s); | - |
293 | return NULL;executed 160 times by 1 test: return ((void *)0) ; | 160 |
294 | } | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | | - |
303 | static char * | - |
304 | filter_list(const char *proposal, const char *filter, int blacklist) | - |
305 | { | - |
306 | size_t len = strlen(proposal) + 1; | - |
307 | char *fix_prop = malloc(len); | - |
308 | char *orig_prop = strdup(proposal); never executed: __retval = (char *) memcpy (__retval, proposal , __len); TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | evaluated 10 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
| 0-10 |
309 | char *cp, *tmp; | - |
310 | int r; | - |
311 | | - |
312 | if (fix_prop == NULL || orig_prop == NULL) {TRUE | never evaluated | FALSE | evaluated 10 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 10 times by 1 test |
| 0-10 |
313 | free(orig_prop); | - |
314 | free(fix_prop); | - |
315 | return NULL; never executed: return ((void *)0) ; | 0 |
316 | } | - |
317 | | - |
318 | tmp = orig_prop; | - |
319 | *fix_prop = '\0'; | - |
320 | while ((cp = strsep(&tmp, ",")) != NULL) {TRUE | evaluated 28 times by 1 test | FALSE | evaluated 10 times by 1 test |
| 10-28 |
321 | r = match_pattern_list(cp, filter, 0); | - |
322 | if ((blacklist && r != 1) || (!blacklist && r == 1)) {TRUE | evaluated 28 times by 1 test | FALSE | never evaluated |
TRUE | evaluated 14 times by 1 test | FALSE | evaluated 14 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 14 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
| 0-28 |
323 | if (*fix_prop != '\0')TRUE | evaluated 5 times by 1 test | FALSE | evaluated 9 times by 1 test |
| 5-9 |
324 | strlcat(fix_prop, ",", len);executed 5 times by 1 test: strlcat(fix_prop, ",", len); | 5 |
325 | strlcat(fix_prop, cp, len); | - |
326 | }executed 14 times by 1 test: end of block | 14 |
327 | }executed 28 times by 1 test: end of block | 28 |
328 | free(orig_prop); | - |
329 | return fix_prop;executed 10 times by 1 test: return fix_prop; | 10 |
330 | } | - |
331 | | - |
332 | | - |
333 | | - |
334 | | - |
335 | | - |
336 | char * | - |
337 | match_filter_blacklist(const char *proposal, const char *filter) | - |
338 | { | - |
339 | return filter_list(proposal, filter, 1);executed 10 times by 1 test: return filter_list(proposal, filter, 1); | 10 |
340 | } | - |
341 | | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | char * | - |
347 | match_filter_whitelist(const char *proposal, const char *filter) | - |
348 | { | - |
349 | return filter_list(proposal, filter, 0); never executed: return filter_list(proposal, filter, 0); | 0 |
350 | } | - |
| | |