View | Details | Raw Unified | Return to bug 23367 | Differences between
and this patch

Collapse All | Expand All

(-)debian/control (-1 / +1 lines)
 Lines 2-8    Link Here 
2
Section: univention
2
Section: univention
3
Maintainer: Univention GmbH <packages@univention.de>
3
Maintainer: Univention GmbH <packages@univention.de>
4
Standards-Version: 3.5.5
4
Standards-Version: 3.5.5
5
Build-Depends: debhelper (>>7), ucslint, libssl-dev, libldap2-dev, libdb4.8-dev, python2.6-dev, libunivention-debug-dev (>= 0.8), libunivention-config-dev, libunivention-policy-dev, univention-config-dev, libunivention-policy-dev
5
Build-Depends: debhelper (>>7), ucslint, libssl-dev, libldap2-dev, libdb3-dev, python2.6-dev, libunivention-debug-dev (>= 0.8), libunivention-config-dev, libunivention-policy-dev, univention-config-dev, libunivention-policy-dev
6
6
7
Package: univention-directory-listener
7
Package: univention-directory-listener
8
Architecture: any
8
Architecture: any
(-)debian/rules (-1 / +1 lines)
 Lines 50-56    Link Here 
50
	dh_installinit -a --no-start -r -u"defaults 50"
50
	dh_installinit -a --no-start -r -u"defaults 50"
51
51
52
override_dh_auto_build:
52
override_dh_auto_build:
53
	cd src; $(MAKE) clean; $(MAKE) DB_CFLAGS="-I/usr/include/db -DWITH_DB48" DB_LDADD="-ldb-4.8"; cd -
53
	cd src; $(MAKE) clean; $(MAKE) DB_CFLAGS="-I/usr/include/db3 -DWITH_DB3" DB_LDADD="-ldb3"; cd -
54
	dh_auto_build
54
	dh_auto_build
55
55
56
override_dh_auto_test:
56
override_dh_auto_test:
(-)src/notifier.c (-7 / +22 lines)
 Lines 100-114    Link Here 
100
int notifier_listen(univention_ldap_parameters_t *lp,
100
int notifier_listen(univention_ldap_parameters_t *lp,
101
		univention_krb5_parameters_t *kp,
101
		univention_krb5_parameters_t *kp,
102
		int write_transaction_file,
102
		int write_transaction_file,
103
		univention_ldap_parameters_t *lp_local, CacheMasterEntry master_entry)
103
		univention_ldap_parameters_t *lp_local)
104
{
104
{
105
	NotifierID	id;
106
107
#ifndef WITH_DB42
108
	/* we should only get here, if the cache has previously been
109
	   initialized; thus, *some* ID should've been stored in the
110
	   cache */
111
	cache_get_int("notifier_id", &id, -1);
112
	if ((long)id == -1) {
113
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get last transaction ID from cache; possibly, it hasn't been initialized yet");
114
		return 1;
115
	}
116
#endif
117
105
	for (;;) {
118
	for (;;) {
106
		NotifierEntry	entry;
119
		NotifierEntry	entry;
107
		int		msgid;
120
		int		msgid;
108
		time_t		timeout = DELAY_LDAP_CLOSE;
121
		time_t		timeout = DELAY_LDAP_CLOSE;
109
		int		rv;
122
		int		rv;
110
123
111
		if ((msgid = notifier_get_dn(NULL, master_entry.id+1)) < 1)
124
		if ((msgid = notifier_get_dn(NULL, id+1)) < 1)
112
			break;
125
			break;
113
126
114
		/* wait for data; on timeouts, do maintainance stuff
127
		/* wait for data; on timeouts, do maintainance stuff
 Lines 122-128    Link Here 
122
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get alive answer");
135
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get alive answer");
123
						return 1;
136
						return 1;
124
					}
137
					}
125
					notifier_resend_get_dn(NULL, msgid, master_entry.id+1);
138
					notifier_resend_get_dn(NULL, msgid, id+1);
126
				} else {
139
				} else {
127
					if (lp->ld != NULL) {
140
					if (lp->ld != NULL) {
128
						ldap_unbind_ext(lp->ld, NULL, NULL);
141
						ldap_unbind_ext(lp->ld, NULL, NULL);
 Lines 151-158    Link Here 
151
		}
164
		}
152
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "notifier returned = id: %ld\tdn: %s\tcmd: %c", entry.id, entry.dn, entry.command);
165
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "notifier returned = id: %ld\tdn: %s\tcmd: %c", entry.id, entry.dn, entry.command);
153
166
154
		if (entry.id != master_entry.id+1) {
167
		if (entry.id != id+1) {
155
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "notifier returned transaction id %ld (%ld expected)", entry.id, master_entry.id+1);
168
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "notifier returned transaction id %ld (%ld expected)", entry.id, id+1);
156
			notifier_entry_free(&entry);
169
			notifier_entry_free(&entry);
157
			return 1;
170
			return 1;
158
		}
171
		}
 Lines 191-198    Link Here 
191
			break;
204
			break;
192
		}
205
		}
193
206
194
		master_entry.id = entry.id;
207
		id = entry.id;
195
208
#ifndef WITH_DB42
209
		cache_set_int("notifier_id", id);
210
#endif
196
		notifier_entry_free(&entry);
211
		notifier_entry_free(&entry);
197
	}
212
	}
198
213
(-)src/notifier.h (-3 / +1 lines)
 Lines 39-50    Link Here 
39
#else
39
#else
40
typedef void univention_krb5_parameters_t;
40
typedef void univention_krb5_parameters_t;
41
#endif
41
#endif
42
#include "cache.h"
43
42
44
int	notifier_listen	(univention_ldap_parameters_t	*lp,
43
int	notifier_listen	(univention_ldap_parameters_t	*lp,
45
			 univention_krb5_parameters_t	*kp,
44
			 univention_krb5_parameters_t	*kp,
46
			 int				 write_transaction_file,
45
			 int				 write_transaction_file,
47
			 univention_ldap_parameters_t *lp_local,
46
			 univention_ldap_parameters_t *lp_local);
48
			 CacheMasterEntry master_entry);
49
47
50
#endif /* _NOTIFIER_H_ */
48
#endif /* _NOTIFIER_H_ */
(-)src/cache_entry.c (-2 / +2 lines)
 Lines 2-8    Link Here 
2
 * Univention Directory Listener
2
 * Univention Directory Listener
3
 *  entries in the cache
3
 *  entries in the cache
4
 *
4
 *
5
 * Copyright 2004-2011 Univention GmbH
5
 * Copyright 2004-2010 Univention GmbH
6
 *
6
 *
7
 * http://www.univention.de/
7
 * http://www.univention.de/
8
 *
8
 *
 Lines 78-84    Link Here 
78
{
78
{
79
	CacheEntryAttribute **attribute;
79
	CacheEntryAttribute **attribute;
80
	char **module;
80
	char **module;
81
	unsigned char **value;
81
	char **value;
82
	
82
	
83
	fprintf(fp, "dn: %s\n", dn);
83
	fprintf(fp, "dn: %s\n", dn);
84
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
84
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
(-)src/change.c (+16 lines)
 Lines 295-301    Link Here 
295
/* Make sure schema is up-to-date */
295
/* Make sure schema is up-to-date */
296
int change_update_schema(univention_ldap_parameters_t *lp)
296
int change_update_schema(univention_ldap_parameters_t *lp)
297
{
297
{
298
#ifdef WITH_DB42
298
	CacheMasterEntry	 master_entry;
299
	CacheMasterEntry	 master_entry;
300
#else
301
	NotifierID		 id = 0;
302
#endif
299
	NotifierID		 new_id = 0;
303
	NotifierID		 new_id = 0;
300
	LDAPMessage		*res,
304
	LDAPMessage		*res,
301
				*cur;
305
				*cur;
 Lines 316-332    Link Here 
316
	timeout.tv_sec = 300;
320
	timeout.tv_sec = 300;
317
	timeout.tv_usec = 0;
321
	timeout.tv_usec = 0;
318
322
323
#ifdef WITH_DB42
319
	if ((rv=cache_get_master_entry(&master_entry)) == DB_NOTFOUND) {
324
	if ((rv=cache_get_master_entry(&master_entry)) == DB_NOTFOUND) {
320
		master_entry.id = 0;
325
		master_entry.id = 0;
321
		master_entry.schema_id = 0;
326
		master_entry.schema_id = 0;
322
	 } else if (rv != 0)
327
	 } else if (rv != 0)
323
		return rv;
328
		return rv;
329
#else
330
	cache_get_schema_id("notifier_schema_id", &id, 0);
331
#endif
324
	if ((notifier_get_schema_id_s(NULL, &new_id)) != 0) {
332
	if ((notifier_get_schema_id_s(NULL, &new_id)) != 0) {
325
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get schema DN");
333
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get schema DN");
326
		return LDAP_OTHER;
334
		return LDAP_OTHER;
327
	}
335
	}
328
336
337
#ifdef WITH_DB42
329
	if (new_id > master_entry.schema_id) {
338
	if (new_id > master_entry.schema_id) {
339
#else
340
	if (new_id > id) {
341
#endif
330
		if ((rv=ldap_search_ext_s(lp->ld, "cn=Subschema", LDAP_SCOPE_BASE, "(objectClass=*)", attrs, 0, NULL /*serverctrls*/, NULL /*clientctrls*/, &timeout, 0 /*sizelimit*/, &res)) == LDAP_SUCCESS) {
342
		if ((rv=ldap_search_ext_s(lp->ld, "cn=Subschema", LDAP_SCOPE_BASE, "(objectClass=*)", attrs, 0, NULL /*serverctrls*/, NULL /*clientctrls*/, &timeout, 0 /*sizelimit*/, &res)) == LDAP_SUCCESS) {
331
			if ((cur=ldap_first_entry(lp->ld, res)) == NULL) {
343
			if ((cur=ldap_first_entry(lp->ld, res)) == NULL) {
332
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "got no entry for schema");
344
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "got no entry for schema");
 Lines 339-344    Link Here 
339
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not receive schema (%s)", ldap_err2string(rv));
351
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not receive schema (%s)", ldap_err2string(rv));
340
		}
352
		}
341
353
354
#ifndef WITH_DB42
355
		if (rv == 0)
356
			cache_set_schema_id("notifier_schema_id", new_id);
357
#endif
342
	}
358
	}
343
	
359
	
344
	return rv;
360
	return rv;
(-)src/Makefile (-2 / +2 lines)
 Lines 30-37    Link Here 
30
# <http://www.gnu.org/licenses/>.
30
# <http://www.gnu.org/licenses/>.
31
#
31
#
32
CC=gcc
32
CC=gcc
33
DB_LDADD=-ldb-4.8
33
DB_LDADD=-ldb3
34
DB_CFLAGS=-I/usr/include/db -DWITH_DB48
34
DB_CFLAGS=-I/usr/include/db3 -DWITH_DB3
35
DB_OBJS=cache.o cache_entry.o cache_lowlevel.o base64.o
35
DB_OBJS=cache.o cache_entry.o cache_lowlevel.o base64.o
36
36
37
CFLAGS=-g -Wall -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS)
37
CFLAGS=-g -Wall -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS)
(-)src/cache.c (-11 / +54 lines)
 Lines 88-100    Link Here 
88
88
89
DB *dbp;
89
DB *dbp;
90
DBC *dbc_cur = NULL;
90
DBC *dbc_cur = NULL;
91
#ifdef WITH_DB42
91
DB_ENV *dbenvp;
92
DB_ENV *dbenvp;
93
#endif
92
static FILE *lock_fp=NULL;
94
static FILE *lock_fp=NULL;
93
95
96
#ifdef WITH_DB42
94
static void cache_panic_call(DB_ENV *dbenvp, int errval)
97
static void cache_panic_call(DB_ENV *dbenvp, int errval)
95
{
98
{
96
	exit(1);
99
	exit(1);
97
}
100
}
101
#endif
98
102
99
char* _convert_to_lower(char *dn)
103
char* _convert_to_lower(char *dn)
100
{
104
{
 Lines 112-118    Link Here 
112
	return lower_dn;
116
	return lower_dn;
113
}
117
}
114
118
115
static void cache_error_message(const DB_ENV *dbenvp, const char *errpfx, const char *msg)
119
static void cache_error_message(const char *errpfx, char *msg)
116
{
120
{
117
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
121
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
118
			"database error: %s", msg);
122
			"database error: %s", msg);
 Lines 142-147    Link Here 
142
	}
146
	}
143
	lockf(fileno(lock_fp), F_LOCK, 0);
147
	lockf(fileno(lock_fp), F_LOCK, 0);
144
148
149
#ifdef WITH_DB42
145
	if ((rv = db_env_create(&dbenvp, 0)) != 0) {
150
	if ((rv = db_env_create(&dbenvp, 0)) != 0) {
146
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
151
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
147
				"creating database environment failed");
152
				"creating database environment failed");
 Lines 171-176    Link Here 
171
		// FIXME: free dbp
176
		// FIXME: free dbp
172
		return rv;
177
		return rv;
173
	}
178
	}
179
#else
180
	if ((rv = db_create(&dbp, NULL, 0)) != 0) {
181
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
182
				"creating database handle failed");
183
		return rv;
184
	}
185
	if ((rv = dbp->open(dbp, file, NULL, DB_BTREE, DB_CREATE, 0600)) != 0) {
186
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
187
				"opening database failed");
188
		dbp->err(dbp, rv, "open");
189
		// FIXME: free dbp
190
		return rv;
191
	}
192
	dbp->set_errcall(dbp, cache_error_message);
193
#endif
174
	return 0;
194
	return 0;
175
}
195
}
176
196
 Lines 229-234    Link Here 
229
	return fclose(fp);
249
	return fclose(fp);
230
}
250
}
231
251
252
#ifdef WITH_DB42
232
int cache_get_master_entry(CacheMasterEntry *master_entry)
253
int cache_get_master_entry(CacheMasterEntry *master_entry)
233
{
254
{
234
	DBT key, data;
255
	DBT key, data;
 Lines 277-285    Link Here 
277
	data.data=(void*)master_entry;
298
	data.data=(void*)master_entry;
278
	data.size=sizeof(CacheMasterEntry);
299
	data.size=sizeof(CacheMasterEntry);
279
300
301
#ifdef WITH_DB42
280
	if (dbtxnp == NULL)
302
	if (dbtxnp == NULL)
281
		flags = DB_AUTO_COMMIT;
303
		flags = DB_AUTO_COMMIT;
282
	else
304
	else
305
#endif
283
		flags = 0;
306
		flags = 0;
284
	
307
	
285
	if ((rv=dbp->put(dbp, dbtxnp, &key, &data, flags)) != 0) {
308
	if ((rv=dbp->put(dbp, dbtxnp, &key, &data, flags)) != 0) {
 Lines 295-303    Link Here 
295
318
296
	return 0;
319
	return 0;
297
}
320
}
321
#endif
298
322
299
DB_TXN* cache_new_transaction(NotifierID id, char *dn)
323
DB_TXN* cache_new_transaction(NotifierID id, char *dn)
300
{
324
{
325
#ifdef WITH_DB42
301
	DB_TXN			*dbtxnp;
326
	DB_TXN			*dbtxnp;
302
	CacheMasterEntry	 master_entry;
327
	CacheMasterEntry	 master_entry;
303
	NotifierID		*old_id;
328
	NotifierID		*old_id;
 Lines 315-344    Link Here 
315
		else
340
		else
316
			old_id = &master_entry.id;
341
			old_id = &master_entry.id;
317
342
318
		if (*old_id > id) {
343
		if (*old_id >= id) {
319
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "New ID (%ld) is lower than old ID (%ld): %s", id, *old_id, dn);
344
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
345
					"New ID (%ld) is not greater than old"
346
					" ID (%ld): %s", id, *old_id, dn);
320
			dbtxnp->abort(dbtxnp);
347
			dbtxnp->abort(dbtxnp);
321
			return NULL;
348
			return NULL;
322
		} else if ( *old_id < id ) {
349
		} else
323
			*old_id = id;
350
			*old_id = id;
324
325
			if (cache_update_master_entry(&master_entry, dbtxnp) != 0) {
326
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_transaction: cache_update_master_entry failed");
327
				dbtxnp->abort(dbtxnp);
328
				return NULL;
329
			}
330
		
351
		
352
		if (cache_update_master_entry(&master_entry, dbtxnp) != 0) {
353
			dbtxnp->abort(dbtxnp);
354
			return NULL;
331
		}
355
		}
332
	}
356
	}
333
357
334
	return dbtxnp;
358
	return dbtxnp;
359
#else
360
	return NULL;
361
#endif
335
}
362
}
336
363
337
364
338
/* XXX: The NotifierID is passed for future use. Once the journal is
365
/* XXX: The NotifierID is passed for future use. Once the journal is
339
   implemented, entries other than the most recent one can be returned.
366
   implemented, entries other than the most recent one can be returned.
340
   At the moment, the id parameters for cache_update_entry, and
367
   At the moment, the id parameters for cache_update_entry, and
341
   cache_delete_entry do nothing (at least if WITH_DB48 is undefined) */
368
   cache_delete_entry do nothing (at least if WITH_DB42 is undefined) */
342
inline int cache_update_entry(NotifierID id, char *dn, CacheEntry *entry)
369
inline int cache_update_entry(NotifierID id, char *dn, CacheEntry *entry)
343
{
370
{
344
	DBT key, data;
371
	DBT key, data;
 Lines 357-368    Link Here 
357
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "put %d bytes", data.size);
384
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "put %d bytes", data.size);
358
385
359
	signals_block();
386
	signals_block();
387
#ifdef WITH_DB42
360
	dbtxnp = cache_new_transaction(id, dn);
388
	dbtxnp = cache_new_transaction(id, dn);
361
	if (dbtxnp == NULL) {
389
	if (dbtxnp == NULL) {
362
		signals_unblock();
390
		signals_unblock();
363
		free(data.data);
391
		free(data.data);
364
		return 1;
392
		return 1;
365
	}
393
	}
394
#else
395
	dbtxnp = NULL;
396
#endif
366
397
367
	key.data=dn;
398
	key.data=dn;
368
	key.size=strlen(dn)+1;
399
	key.size=strlen(dn)+1;
 Lines 372-383    Link Here 
372
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
403
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
373
				"storing entry in database failed: %s", dn);
404
				"storing entry in database failed: %s", dn);
374
		dbp->err(dbp, rv, "put");
405
		dbp->err(dbp, rv, "put");
406
#ifdef WITH_DB42
375
		dbtxnp->abort(dbtxnp);
407
		dbtxnp->abort(dbtxnp);
408
#endif
376
		free(data.data);
409
		free(data.data);
377
		return rv;
410
		return rv;
378
	}
411
	}
379
412
413
#ifdef WITH_DB42
380
	dbtxnp->commit(dbtxnp, 0);
414
	dbtxnp->commit(dbtxnp, 0);
415
#endif
381
	if ( !INIT_ONLY ) {
416
	if ( !INIT_ONLY ) {
382
		dbp->sync(dbp, 0);
417
		dbp->sync(dbp, 0);
383
	}
418
	}
 Lines 411-421    Link Here 
411
	key.size=strlen(dn)+1;
446
	key.size=strlen(dn)+1;
412
447
413
	signals_block();
448
	signals_block();
449
#ifdef WITH_DB42
414
	dbtxnp = cache_new_transaction(id, dn);
450
	dbtxnp = cache_new_transaction(id, dn);
415
	if (dbtxnp == NULL) {
451
	if (dbtxnp == NULL) {
416
		signals_unblock();
452
		signals_unblock();
417
		return 1;
453
		return 1;
418
	}
454
	}
455
#else
456
	dbtxnp = NULL;
457
#endif
419
458
420
	if ((rv=dbp->del(dbp, dbtxnp, &key, 0)) != 0 && rv != DB_NOTFOUND) {
459
	if ((rv=dbp->del(dbp, dbtxnp, &key, 0)) != 0 && rv != DB_NOTFOUND) {
421
		signals_unblock();
460
		signals_unblock();
 Lines 424-430    Link Here 
424
		dbp->err(dbp, rv, "del");
463
		dbp->err(dbp, rv, "del");
425
	}
464
	}
426
465
466
#ifdef WITH_DB42
427
	dbtxnp->commit(dbtxnp, 0);
467
	dbtxnp->commit(dbtxnp, 0);
468
#endif
428
	if ( !INIT_ONLY ) {
469
	if ( !INIT_ONLY ) {
429
		dbp->sync(dbp, 0);
470
		dbp->sync(dbp, 0);
430
	}
471
	}
 Lines 622-631    Link Here 
622
	if ((rv = dbp->close(dbp, 0)) != 0) {
663
	if ((rv = dbp->close(dbp, 0)) != 0) {
623
		dbp->err(dbp, rv, "close");
664
		dbp->err(dbp, rv, "close");
624
	}
665
	}
666
#ifdef WITH_DB42
625
	if ((rv = dbenvp->close(dbenvp, 0)) != 0) {
667
	if ((rv = dbenvp->close(dbenvp, 0)) != 0) {
626
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
668
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
627
				"closing database environment failed");
669
				"closing database environment failed");
628
	}
670
	}
671
#endif
629
	if (lock_fp != NULL) {
672
	if (lock_fp != NULL) {
630
		int rc=lockf(fileno(lock_fp), F_ULOCK, 0);
673
		int rc=lockf(fileno(lock_fp), F_ULOCK, 0);
631
		if (rc == 0) {
674
		if (rc == 0) {
(-)src/dump.c (-1 / +24 lines)
 Lines 63-69    Link Here 
63
63
64
int main(int argc, char* argv[])
64
int main(int argc, char* argv[])
65
{
65
{
66
	int debugging = 0, broken_only = 0;
66
	int debugging = 0, broken_only = 0, id_only = 0;
67
	char *output_file = NULL;
67
	char *output_file = NULL;
68
	FILE *fp;
68
	FILE *fp;
69
	int rv;
69
	int rv;
 Lines 94-99    Link Here 
94
		case 'r':
94
		case 'r':
95
			broken_only=1;
95
			broken_only=1;
96
			break;
96
			break;
97
#ifdef WITH_DB42
98
		case 'i':
99
			id_only=1;
100
			break;
101
#endif
97
		default:
102
		default:
98
			usage();
103
			usage();
99
			exit(1);
104
			exit(1);
 Lines 127-133    Link Here 
127
	if (cache_init() != 0)
132
	if (cache_init() != 0)
128
		exit(1);
133
		exit(1);
129
134
135
#ifdef WITH_DB42
136
	if (id_only) {
137
138
		CacheMasterEntry master_entry;
139
		cache_get_master_entry(&master_entry);
140
141
		printf("%ld %ld\n", master_entry.id, master_entry.schema_id);
130
		
142
		
143
	} else {
144
145
	cache_print_entries("uid=b95152,cn=users,dc=olb,dc=de");
146
147
	exit(0);
148
#endif
149
		
131
	for (rv=cache_first_entry(&cur, &dn, &entry); rv != DB_NOTFOUND;
150
	for (rv=cache_first_entry(&cur, &dn, &entry); rv != DB_NOTFOUND;
132
			rv=cache_next_entry(&cur, &dn, &entry)) {
151
			rv=cache_next_entry(&cur, &dn, &entry)) {
133
		if ((rv == 0 && !broken_only) || (rv == -1 && broken_only)) {
152
		if ((rv == 0 && !broken_only) || (rv == -1 && broken_only)) {
 Lines 139-144    Link Here 
139
	}
158
	}
140
	cache_free_cursor(cur);
159
	cache_free_cursor(cur);
141
160
161
#ifdef WITH_DB42
162
	}
163
#endif
164
	
142
	cache_close();
165
	cache_close();
143
166
144
	return 0;
167
	return 0;
(-)src/cache.h (-6 / +9 lines)
 Lines 40-55    Link Here 
40
#include <stdbool.h>
40
#include <stdbool.h>
41
41
42
42
43
int	cache_init				(void);
43
#ifdef WITH_DB42
44
44
struct _CacheMasterEntry {
45
typedef struct _CacheMasterEntry {
46
	NotifierID id;
45
	NotifierID id;
47
	NotifierID schema_id;
46
	NotifierID schema_id;
48
} CacheMasterEntry;
47
} CacheMasterEntry;
48
#endif
49
49
50
int	cache_get_master_entry			(CacheMasterEntry *master_entry);
50
int	cache_init				(void);
51
int	cache_update_master_entry		(CacheMasterEntry *master_entry, DB_TXN *dptxnp);
51
#ifdef WITH_DB42
52
52
int	cache_get_master_entry			(CacheMasterEntry	 *master_entry);
53
int	cache_update_master_entry		(CacheMasterEntry	 *master_entry,
54
						 DB_TXN			 *dptxnp);
55
#endif
53
int	cache_update_entry			(NotifierID		  id,
56
int	cache_update_entry			(NotifierID		  id,
54
						 char			 *dn,
57
						 char			 *dn,
55
						 CacheEntry		 *entry);
58
						 CacheEntry		 *entry);
(-)src/main.c (-1 / +37 lines)
 Lines 178-183    Link Here 
178
178
179
static void convert_cookie(void)
179
static void convert_cookie(void)
180
{
180
{
181
#ifndef WITH_DB42
182
	char *f;
183
	struct stat stbuf;
184
185
	asprintf(&f, "%s/notifier_id", cache_dir);
186
	if (stat(f, &stbuf) != 0) {
187
		free(f);
188
		asprintf(&f, "%s/cookie", cache_dir);
189
		FILE *fp = fopen(f, "r");
190
		if (fp != NULL) {
191
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "converting cookie file");
192
			char buf[1024];
193
			int  i;
194
			fgets(buf, 1024, fp);
195
			fgets(buf, 1024, fp);
196
			i = atoi(buf);
197
			if (i > 0)
198
				cache_set_int("notifier_id", i);
199
			fclose(fp);
200
		}
201
	}
202
	free(f);
203
#else
181
	char *filename;
204
	char *filename;
182
	FILE *fp;
205
	FILE *fp;
183
	CacheMasterEntry master_entry;
206
	CacheMasterEntry master_entry;
 Lines 214-222    Link Here 
214
		fclose(fp);
237
		fclose(fp);
215
	} else
238
	} else
216
		master_entry.schema_id = 0;
239
		master_entry.schema_id = 0;
240
	free(filename);
217
241
218
	if ((rv=cache_update_master_entry(&master_entry, NULL)) != 0)
242
	if ((rv=cache_update_master_entry(&master_entry, NULL)) != 0)
219
		exit(1); /* XXX */
243
		exit(1); /* XXX */
244
#endif
220
}
245
}
221
246
222
void purge_cache(const char *cache_dir)
247
void purge_cache(const char *cache_dir)
 Lines 306-312    Link Here 
306
					 write_transaction_file = 0;
331
					 write_transaction_file = 0;
307
	int				 rv;
332
	int				 rv;
308
	NotifierID			 id = -1;
333
	NotifierID			 id = -1;
334
#ifndef WITH_DB42
335
	NotifierID			 old_id = -1;
336
#else
309
	CacheMasterEntry		 master_entry;
337
	CacheMasterEntry		 master_entry;
338
#endif
310
	struct stat			 stbuf;
339
	struct stat			 stbuf;
311
340
312
	if (stat("/var/lib/univention-directory-listener/bad_cache", &stbuf) == 0) {
341
	if (stat("/var/lib/univention-directory-listener/bad_cache", &stbuf) == 0) {
 Lines 538-543    Link Here 
538
	signals_unblock();
567
	signals_unblock();
539
568
540
	/* if no ID is set, assume the database has just been initialized */
569
	/* if no ID is set, assume the database has just been initialized */
570
#ifdef WITH_DB42
541
	if ((rv=cache_get_master_entry(&master_entry)) == DB_NOTFOUND) {
571
	if ((rv=cache_get_master_entry(&master_entry)) == DB_NOTFOUND) {
542
		master_entry.id = id;
572
		master_entry.id = id;
543
		if ((rv=cache_update_master_entry(&master_entry, NULL)) != 0)
573
		if ((rv=cache_update_master_entry(&master_entry, NULL)) != 0)
 Lines 545-553    Link Here 
545
	} else if (rv != 0)
575
	} else if (rv != 0)
546
		exit(1);
576
		exit(1);
547
	
577
	
578
#else
579
	cache_get_int("notifier_id", &old_id, -1);
580
	if ((long)old_id == -1) {
581
		cache_set_int("notifier_id", id);
582
	}
583
#endif
548
	
584
	
549
	if (!initialize_only) {
585
	if (!initialize_only) {
550
		rv=notifier_listen(lp, kp, write_transaction_file, lp_local, master_entry);
586
		rv=notifier_listen(lp, kp, write_transaction_file, lp_local);
551
	}
587
	}
552
588
553
	if (rv != 0)
589
	if (rv != 0)

Return to bug 23367