View | Details | Raw Unified | Return to bug 27329
Collapse All | Expand All

(-)a/branches/ucs-3.0/ucs/management/univention-directory-listener/debian/rules (-1 / +2 lines)
 Lines 32-37    Link Here 
32
32
33
override_dh_auto_clean:
33
override_dh_auto_clean:
34
	$(MAKE) -C src clean
34
	$(MAKE) -C src clean
35
	$(MAKE) -C tests clean
35
	dh_auto_clean
36
	dh_auto_clean
36
37
37
override_dh_auto_build:
38
override_dh_auto_build:
 Lines 56-62   override_dh_installinit: Link Here 
56
57
57
override_dh_auto_test:
58
override_dh_auto_test:
58
	ucslint
59
	ucslint
59
	dh_auto_test
60
	make -C tests
60
61
61
override_dh_strip:
62
override_dh_strip:
62
	dh_strip --dbg-package=univention-directory-listener-dbg
63
	dh_strip --dbg-package=univention-directory-listener-dbg
(-)a/branches/ucs-3.0/ucs/management/univention-directory-listener/tests/Makefile (+39 lines)
Line 0    Link Here 
1
#
2
# Univention Directory Listener
3
#  Makefile for testing the listener
4
#
5
# Copyright 2004-2012 Univention GmbH
6
#
7
# http://www.univention.de/
8
#
9
# All rights reserved.
10
#
11
# The source code of this program is made available
12
# under the terms of the GNU Affero General Public License version 3
13
# (GNU AGPL V3) as published by the Free Software Foundation.
14
#
15
# Binary versions of this program provided by Univention to you as
16
# well as other copyrighted, protected or trademarked materials like
17
# Logos, graphics, fonts, specific documentations and configurations,
18
# cryptographic keys etc. are subject to a license agreement between
19
# you and Univention and not subject to the GNU AGPL V3.
20
#
21
# In the case you use this program under the terms of the GNU AGPL V3,
22
# the program is provided in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU Affero General Public License for more details.
26
#
27
# You should have received a copy of the GNU Affero General Public
28
# License with the Debian GNU/Linux or Univention distribution in file
29
# /usr/share/common-licenses/AGPL-3; if not, see
30
# <http://www.gnu.org/licenses/>.
31
#
32
tests: test__filter__cache_entry_ldap_filter_match
33
	set -e ; for t in $^; do ./$$t ; done
34
35
test__filter__cache_entry_ldap_filter_match: test__filter__cache_entry_ldap_filter_match.o ../src/filter.o
36
37
include ../src/Makefile
38
39
CFLAGS := -g -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS) -I../src
(-)a/branches/ucs-3.0/ucs/management/univention-directory-listener/tests/test__filter__cache_entry_ldap_filter_match.c (-2 / +89 lines)
Line 0    Link Here 
0
- 
1
#include <stdlib.h>
1
--
2
#include <stdio.h>
3
#include <stdbool.h>
4
#include "filter.h"
5
6
static struct filter filter = {
7
	.base = "dc=bar,dc=baz",
8
	.scope = 2, // LDAP.SCOPE_SUBTREE
9
	.filter = "objectclass=*",
10
};
11
static struct filter *filters[2] = {
12
	&filter,
13
	NULL,
14
};
15
static CacheEntry entry = {
16
	.attributes = NULL,
17
	.attribute_count = 0,
18
	.modules = NULL,
19
	.module_count = 0,
20
};
21
22
static bool test_match_exact(void) {
23
	char dn[] = "dc=bar,dc=baz";
24
	int r = cache_entry_ldap_filter_match(filters, dn, &entry);
25
	return r == 1;
26
}
27
28
static bool test_match_one(void) {
29
	char dn[] = "dc=foo,dc=bar,dc=baz";
30
	int r = cache_entry_ldap_filter_match(filters, dn, &entry);
31
	return r == 1;
32
}
33
34
static bool test_match_other(void) {
35
	char dn[] = "dc=foo";
36
	int r = cache_entry_ldap_filter_match(filters, dn, &entry);
37
	return r == 0;
38
}
39
40
static bool test_match_sub(void) {
41
	char dn[] = "dc=bam,dc=foo,dc=bar,dc=baz";
42
	int r = cache_entry_ldap_filter_match(filters, dn, &entry);
43
	return r == 1;
44
}
45
46
static bool test_match_case(void) {
47
	char dn[] = "dc=foo,dc=bar,dc=BAZ";
48
	int r = cache_entry_ldap_filter_match(filters, dn, &entry);
49
	return r == 0;
50
}
51
52
static bool test_match_short(void) {
53
	char dn[] = "dc=baz";
54
	int r = cache_entry_ldap_filter_match(filters, dn, &entry);
55
	return r == 0;
56
}
57
58
static bool test_match_infix(void) {
59
	char dn[] = "dc=foo,dc=bar,dc=baz,dc=bam";
60
	int r = cache_entry_ldap_filter_match(filters, dn, &entry);
61
	return r == 0;
62
}
63
64
#define TEST(n) { .name = "test_" # n, .func = test_##n }
65
struct tests {
66
	const char *name;
67
	bool (*func)(void);
68
} tests[] = {
69
	TEST(match_exact),
70
	TEST(match_one),
71
	TEST(match_other),
72
	TEST(match_sub),
73
	TEST(match_case),
74
	TEST(match_short),
75
	TEST(match_infix),
76
};
77
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
78
79
int main(int argc, char *argv[]) {
80
	int i, failed = 0;
81
	for (i = 0; i < ARRAY_SIZE(tests); i++)
82
		if (tests[i].func()) {
83
			fprintf(stdout, "+%s\n", tests[i].name);
84
		} else {
85
			fprintf(stdout, "-%s\n", tests[i].name);
86
			failed++;
87
		}
88
	return failed;
89
}
2
.../univention-directory-listener/src/filter.c     |   36 +++++++++++---------
90
.../univention-directory-listener/src/filter.c     |   36 +++++++++++---------
3
1 files changed, 20 insertions(+), 16 deletions(-)
91
1 files changed, 20 insertions(+), 16 deletions(-)
(-)a/branches/ucs-3.0/ucs/management/univention-directory-listener/src/filter.c (-17 / +20 lines)
 Lines 169-198   static int __cache_entry_ldap_filter_match(char* filter, int first, int last, Ca Link Here 
169
int cache_entry_ldap_filter_match(struct filter **filter, char *dn, CacheEntry *entry)
169
int cache_entry_ldap_filter_match(struct filter **filter, char *dn, CacheEntry *entry)
170
{
170
{
171
	struct filter **f;
171
	struct filter **f;
172
	size_t dn_len = strlen(dn);
172
173
173
	for (f = filter; f != NULL && *f != NULL; f++) {
174
	for (f = filter; f != NULL && *f != NULL; f++) {
174
		int len = strlen((*f)->filter);
175
176
		/* check if base and scope match */
175
		/* check if base and scope match */
177
		if ((*f)->base != NULL && (*f)->base[0] != '\0') {
176
		if ((*f)->base != NULL && (*f)->base[0] != '\0') {
178
			char *p = strstr(dn, (*f)->base);
177
			size_t b_len = strlen((*f)->base);
179
		
178
			/* No match if required base is longer then tested dn */
180
			/* strstr only finds the first occurance of the needle in the
179
			if (b_len > dn_len)
181
			 * haystack; hence, we keep on looping thru the results while
182
			 * the result isn't at the end of the haystack */
183
			while (p != NULL && p+strlen(p) != (*f)->base+strlen((*f)->base)) {
184
				p = strstr(p+1, (*f)->base);
185
			}
186
			if (p == NULL) /* base doesn't match at all*/
187
				continue;
180
				continue;
188
181
			/* No match if testes dn does not end on required base */
189
			if ( /* scope doesn't match */
182
			if (strcmp(dn + dn_len - b_len, (*f)->base))
190
					((*f)->scope == LDAP_SCOPE_BASE && strchr(dn, ',') <= p) ||
191
					((*f)->scope == LDAP_SCOPE_ONELEVEL && strchr(dn, ',')+1 != p))
192
				continue;
183
				continue;
184
185
			switch ((*f)->scope) {
186
				case LDAP_SCOPE_BASE:
187
					/* skip if more levels exists. */
188
					if (strchr(dn, '.') <= dn + dn_len - b_len)
189
						continue;
190
					break;
191
				case LDAP_SCOPE_ONELEVEL:
192
					/* skip if more then one level */
193
					if (strchr(dn, '.') + 1 != dn + dn_len - b_len)
194
						continue;
195
					break;
196
			}
193
		}
197
		}
194
198
195
		
199
		int len = strlen((*f)->filter);
196
		if (__cache_entry_ldap_filter_match((*f)->filter, 0, len-1, entry))
200
		if (__cache_entry_ldap_filter_match((*f)->filter, 0, len-1, entry))
197
			return 1;
201
			return 1;
198
	}
202
	}
199
- 

Return to bug 27329