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

Collapse All | Expand All

(-)a/management/univention-directory-listener/src/cache.c (-59 / +56 lines)
 Lines 116-124   static void setup_cache_filter(void) { Link Here 
116
116
117
/*
117
/*
118
int mdb_message_func(const char *msg, void *ctx) {
118
int mdb_message_func(const char *msg, void *ctx) {
119
        univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO,
119
	LOG(INFO, "%s\n", msg);
120
                        "%s\n", msg);
120
	return MDB_SUCCESS;
121
        return MDB_SUCCESS;
122
}
121
}
123
*/
122
*/
124
123
 Lines 135-149   int cache_lock(void) { Link Here 
135
		abort();
134
		abort();
136
135
137
	if ((lock_fp = fopen(lock_file, "a+e")) == NULL) {
136
	if ((lock_fp = fopen(lock_file, "a+e")) == NULL) {
138
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Could not open lock file [%s]", lock_file);
137
		LOG(ERROR, "Could not open lock file [%s]", lock_file);
139
		exit(EXIT_FAILURE);
138
		exit(EXIT_FAILURE);
140
	}
139
	}
141
	fd = fileno(lock_fp);
140
	fd = fileno(lock_fp);
142
141
143
	if (lockf(fd, F_TLOCK, 0) != 0) {
142
	if (lockf(fd, F_TLOCK, 0) != 0) {
144
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Could not get lock for database [%s]; "
143
		LOG(ERROR, "Could not get lock for database [%s]; "
145
		                                                    "Is another listener processs running?\n",
144
		           "Is another listener processs running?\n",
146
		                 lock_file);
145
		    lock_file);
147
		exit(EXIT_FAILURE);
146
		exit(EXIT_FAILURE);
148
	}
147
	}
149
148
 Lines 167-185   static size_t determine_mapsize_from_ucr() { Link Here 
167
		free(mapsize_str);
166
		free(mapsize_str);
168
167
169
		if ((errno == ERANGE && (mapsize == LONG_MAX || mapsize == LONG_MIN)) || (errno != 0 && mapsize == 0)) {
168
		if ((errno == ERANGE && (mapsize == LONG_MAX || mapsize == LONG_MIN)) || (errno != 0 && mapsize == 0)) {
170
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_init: Error parsing value of UCR variable %s as number: %s", ucr_var_mapsize, strerror(errno));
169
			LOG(ERROR, "cache_init: Error parsing value of UCR variable %s as number: %s", ucr_var_mapsize, strerror(errno));
171
			exit(EXIT_FAILURE);
170
			exit(EXIT_FAILURE);
172
		}
171
		}
173
		if (endptr == mapsize_str) {
172
		if (endptr == mapsize_str) {
174
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_init: Value of UCR variable %s is not a number", ucr_var_mapsize);
173
			LOG(ERROR, "Value of UCR variable %s is not a number", ucr_var_mapsize);
175
			mapsize = default_mapsize;
174
			mapsize = default_mapsize;
176
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_init: using default mapsize: %zu", mapsize);
175
			LOG(ERROR, "using default mapsize: %zu", mapsize);
177
		} else {
176
		} else {
178
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "cache_init: using UCR defined mapsize: %zu", mapsize);
177
			LOG(INFO, "using UCR defined mapsize: %zu", mapsize);
179
		}
178
		}
180
	} else {
179
	} else {
181
		mapsize = default_mapsize;
180
		mapsize = default_mapsize;
182
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "cache_init: using default mapsize: %zu", mapsize);
181
		LOG(INFO, "using default mapsize: %zu", mapsize);
183
	}
182
	}
184
	return mapsize;
183
	return mapsize;
185
}
184
}
 Lines 191-197   int cache_init(char *cache_mdb_dir, int mdb_flags) { Link Here 
191
	size_t mapsize = determine_mapsize_from_ucr();
190
	size_t mapsize = determine_mapsize_from_ucr();
192
191
193
	if ((mdb_flags & MDB_RDONLY) != 0) {
192
	if ((mdb_flags & MDB_RDONLY) != 0) {
194
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "cache_init: MDB_RDONLY");
193
		LOG(INFO, "MDB_RDONLY");
195
		mdb_readonly = MDB_RDONLY;
194
		mdb_readonly = MDB_RDONLY;
196
	} else {
195
	} else {
197
		mdb_dbi_flags |= MDB_CREATE;
196
		mdb_dbi_flags |= MDB_CREATE;
 Lines 199-231   int cache_init(char *cache_mdb_dir, int mdb_flags) { Link Here 
199
198
200
	rv = mdb_env_create(&env);
199
	rv = mdb_env_create(&env);
201
	if (rv != MDB_SUCCESS) {
200
	if (rv != MDB_SUCCESS) {
202
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_init: creating environment handle failed");
201
		LOG(ERROR, "creating environment handle failed");
203
		ERROR_MDB(rv, "mdb_env_create");
202
		ERROR_MDB(rv, "mdb_env_create");
204
		return rv;
203
		return rv;
205
	}
204
	}
206
205
207
	rv = mdb_env_set_mapsize(env, mapsize);
206
	rv = mdb_env_set_mapsize(env, mapsize);
208
	if (rv != MDB_SUCCESS) {
207
	if (rv != MDB_SUCCESS) {
209
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_init: setting mdb mapsize failed");
208
		LOG(ERROR, "setting mdb mapsize failed");
210
		ERROR_MDB(rv, "mdb_env_set_mapsize");
209
		ERROR_MDB(rv, "mdb_env_set_mapsize");
211
		return rv;
210
		return rv;
212
	}
211
	}
213
212
214
	rv = mdb_env_set_maxdbs(env, 2);
213
	rv = mdb_env_set_maxdbs(env, 2);
215
	if (rv != MDB_SUCCESS) {
214
	if (rv != MDB_SUCCESS) {
216
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_init: setting mdb maxdbs failed");
215
		LOG(ERROR, "setting mdb maxdbs failed");
217
		ERROR_MDB(rv, "mdb_env_set_maxdbs");
216
		ERROR_MDB(rv, "mdb_env_set_maxdbs");
218
		return rv;
217
		return rv;
219
	}
218
	}
220
219
221
	rv = mdb_env_open(env, cache_mdb_dir, mdb_readonly, 0600);
220
	rv = mdb_env_open(env, cache_mdb_dir, mdb_readonly, 0600);
222
	if (rv != MDB_SUCCESS) {
221
	if (rv != MDB_SUCCESS) {
223
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_init: opening database failed");
222
		LOG(ERROR, "opening database failed");
224
		ERROR_MDB(rv, "mdb_env_open");
223
		ERROR_MDB(rv, "mdb_env_open");
225
		return rv;
224
		return rv;
226
	}
225
	}
227
226
228
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_init: Transaction begin");
227
	LOG(ALL, "Transaction begin");
229
228
230
	rv = mdb_txn_begin(env, NULL, mdb_readonly, &cache_init_txn);
229
	rv = mdb_txn_begin(env, NULL, mdb_readonly, &cache_init_txn);
231
	if (rv != MDB_SUCCESS) {
230
	if (rv != MDB_SUCCESS) {
 Lines 251-257   int cache_init(char *cache_mdb_dir, int mdb_flags) { Link Here 
251
		return rv;
250
		return rv;
252
	}
251
	}
253
252
254
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Transaction commit");
253
	LOG(ALL, "Transaction commit");
255
254
256
	rv = mdb_txn_commit(cache_init_txn);
255
	rv = mdb_txn_commit(cache_init_txn);
257
	if (rv != MDB_SUCCESS) {
256
	if (rv != MDB_SUCCESS) {
 Lines 271-277   int cache_set_schema_id(const NotifierID value) { Link Here 
271
	int rv, fd, len;
270
	int rv, fd, len;
272
	char file[PATH_MAX], buf[15];
271
	char file[PATH_MAX], buf[15];
273
272
274
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Set Schema ID to %ld", value);
273
	LOG(WARN, "Set Schema ID to %ld", value);
275
	len = snprintf(buf, sizeof buf, "%ld", value);
274
	len = snprintf(buf, sizeof buf, "%ld", value);
276
	if (len < 0 || len >= sizeof buf)
275
	if (len < 0 || len >= sizeof buf)
277
		return len;
276
		return len;
 Lines 357-363   int cache_get_master_entry(CacheMasterEntry *master_entry) { Link Here 
357
	key.mv_data = &MASTER_KEY;
356
	key.mv_data = &MASTER_KEY;
358
	key.mv_size = MASTER_KEY_SIZE;
357
	key.mv_size = MASTER_KEY_SIZE;
359
358
360
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_get_master_entry: Read Transaction begin");
359
	LOG(ALL, "Read Transaction begin");
361
360
362
	rv = mdb_txn_begin(env, NULL, MDB_RDONLY, &read_txn);
361
	rv = mdb_txn_begin(env, NULL, MDB_RDONLY, &read_txn);
363
	if (rv != MDB_SUCCESS) {
362
	if (rv != MDB_SUCCESS) {
 Lines 367-389   int cache_get_master_entry(CacheMasterEntry *master_entry) { Link Here 
367
366
368
	rv = mdb_get(read_txn, id2entry, &key, &data);
367
	rv = mdb_get(read_txn, id2entry, &key, &data);
369
	if (rv == MDB_NOTFOUND) {
368
	if (rv == MDB_NOTFOUND) {
370
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_get_master_entry: Read Transaction abort"
369
		LOG(ALL, "Read Transaction abort: %s",
371
		                                                  ": %s",
370
		    mdb_strerror(rv));
372
		                 mdb_strerror(rv));
373
		mdb_txn_abort(read_txn);
371
		mdb_txn_abort(read_txn);
374
		return rv;
372
		return rv;
375
	} else if (rv != MDB_SUCCESS) {
373
	} else if (rv != MDB_SUCCESS) {
376
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_get_master_entry: reading master entry from database failed");
374
		LOG(ERROR, "reading master entry from database failed");
377
		ERROR_MDB(rv, "mdb_get");
375
		ERROR_MDB(rv, "mdb_get");
378
		mdb_txn_abort(read_txn);
376
		mdb_txn_abort(read_txn);
379
		return rv;
377
		return rv;
380
	}
378
	}
381
379
382
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_get_master_entry: Read Transaction abort");
380
	LOG(ALL, "Read Transaction abort");
383
	mdb_txn_abort(read_txn);
381
	mdb_txn_abort(read_txn);
384
382
385
	if (data.mv_size != sizeof(CacheMasterEntry)) {
383
	if (data.mv_size != sizeof(CacheMasterEntry)) {
386
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_get_master_entry: master entry has unexpected length");
384
		LOG(ERROR, "master entry has unexpected length");
387
		return 1;
385
		return 1;
388
	}
386
	}
389
387
 Lines 406-426   int cache_update_master_entry(CacheMasterEntry *master_entry) { Link Here 
406
	data.mv_data = (void *)master_entry;
404
	data.mv_data = (void *)master_entry;
407
	data.mv_size = sizeof(CacheMasterEntry);
405
	data.mv_size = sizeof(CacheMasterEntry);
408
406
409
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_update_master_entry: Transaction begin");
407
	LOG(ALL, "Transaction begin");
410
	if ((rv = mdb_txn_begin(env, NULL, 0, &write_txn)) != MDB_SUCCESS) {
408
	if ((rv = mdb_txn_begin(env, NULL, 0, &write_txn)) != MDB_SUCCESS) {
411
		ERROR_MDB(rv, "mdb_txn_begin");
409
		ERROR_MDB(rv, "mdb_txn_begin");
412
		return rv;
410
		return rv;
413
	}
411
	}
414
	rv = mdb_put(write_txn, id2entry, &key, &data, 0);
412
	rv = mdb_put(write_txn, id2entry, &key, &data, 0);
415
	if (rv != MDB_SUCCESS) {
413
	if (rv != MDB_SUCCESS) {
416
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_update_master_entry: storing master entry in database failed");
414
		LOG(ERROR, "storing master entry in database failed");
417
		ERROR_MDB(rv, "mdb_put");
415
		ERROR_MDB(rv, "mdb_put");
418
		mdb_txn_abort(write_txn);
416
		mdb_txn_abort(write_txn);
419
		return rv;
417
		return rv;
420
	}
418
	}
421
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_update_master_entry: Transaction commit");
419
	LOG(ALL, "Transaction commit");
422
	if ((rv = mdb_txn_commit(write_txn)) != MDB_SUCCESS) {
420
	if ((rv = mdb_txn_commit(write_txn)) != MDB_SUCCESS) {
423
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_update_master_entry: storing master entry in database failed");
421
		LOG(ERROR, "storing master entry in database failed");
424
		ERROR_MDB(rv, "mdb_txn_commit");
422
		ERROR_MDB(rv, "mdb_txn_commit");
425
		return rv;
423
		return rv;
426
	}
424
	}
 Lines 443-449   static inline int cache_update_entry_in_transaction(NotifierID id, char *dn, Cac Link Here 
443
	rv = unparse_entry(&data.mv_data, &tmp_size, entry);
441
	rv = unparse_entry(&data.mv_data, &tmp_size, entry);
444
	data.mv_size = tmp_size;
442
	data.mv_size = tmp_size;
445
	if (rv != 0) {
443
	if (rv != 0) {
446
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_update_entry: unparsing entry failed");
444
		LOG(ERROR, "unparsing entry failed");
447
		return rv;
445
		return rv;
448
	}
446
	}
449
447
 Lines 460-470   static inline int cache_update_entry_in_transaction(NotifierID id, char *dn, Cac Link Here 
460
	write_txn = mdb_cursor_txn(*id2dn_cursor_pp);
458
	write_txn = mdb_cursor_txn(*id2dn_cursor_pp);
461
	rv = mdb_put(write_txn, id2entry, &key, &data, 0);
459
	rv = mdb_put(write_txn, id2entry, &key, &data, 0);
462
	if (rv != MDB_SUCCESS) {
460
	if (rv != MDB_SUCCESS) {
463
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_update_entry: storing entry in database failed: %s", dn);
461
		LOG(ERROR, "storing entry in database failed: %s", dn);
464
		ERROR_MDB(rv, "mdb_put");
462
		ERROR_MDB(rv, "mdb_put");
465
		goto out;
463
		goto out;
466
	}
464
	}
467
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "put %zu bytes for %s", data.mv_size, dn);
465
	LOG(ALL, "put %zu bytes for %s", data.mv_size, dn);
468
466
469
out:
467
out:
470
	signals_unblock();
468
	signals_unblock();
 Lines 478-484   inline int cache_update_entry(NotifierID id, char *dn, CacheEntry *entry) { Link Here 
478
	MDB_txn *write_txn;
476
	MDB_txn *write_txn;
479
	MDB_cursor *id2dn_write_cursor_p;
477
	MDB_cursor *id2dn_write_cursor_p;
480
478
481
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_update_entry: Transaction begin");
479
	LOG(ALL, "Transaction begin");
482
	rv = mdb_txn_begin(env, NULL, 0, &write_txn);
480
	rv = mdb_txn_begin(env, NULL, 0, &write_txn);
483
	if (rv != MDB_SUCCESS) {
481
	if (rv != MDB_SUCCESS) {
484
		ERROR_MDB(rv, "mdb_txn_begin");
482
		ERROR_MDB(rv, "mdb_txn_begin");
 Lines 496-510   inline int cache_update_entry(NotifierID id, char *dn, CacheEntry *entry) { Link Here 
496
	mdb_cursor_close(id2dn_write_cursor_p);
494
	mdb_cursor_close(id2dn_write_cursor_p);
497
495
498
	if (rv != MDB_SUCCESS) {
496
	if (rv != MDB_SUCCESS) {
499
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_update_entry: Transaction abort");
497
		LOG(ALL, "Transaction abort");
500
		mdb_txn_abort(write_txn);
498
		mdb_txn_abort(write_txn);
501
		return rv;
499
		return rv;
502
	}
500
	}
503
501
504
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_update_entry: Transaction commit");
502
	LOG(ALL, "Transaction commit");
505
	rv = mdb_txn_commit(write_txn);
503
	rv = mdb_txn_commit(write_txn);
506
	if (rv != MDB_SUCCESS) {
504
	if (rv != MDB_SUCCESS) {
507
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_update_entry: storing updated entry in database failed");
505
		LOG(ERROR, "storing updated entry in database failed");
508
		ERROR_MDB(rv, "mdb_txn_commit");
506
		ERROR_MDB(rv, "mdb_txn_commit");
509
		return rv;
507
		return rv;
510
	}
508
	}
 Lines 517-523   int cache_update_entry_lower(NotifierID id, char *dn, CacheEntry *entry) { Link Here 
517
	int rv = 0;
515
	int rv = 0;
518
516
519
	if (cache_filter.filter && cache_entry_ldap_filter_match(cache_filters, dn, entry)) {
517
	if (cache_filter.filter && cache_entry_ldap_filter_match(cache_filters, dn, entry)) {
520
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Not caching %s, filtered out.", dn);
518
		LOG(ALL, "Not caching %s, filtered out.", dn);
521
		return rv;
519
		return rv;
522
	}
520
	}
523
521
 Lines 548-554   static inline int cache_delete_entry_in_transaction(NotifierID id, char *dn, MDB Link Here 
548
	write_txn = mdb_cursor_txn(*id2dn_cursor_pp);
546
	write_txn = mdb_cursor_txn(*id2dn_cursor_pp);
549
	rv = mdb_del(write_txn, id2entry, &key, 0);
547
	rv = mdb_del(write_txn, id2entry, &key, 0);
550
	if (rv != MDB_SUCCESS && rv != MDB_NOTFOUND) {
548
	if (rv != MDB_SUCCESS && rv != MDB_NOTFOUND) {
551
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_delete_entry: removing from database failed: %s", dn);
549
		LOG(ERROR, "removing from database failed: %s", dn);
552
		ERROR_MDB(rv, "ERROR_MDB: mdb_del");
550
		ERROR_MDB(rv, "ERROR_MDB: mdb_del");
553
		signals_unblock();
551
		signals_unblock();
554
		return rv;
552
		return rv;
 Lines 570-576   int cache_delete_entry(NotifierID id, char *dn) { Link Here 
570
	MDB_txn *write_txn;
568
	MDB_txn *write_txn;
571
	MDB_cursor *id2dn_write_cursor_p;
569
	MDB_cursor *id2dn_write_cursor_p;
572
570
573
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_delete_entry: Transaction begin");
571
	LOG(ALL, "Transaction begin");
574
	rv = mdb_txn_begin(env, NULL, 0, &write_txn);
572
	rv = mdb_txn_begin(env, NULL, 0, &write_txn);
575
	if (rv != MDB_SUCCESS) {
573
	if (rv != MDB_SUCCESS) {
576
		ERROR_MDB(rv, "mdb_txn_begin");
574
		ERROR_MDB(rv, "mdb_txn_begin");
 Lines 588-602   int cache_delete_entry(NotifierID id, char *dn) { Link Here 
588
	mdb_cursor_close(id2dn_write_cursor_p);
586
	mdb_cursor_close(id2dn_write_cursor_p);
589
587
590
	if (rv != MDB_SUCCESS) {
588
	if (rv != MDB_SUCCESS) {
591
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_update_entry: Transaction abort");
589
		LOG(ALL, "Transaction abort");
592
		mdb_txn_abort(write_txn);
590
		mdb_txn_abort(write_txn);
593
		return rv;
591
		return rv;
594
	}
592
	}
595
593
596
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_delete_entry: Transaction commit");
594
	LOG(ALL, "Transaction commit");
597
	rv = mdb_txn_commit(write_txn);
595
	rv = mdb_txn_commit(write_txn);
598
	if (rv != MDB_SUCCESS) {
596
	if (rv != MDB_SUCCESS) {
599
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_delete_entry: storing entry removal from database failed");
597
		LOG(ERROR, "storing entry removal from database failed");
600
		ERROR_MDB(rv, "mdb_txn_commit");
598
		ERROR_MDB(rv, "mdb_txn_commit");
601
	}
599
	}
602
600
 Lines 643-649   int cache_get_entry(char *dn, CacheEntry *entry) { Link Here 
643
	memset(&data, 0, sizeof(MDB_val));
641
	memset(&data, 0, sizeof(MDB_val));
644
	memset(entry, 0, sizeof(CacheEntry));
642
	memset(entry, 0, sizeof(CacheEntry));
645
643
646
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_get_entry: Read Transaction begin");
644
	LOG(ALL, "Read Transaction begin");
647
645
648
	rv = mdb_txn_begin(env, NULL, MDB_RDONLY, &read_txn);
646
	rv = mdb_txn_begin(env, NULL, MDB_RDONLY, &read_txn);
649
	if (rv != MDB_SUCCESS) {
647
	if (rv != MDB_SUCCESS) {
 Lines 661-667   int cache_get_entry(char *dn, CacheEntry *entry) { Link Here 
661
	rv = dntree_get_id4dn(id2dn_read_cursor_p, dn, &dnid, false);
659
	rv = dntree_get_id4dn(id2dn_read_cursor_p, dn, &dnid, false);
662
	mdb_cursor_close(id2dn_read_cursor_p);
660
	mdb_cursor_close(id2dn_read_cursor_p);
663
	if (rv == MDB_NOTFOUND) {
661
	if (rv == MDB_NOTFOUND) {
664
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_get_entry: Read Transaction abort");
662
		LOG(ALL, "Read Transaction abort");
665
		mdb_txn_abort(read_txn);
663
		mdb_txn_abort(read_txn);
666
		return rv;
664
		return rv;
667
	}
665
	}
 Lines 673-688   int cache_get_entry(char *dn, CacheEntry *entry) { Link Here 
673
	rv = mdb_get(read_txn, id2entry, &key, &data);
671
	rv = mdb_get(read_txn, id2entry, &key, &data);
674
	// signals_unblock();
672
	// signals_unblock();
675
673
676
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_get_entry: Read Transaction abort");
674
	LOG(ALL, "Read Transaction abort");
677
	mdb_txn_abort(read_txn);
675
	mdb_txn_abort(read_txn);
678
676
679
	if (rv == MDB_SUCCESS) {
677
	if (rv == MDB_SUCCESS) {
680
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "got %zu bytes for %s", data.mv_size, dn);
678
		LOG(INFO, "got %zu bytes for %s", data.mv_size, dn);
681
	} else if (rv == MDB_NOTFOUND) {
679
	} else if (rv == MDB_NOTFOUND) {
682
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "cache_get_entry: no cache entry found for %s", dn);
680
		LOG(INFO, "no cache entry found for %s", dn);
683
		return rv;
681
		return rv;
684
	} else {
682
	} else {
685
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "reading %s from database failed", dn);
683
		LOG(ERROR, "reading %s from database failed", dn);
686
		ERROR_MDB(rv, "mdb_get");
684
		ERROR_MDB(rv, "mdb_get");
687
		return rv;
685
		return rv;
688
	}
686
	}
 Lines 690-696   int cache_get_entry(char *dn, CacheEntry *entry) { Link Here 
690
	assert(data.mv_size <= UINT32_MAX);
688
	assert(data.mv_size <= UINT32_MAX);
691
	rv = parse_entry(data.mv_data, data.mv_size, entry);
689
	rv = parse_entry(data.mv_data, data.mv_size, entry);
692
	if (rv != 0) {
690
	if (rv != 0) {
693
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_get_entry: parsing entry failed");
691
		LOG(ERROR, "parsing entry failed");
694
		exit(1);
692
		exit(1);
695
	}
693
	}
696
694
 Lines 722-728   int cache_first_entry(MDB_cursor **id2entry_read_cursor_pp, MDB_cursor **id2dn_r Link Here 
722
	MDB_txn *read_txn;
720
	MDB_txn *read_txn;
723
	int rv;
721
	int rv;
724
722
725
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_first_entry: Transaction begin");
723
	LOG(ALL, "Transaction begin");
726
724
727
	rv = mdb_txn_begin(env, NULL, mdb_readonly, &read_txn);
725
	rv = mdb_txn_begin(env, NULL, mdb_readonly, &read_txn);
728
	if (rv != MDB_SUCCESS) {
726
	if (rv != MDB_SUCCESS) {
 Lines 749-756   int cache_first_entry(MDB_cursor **id2entry_read_cursor_pp, MDB_cursor **id2dn_r Link Here 
749
	MDB_envinfo stat;
747
	MDB_envinfo stat;
750
	MDB_env *env = mdb_txn_env(read_txn);
748
	MDB_env *env = mdb_txn_env(read_txn);
751
	mdb_env_info(env, &stat);
749
	mdb_env_info(env, &stat);
752
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL,
750
	LOG(ALL, "LAST COMMITTED TXN: %zu", stat.me_last_txnid);
753
	        "LAST COMMITTED TXN: %zu", stat.me_last_txnid);
754
	*/
751
	*/
755
752
756
	return cache_next_entry(id2entry_read_cursor_pp, id2dn_read_cursor_pp, dn, entry);
753
	return cache_next_entry(id2entry_read_cursor_pp, id2dn_read_cursor_pp, dn, entry);
 Lines 779-790   int cache_next_entry(MDB_cursor **id2entry_read_cursor_pp, MDB_cursor **id2dn_re Link Here 
779
		return cache_next_entry(id2entry_read_cursor_pp, id2dn_read_cursor_pp, dn, entry);
776
		return cache_next_entry(id2entry_read_cursor_pp, id2dn_read_cursor_pp, dn, entry);
780
	}
777
	}
781
778
782
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "got %zu bytes", data.mv_size);
779
	LOG(ALL, "got %zu bytes", data.mv_size);
783
780
784
	assert(data.mv_size <= UINT32_MAX);
781
	assert(data.mv_size <= UINT32_MAX);
785
	rv = parse_entry(data.mv_data, (u_int32_t)data.mv_size, entry);
782
	rv = parse_entry(data.mv_data, (u_int32_t)data.mv_size, entry);
786
	if (rv != 0) {
783
	if (rv != 0) {
787
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_next_entry: parsing entry failed: %s", *dn);
784
		LOG(ERROR, "parsing entry failed: %s", *dn);
788
		printf("%zu\n", data.mv_size);
785
		printf("%zu\n", data.mv_size);
789
		return rv;
786
		return rv;
790
	}
787
	}
 Lines 797-803   int cache_next_entry(MDB_cursor **id2entry_read_cursor_pp, MDB_cursor **id2dn_re Link Here 
797
794
798
	rv = dntree_lookup_dn4id(*id2dn_read_cursor_pp, dnid, dn);
795
	rv = dntree_lookup_dn4id(*id2dn_read_cursor_pp, dnid, dn);
799
	if (rv != MDB_SUCCESS) {
796
	if (rv != MDB_SUCCESS) {
800
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_next_entry: DB corruption, DN entry for id %d not found", *(int *)key.mv_data);
797
		LOG(ERROR, "DB corruption, DN entry for id %d not found", *(int *)key.mv_data);
801
		ERROR_MDB(rv, "mdb_get");
798
		ERROR_MDB(rv, "mdb_get");
802
		return rv;
799
		return rv;
803
	}
800
	}
 Lines 813-822   int cache_free_cursor(MDB_cursor *id2entry_read_cursor_pp, MDB_cursor *id2dn_rea Link Here 
813
	mdb_cursor_close(id2entry_read_cursor_pp);
810
	mdb_cursor_close(id2entry_read_cursor_pp);
814
	mdb_cursor_close(id2dn_read_cursor_pp);
811
	mdb_cursor_close(id2dn_read_cursor_pp);
815
812
816
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "cache_free_cursor: Transaction commit");
813
	LOG(ALL, "Transaction commit");
817
	rv = mdb_txn_commit(read_txn);
814
	rv = mdb_txn_commit(read_txn);
818
	if (rv != MDB_SUCCESS) {
815
	if (rv != MDB_SUCCESS) {
819
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_free_cursor: Transation commit failed");
816
		LOG(ERROR, "Transation commit failed");
820
		ERROR_MDB(rv, "mdb_txn_commit");
817
		ERROR_MDB(rv, "mdb_txn_commit");
821
	}
818
	}
822
	return rv;
819
	return rv;
(-)a/management/univention-directory-listener/src/cache_bdb.c (-34 / +30 lines)
 Lines 71-77    Link Here 
71
#include <stdbool.h>
71
#include <stdbool.h>
72
#include <assert.h>
72
#include <assert.h>
73
73
74
#include <univention/debug.h>
75
#include <univention/config.h>
74
#include <univention/config.h>
76
75
77
#include "common.h"
76
#include "common.h"
 Lines 117-123   static void bdb_cache_panic_call(DB_ENV *dbenvp, int errval) { Link Here 
117
#endif
116
#endif
118
117
119
static void bdb_cache_error_message(const char *errpfx, char *msg) {
118
static void bdb_cache_error_message(const char *errpfx, char *msg) {
120
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "database error: %s", msg);
119
	LOG(ERROR, "database error: %s", msg);
121
}
120
}
122
121
123
int bdb_cache_lock(void) {
122
int bdb_cache_lock(void) {
 Lines 131-145   int bdb_cache_lock(void) { Link Here 
131
		abort();
130
		abort();
132
131
133
	if ((lock_fp = fopen(lock_file, "a+e")) == NULL) {
132
	if ((lock_fp = fopen(lock_file, "a+e")) == NULL) {
134
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Could not open lock file [%s]", lock_file);
133
		LOG(ERROR, "Could not open lock file [%s]", lock_file);
135
		exit(EXIT_FAILURE);
134
		exit(EXIT_FAILURE);
136
	}
135
	}
137
	fd = fileno(lock_fp);
136
	fd = fileno(lock_fp);
138
137
139
	if (lockf(fd, F_TLOCK, 0) != 0) {
138
	if (lockf(fd, F_TLOCK, 0) != 0) {
140
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Could not get lock for database [%s]; "
139
		LOG(ERROR, "Could not get lock for database [%s]; "
141
		                                                    "Is another listener processs running?\n",
140
		           "Is another listener processs running?\n",
142
		                 lock_file);
141
		    lock_file);
143
		exit(EXIT_FAILURE);
142
		exit(EXIT_FAILURE);
144
	}
143
	}
145
144
 Lines 154-160   int bdb_cache_init(void) { Link Here 
154
153
155
#ifdef WITH_DB42
154
#ifdef WITH_DB42
156
	if ((rv = db_env_create(&dbenvp, 0)) != 0) {
155
	if ((rv = db_env_create(&dbenvp, 0)) != 0) {
157
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "creating database environment failed");
156
		LOG(ERROR, "creating database environment failed");
158
		return rv;
157
		return rv;
159
	}
158
	}
160
	dbenvp->set_errcall(dbenvp, bdb_cache_error_message);
159
	dbenvp->set_errcall(dbenvp, bdb_cache_error_message);
 Lines 162-188   int bdb_cache_init(void) { Link Here 
162
	if ((rv = dbenvp->open(dbenvp, bdb_cache_dir, DB_CREATE | DB_INIT_MPOOL |
161
	if ((rv = dbenvp->open(dbenvp, bdb_cache_dir, DB_CREATE | DB_INIT_MPOOL |
163
	                                                  /*DB_INIT_LOCK | */ DB_INIT_LOG | DB_INIT_TXN | DB_RECOVER,
162
	                                                  /*DB_INIT_LOCK | */ DB_INIT_LOG | DB_INIT_TXN | DB_RECOVER,
164
	                       0600)) != 0) {
163
	                       0600)) != 0) {
165
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "opening database environment failed");
164
		LOG(ERROR, "opening database environment failed");
166
		dbenvp->err(dbenvp, rv, "%s", "environment");
165
		dbenvp->err(dbenvp, rv, "%s", "environment");
167
		return rv;
166
		return rv;
168
	}
167
	}
169
	if ((rv = db_create(&dbp, dbenvp, 0)) != 0) {
168
	if ((rv = db_create(&dbp, dbenvp, 0)) != 0) {
170
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "creating database handle failed");
169
		LOG(ERROR, "creating database handle failed");
171
		return rv;
170
		return rv;
172
	}
171
	}
173
	if ((rv = dbp->open(dbp, NULL, "cache.db", NULL, DB_BTREE, DB_CREATE | DB_CHKSUM | DB_AUTO_COMMIT, 0600)) != 0) {
172
	if ((rv = dbp->open(dbp, NULL, "cache.db", NULL, DB_BTREE, DB_CREATE | DB_CHKSUM | DB_AUTO_COMMIT, 0600)) != 0) {
174
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "opening database failed");
173
		LOG(ERROR, "opening database failed");
175
		dbp->err(dbp, rv, "open");
174
		dbp->err(dbp, rv, "open");
176
		// FIXME: free dbp
175
		// FIXME: free dbp
177
		return rv;
176
		return rv;
178
	}
177
	}
179
#else
178
#else
180
	if ((rv = db_create(&dbp, NULL, 0)) != 0) {
179
	if ((rv = db_create(&dbp, NULL, 0)) != 0) {
181
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "creating database handle failed");
180
		LOG(ERROR, "creating database handle failed");
182
		return rv;
181
		return rv;
183
	}
182
	}
184
	if ((rv = dbp->open(dbp, file, NULL, DB_BTREE, DB_CREATE, 0600)) != 0) {
183
	if ((rv = dbp->open(dbp, file, NULL, DB_BTREE, DB_CREATE, 0600)) != 0) {
185
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "opening database failed");
184
		LOG(ERROR, "opening database failed");
186
		dbp->err(dbp, rv, "open");
185
		dbp->err(dbp, rv, "open");
187
		// FIXME: free dbp
186
		// FIXME: free dbp
188
		return rv;
187
		return rv;
 Lines 203-209   int bdb_cache_set_schema_id(const NotifierID value) { Link Here 
203
	int rv, fd, len;
202
	int rv, fd, len;
204
	char file[PATH_MAX], buf[15];
203
	char file[PATH_MAX], buf[15];
205
204
206
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Set Schema ID to %ld", value);
205
	LOG(WARN, "Set Schema ID to %ld", value);
207
	len = snprintf(buf, sizeof buf, "%ld", value);
206
	len = snprintf(buf, sizeof buf, "%ld", value);
208
	if (len < 0 || len >= sizeof buf)
207
	if (len < 0 || len >= sizeof buf)
209
		return len;
208
		return len;
 Lines 292-304   int bdb_cache_get_master_entry(BdbCacheMasterEntry *master_entry) { Link Here 
292
	if ((rv = dbp->get(dbp, NULL, &key, &data, 0)) == DB_NOTFOUND)
291
	if ((rv = dbp->get(dbp, NULL, &key, &data, 0)) == DB_NOTFOUND)
293
		return rv;
292
		return rv;
294
	else if (rv != 0) {
293
	else if (rv != 0) {
295
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "reading master entry from database failed");
294
		LOG(ERROR, "reading master entry from database failed");
296
		dbp->err(dbp, rv, "get");
295
		dbp->err(dbp, rv, "get");
297
		return rv;
296
		return rv;
298
	}
297
	}
299
298
300
	if (data.size != sizeof(BdbCacheMasterEntry)) {
299
	if (data.size != sizeof(BdbCacheMasterEntry)) {
301
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "master entry has unexpected length");
300
		LOG(ERROR, "master entry has unexpected length");
302
		return 1;
301
		return 1;
303
	}
302
	}
304
303
 Lines 330-336   int bdb_cache_update_master_entry(BdbCacheMasterEntry *master_entry, DB_TXN *dbt Link Here 
330
		flags = 0;
329
		flags = 0;
331
330
332
	if ((rv = dbp->put(dbp, dbtxnp, &key, &data, flags)) != 0) {
331
	if ((rv = dbp->put(dbp, dbtxnp, &key, &data, flags)) != 0) {
333
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "storing master entry in database failed");
332
		LOG(ERROR, "storing master entry in database failed");
334
		dbp->err(dbp, rv, "put");
333
		dbp->err(dbp, rv, "put");
335
		return rv;
334
		return rv;
336
	}
335
	}
 Lines 360-368   DB_TXN *bdb_cache_new_transaction(NotifierID id, char *dn) { Link Here 
360
			old_id = &master_entry.id;
359
			old_id = &master_entry.id;
361
360
362
		if (*old_id >= id) {
361
		if (*old_id >= id) {
363
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "New ID (%ld) is not greater than old"
362
			LOG(ERROR, "New ID (%ld) is not greater than old"
364
			                                                    " ID (%ld): %s",
363
			           " ID (%ld): %s",
365
			                 id, *old_id, dn);
364
			    id, *old_id, dn);
366
			dbtxnp->abort(dbtxnp);
365
			dbtxnp->abort(dbtxnp);
367
			return NULL;
366
			return NULL;
368
		} else
367
		} else
 Lines 380-386   DB_TXN *bdb_cache_new_transaction(NotifierID id, char *dn) { Link Here 
380
#endif
379
#endif
381
}
380
}
382
381
383
384
/* XXX: The NotifierID is passed for future use. Once the journal is
382
/* XXX: The NotifierID is passed for future use. Once the journal is
385
   implemented, entries other than the most recent one can be returned.
383
   implemented, entries other than the most recent one can be returned.
386
   At the moment, the id parameters for bdb_cache_update_entry, and
384
   At the moment, the id parameters for bdb_cache_update_entry, and
 Lines 394-404   inline int bdb_cache_update_entry(NotifierID id, char *dn, CacheEntry *entry) { Link Here 
394
	memset(&data, 0, sizeof(DBT));
392
	memset(&data, 0, sizeof(DBT));
395
393
396
	if ((rv = unparse_entry(&data.data, &data.size, entry)) != 0) {
394
	if ((rv = unparse_entry(&data.data, &data.size, entry)) != 0) {
397
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "unparsing entry failed");
395
		LOG(ERROR, "unparsing entry failed");
398
		return rv;
396
		return rv;
399
	}
397
	}
400
398
401
402
	signals_block();
399
	signals_block();
403
#ifdef WITH_DB42
400
#ifdef WITH_DB42
404
	dbtxnp = bdb_cache_new_transaction(id, dn);
401
	dbtxnp = bdb_cache_new_transaction(id, dn);
 Lines 416-422   inline int bdb_cache_update_entry(NotifierID id, char *dn, CacheEntry *entry) { Link Here 
416
413
417
	if ((rv = dbp->put(dbp, dbtxnp, &key, &data, 0)) != 0) {
414
	if ((rv = dbp->put(dbp, dbtxnp, &key, &data, 0)) != 0) {
418
		signals_unblock();
415
		signals_unblock();
419
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "storing entry in database failed: %s", dn);
416
		LOG(ERROR, "storing entry in database failed: %s", dn);
420
		dbp->err(dbp, rv, "put");
417
		dbp->err(dbp, rv, "put");
421
#ifdef WITH_DB42
418
#ifdef WITH_DB42
422
		dbtxnp->abort(dbtxnp);
419
		dbtxnp->abort(dbtxnp);
 Lines 424-431   inline int bdb_cache_update_entry(NotifierID id, char *dn, CacheEntry *entry) { Link Here 
424
		free(data.data);
421
		free(data.data);
425
		return rv;
422
		return rv;
426
	}
423
	}
427
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "put %d bytes for %s", data.size, dn);
424
	LOG(ALL, "put %d bytes for %s", data.size, dn);
428
429
425
430
#ifdef WITH_DB42
426
#ifdef WITH_DB42
431
	dbtxnp->commit(dbtxnp, 0);
427
	dbtxnp->commit(dbtxnp, 0);
 Lines 442-448   int bdb_cache_update_entry_lower(NotifierID id, char *dn, CacheEntry *entry) { Link Here 
442
	int rv = 0;
438
	int rv = 0;
443
439
444
	if (cache_filter.filter && cache_entry_ldap_filter_match(cache_filters, dn, entry)) {
440
	if (cache_filter.filter && cache_entry_ldap_filter_match(cache_filters, dn, entry)) {
445
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Not caching %s, filtered out.", dn);
441
		LOG(ALL, "Not caching %s, filtered out.", dn);
446
		return rv;
442
		return rv;
447
	}
443
	}
448
444
 Lines 476-482   int bdb_cache_delete_entry(NotifierID id, char *dn) { Link Here 
476
472
477
	if ((rv = dbp->del(dbp, dbtxnp, &key, 0)) != 0 && rv != DB_NOTFOUND) {
473
	if ((rv = dbp->del(dbp, dbtxnp, &key, 0)) != 0 && rv != DB_NOTFOUND) {
478
		signals_unblock();
474
		signals_unblock();
479
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "removing from database failed: %s", dn);
475
		LOG(ERROR, "removing from database failed: %s", dn);
480
		dbp->err(dbp, rv, "del");
476
		dbp->err(dbp, rv, "del");
481
	}
477
	}
482
478
 Lines 535-552   int bdb_cache_get_entry(char *dn, CacheEntry *entry) { Link Here 
535
	signals_unblock();
531
	signals_unblock();
536
532
537
	if (rv != 0 && rv != DB_NOTFOUND) {
533
	if (rv != 0 && rv != DB_NOTFOUND) {
538
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "reading %s from database failed", dn);
534
		LOG(ERROR, "reading %s from database failed", dn);
539
		dbp->err(dbp, rv, "get");
535
		dbp->err(dbp, rv, "get");
540
		return rv;
536
		return rv;
541
	} else if (rv == DB_NOTFOUND) {
537
	} else if (rv == DB_NOTFOUND) {
542
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "no cache entry found for %s", dn);
538
		LOG(ALL, "no cache entry found for %s", dn);
543
		return rv;
539
		return rv;
544
	}
540
	}
545
541
546
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "got %d bytes for %s", data.size, dn);
542
	LOG(ALL, "got %d bytes for %s", data.size, dn);
547
543
548
	if ((rv = parse_entry(data.data, data.size, entry)) != 0) {
544
	if ((rv = parse_entry(data.data, data.size, entry)) != 0) {
549
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "parsing entry failed");
545
		LOG(ERROR, "parsing entry failed");
550
		free(data.data);
546
		free(data.data);
551
		exit(1);
547
		exit(1);
552
	}
548
	}
 Lines 636-645   int bdb_cache_next_entry(DBC **cur, char **dn, CacheEntry *entry) { Link Here 
636
		free(*dn);
632
		free(*dn);
637
	*dn = strdup(key.data);
633
	*dn = strdup(key.data);
638
634
639
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "got %d bytes", data.size);
635
	LOG(ALL, "got %d bytes", data.size);
640
636
641
	if ((rv = parse_entry(data.data, data.size, entry)) != 0) {
637
	if ((rv = parse_entry(data.data, data.size, entry)) != 0) {
642
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "parsing entry failed: %s", *dn);
638
		LOG(ERROR, "parsing entry failed: %s", *dn);
643
		printf("%d\n", data.size);
639
		printf("%d\n", data.size);
644
		free(key.data);
640
		free(key.data);
645
		free(data.data);
641
		free(data.data);
 Lines 665-671   int bdb_cache_close(void) { Link Here 
665
	dbp = NULL;
661
	dbp = NULL;
666
#ifdef WITH_DB42
662
#ifdef WITH_DB42
667
	if ((rv = dbenvp->close(dbenvp, 0)) != 0) {
663
	if ((rv = dbenvp->close(dbenvp, 0)) != 0) {
668
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "closing database environment failed");
664
		LOG(ERROR, "closing database environment failed");
669
	}
665
	}
670
#endif
666
#endif
671
	if (lock_fp != NULL) {
667
	if (lock_fp != NULL) {
(-)a/management/univention-directory-listener/src/cache_dn.c (-33 / +30 lines)
 Lines 47-54    Link Here 
47
#include <sys/stat.h>
47
#include <sys/stat.h>
48
#include <unistd.h>
48
#include <unistd.h>
49
#include <assert.h>
49
#include <assert.h>
50
50
#include "cache_dn.h"
51
#include "cache_dn.h"
51
#include <univention/debug.h>
52
#include "common.h"
52
53
53
static int mdb_dupsort(const MDB_val *a, const MDB_val *b) {
54
static int mdb_dupsort(const MDB_val *a, const MDB_val *b) {
54
	int diff;
55
	int diff;
 Lines 92-98   static int dntree_lookup_id4ldapdn(MDB_cursor *cur, LDAPDN dn, DNID *dnid_out, i Link Here 
92
	for (iRDN--; iRDN >= 0; iRDN--) {
93
	for (iRDN--; iRDN >= 0; iRDN--) {
93
		rv = ldap_rdn2str(dn[iRDN], &rdn, LDAP_DN_FORMAT_LDAPV3);
94
		rv = ldap_rdn2str(dn[iRDN], &rdn, LDAP_DN_FORMAT_LDAPV3);
94
		if (rv != LDAP_SUCCESS) {
95
		if (rv != LDAP_SUCCESS) {
95
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: ldap_rdn2str failed: %s (%d)", __func__, ldap_err2string(rv), rv);
96
			LOG(ERROR, "ldap_rdn2str failed: %s (%d)", ldap_err2string(rv), rv);
96
			return rv;
97
			return rv;
97
		}
98
		}
98
99
 Lines 102-108   static int dntree_lookup_id4ldapdn(MDB_cursor *cur, LDAPDN dn, DNID *dnid_out, i Link Here 
102
		data.mv_size = sizeof(subDN) + strlen(rdn);
103
		data.mv_size = sizeof(subDN) + strlen(rdn);
103
		subdn = calloc(1, data.mv_size);
104
		subdn = calloc(1, data.mv_size);
104
		if (subdn == NULL) {
105
		if (subdn == NULL) {
105
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: calloc failed", __func__);
106
			LOG(ERROR, "calloc failed");
106
			ldap_memfree(rdn);
107
			ldap_memfree(rdn);
107
			abort();
108
			abort();
108
		}
109
		}
 Lines 118-124   static int dntree_lookup_id4ldapdn(MDB_cursor *cur, LDAPDN dn, DNID *dnid_out, i Link Here 
118
			break;
119
			break;
119
		}
120
		}
120
		if (rv != MDB_SUCCESS) {
121
		if (rv != MDB_SUCCESS) {
121
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_get failed: %s (%d)", __func__, ldap_err2string(rv), rv);
122
			LOG(ERROR, "mdb_cursor_get failed: %s (%d)", ldap_err2string(rv), rv);
122
			return rv;
123
			return rv;
123
		};
124
		};
124
125
 Lines 128-136   static int dntree_lookup_id4ldapdn(MDB_cursor *cur, LDAPDN dn, DNID *dnid_out, i Link Here 
128
	}
129
	}
129
130
130
	if (rv == MDB_SUCCESS) {
131
	if (rv == MDB_SUCCESS) {
131
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "%s: found id=%lu", __func__, id);
132
		LOG(INFO, "found id=%lu", id);
132
	} else if (rv != MDB_NOTFOUND) {
133
	} else if (rv != MDB_NOTFOUND) {
133
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: failed: %s (%d)", __func__, mdb_strerror(rv), rv);
134
		LOG(ERROR, "failed: %s (%d)", mdb_strerror(rv), rv);
134
	}
135
	}
135
136
136
	*dnid_out = id;
137
	*dnid_out = id;
 Lines 158-171   int dntree_lookup_dn4id(MDB_cursor *cur, DNID dnid, char **dn) { Link Here 
158
	data.mv_size = 0;
159
	data.mv_size = 0;
159
160
160
	if (rv != MDB_SUCCESS) {
161
	if (rv != MDB_SUCCESS) {
161
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_get (MDB_GET_BOTH): %s (%d)", __func__, mdb_strerror(rv), rv);
162
		LOG(ERROR, "mdb_cursor_get (MDB_GET_BOTH): %s (%d)", mdb_strerror(rv), rv);
162
		return rv;
163
		return rv;
163
	};
164
	};
164
165
165
	// Workaround for (ITS#8393) LMDB - MDB_GET_BOTH broken on non-dup value
166
	// Workaround for (ITS#8393) LMDB - MDB_GET_BOTH broken on non-dup value
166
	rv = mdb_cursor_get(cur, &key, &data, MDB_GET_CURRENT);
167
	rv = mdb_cursor_get(cur, &key, &data, MDB_GET_CURRENT);
167
	if (rv != MDB_SUCCESS) {
168
	if (rv != MDB_SUCCESS) {
168
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_get: %s (%d)", __func__, mdb_strerror(rv), rv);
169
		LOG(ERROR, "mdb_cursor_get: %s (%d)", mdb_strerror(rv), rv);
169
		return rv;
170
		return rv;
170
	};
171
	};
171
172
 Lines 177-185   int dntree_lookup_dn4id(MDB_cursor *cur, DNID dnid, char **dn) { Link Here 
177
	dbi = mdb_cursor_dbi(cur);
178
	dbi = mdb_cursor_dbi(cur);
178
	rv = mdb_get(txn, dbi, &key, &data);
179
	rv = mdb_get(txn, dbi, &key, &data);
179
	if (rv != MDB_SUCCESS) {
180
	if (rv != MDB_SUCCESS) {
180
	        univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR,
181
	        LOG(ERROR, "mdb_get: %s (%d)", mdb_strerror(rv), rv);
181
	                "%s: mdb_get: %s (%d)",
182
	                __func__, mdb_strerror(rv), rv);
183
	        return rv;
182
	        return rv;
184
	};
183
	};
185
	*/
184
	*/
 Lines 188-194   int dntree_lookup_dn4id(MDB_cursor *cur, DNID dnid, char **dn) { Link Here 
188
187
189
	*dn = strdup(subdn->data);
188
	*dn = strdup(subdn->data);
190
	if (*dn == NULL) {
189
	if (*dn == NULL) {
191
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: strdup failed", __func__);
190
		LOG(ERROR, "strdup failed");
192
		abort();
191
		abort();
193
	}
192
	}
194
193
 Lines 207-213   static int next_free_dnid(MDB_cursor *cur, DNID *dnid_out) { Link Here 
207
		*dnid_out = 1;
206
		*dnid_out = 1;
208
		return MDB_SUCCESS;
207
		return MDB_SUCCESS;
209
	} else {
208
	} else {
210
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_get: %s (%d)", __func__, mdb_strerror(rv), rv);
209
		LOG(ERROR, "mdb_cursor_get: %s (%d)", mdb_strerror(rv), rv);
211
		return rv;
210
		return rv;
212
	}
211
	}
213
}
212
}
 Lines 228-250   static int dntree_add_id(MDB_cursor *write_cursor_p, DNID child, LDAPDN dn, DNID Link Here 
228
227
229
	rv = ldap_dn2str(dn, &dn_str, LDAP_DN_FORMAT_LDAPV3);
228
	rv = ldap_dn2str(dn, &dn_str, LDAP_DN_FORMAT_LDAPV3);
230
	if (rv != LDAP_SUCCESS) {
229
	if (rv != LDAP_SUCCESS) {
231
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: ldap_dn2str failed: %s (%d)", __func__, ldap_err2string(rv), rv);
230
		LOG(ERROR, "ldap_dn2str failed: %s (%d)", ldap_err2string(rv), rv);
232
		return rv;
231
		return rv;
233
	}
232
	}
234
233
235
	rv = ldap_rdn2str(dn[0], &rdn_str, LDAP_DN_FORMAT_LDAPV3);
234
	rv = ldap_rdn2str(dn[0], &rdn_str, LDAP_DN_FORMAT_LDAPV3);
236
	if (rv != LDAP_SUCCESS) {
235
	if (rv != LDAP_SUCCESS) {
237
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: ldap_rdn2str failed: %s (%d)", __func__, ldap_err2string(rv), rv);
236
		LOG(ERROR, "ldap_rdn2str failed: %s (%d)", ldap_err2string(rv), rv);
238
		ldap_memfree(dn_str);
237
		ldap_memfree(dn_str);
239
		return rv;
238
		return rv;
240
	}
239
	}
241
240
242
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "%s: child=%lu, parent=%lu: \"%s\"", __func__, child, parent, rdn_str);
241
	LOG(INFO, "child=%lu, parent=%lu: \"%s\"", child, parent, rdn_str);
243
242
244
	dn_len = strlen(dn_str);
243
	dn_len = strlen(dn_str);
245
	subdn = calloc(1, sizeof(subDN) + dn_len);
244
	subdn = calloc(1, sizeof(subDN) + dn_len);
246
	if (subdn == NULL) {
245
	if (subdn == NULL) {
247
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: calloc failed", __func__);
246
		LOG(ERROR, "calloc failed");
248
		ldap_memfree(dn_str);
247
		ldap_memfree(dn_str);
249
		ldap_memfree(rdn_str);
248
		ldap_memfree(rdn_str);
250
		abort();
249
		abort();
 Lines 272-281   static int dntree_add_id(MDB_cursor *write_cursor_p, DNID child, LDAPDN dn, DNID Link Here 
272
271
273
		rv = mdb_cursor_put(write_cursor_p, &key, &data, MDB_NODUPDATA);
272
		rv = mdb_cursor_put(write_cursor_p, &key, &data, MDB_NODUPDATA);
274
		if (rv != MDB_SUCCESS) {
273
		if (rv != MDB_SUCCESS) {
275
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_put failed for child %lu: %s (%d)", __func__, id, mdb_strerror(rv), rv);
274
			LOG(ERROR, "mdb_cursor_put failed for child %lu: %s (%d)", id, mdb_strerror(rv), rv);
276
		}
275
		}
277
	} else {
276
	} else {
278
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_put failed for parent %lu: %s (%d)", __func__, id, mdb_strerror(rv), rv);
277
		LOG(ERROR, "mdb_cursor_put failed for parent %lu: %s (%d)", id, mdb_strerror(rv), rv);
279
	}
278
	}
280
	ldap_memfree(dn_str);
279
	ldap_memfree(dn_str);
281
	free(subdn);
280
	free(subdn);
 Lines 314-331   int dntree_del_id(MDB_cursor *write_cursor_p, DNID dnid) { Link Here 
314
	dbi = mdb_cursor_dbi(write_cursor_p);
313
	dbi = mdb_cursor_dbi(write_cursor_p);
315
	rv = mdb_cursor_open(txn, dbi, &local_read_cursor_p);
314
	rv = mdb_cursor_open(txn, dbi, &local_read_cursor_p);
316
	if (rv != MDB_SUCCESS) {
315
	if (rv != MDB_SUCCESS) {
317
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_open: %s (%d)", __func__, ldap_err2string(rv), rv);
316
		LOG(ERROR, "mdb_cursor_open: %s (%d)", ldap_err2string(rv), rv);
318
		return rv;
317
		return rv;
319
	}
318
	}
320
319
321
	rv = dntree_has_children(local_read_cursor_p, dnid);
320
	rv = dntree_has_children(local_read_cursor_p, dnid);
322
	if (rv == MDB_SUCCESS) {
321
	if (rv == MDB_SUCCESS) {
323
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: delete failed:"
322
		LOG(ERROR, "delete failed: subordinate objects must be deleted first");
324
		                                                    " subordinate objects must be deleted first",
325
		                 __func__);
326
		return -1;
323
		return -1;
327
	} else if (rv != MDB_NOTFOUND) {
324
	} else if (rv != MDB_NOTFOUND) {
328
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: dntree_has_children failed: %s (%d)", __func__, mdb_strerror(rv), rv);
325
		LOG(ERROR, "dntree_has_children failed: %s (%d)", mdb_strerror(rv), rv);
329
		return -1;
326
		return -1;
330
	}
327
	}
331
	mdb_cursor_close(local_read_cursor_p);
328
	mdb_cursor_close(local_read_cursor_p);
 Lines 362-368   static int dntree_get_id4ldapdn(MDB_cursor *write_cursor_p, LDAPDN dn, DNID *dni Link Here 
362
		if (num_rdns(pdn) != found) {
359
		if (num_rdns(pdn) != found) {
363
			rv = dntree_get_id4ldapdn(write_cursor_p, pdn, &parent);
360
			rv = dntree_get_id4ldapdn(write_cursor_p, pdn, &parent);
364
			if (rv != MDB_SUCCESS) {
361
			if (rv != MDB_SUCCESS) {
365
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: failed: %s (%d)", __func__, mdb_strerror(rv), rv);
362
				LOG(ERROR, "failed: %s (%d)", mdb_strerror(rv), rv);
366
				return rv;
363
				return rv;
367
			}
364
			}
368
		} else {
365
		} else {
 Lines 386-410   int dntree_get_id4dn(MDB_cursor *id2dn_cursor_p, char *dn, DNID *dnid, bool crea Link Here 
386
383
387
	rv = ldap_str2dn(dn, &ldapdn, LDAP_DN_FORMAT_LDAP);
384
	rv = ldap_str2dn(dn, &ldapdn, LDAP_DN_FORMAT_LDAP);
388
	if (rv != LDAP_SUCCESS) {
385
	if (rv != LDAP_SUCCESS) {
389
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: ldap_str2dn failed: %s (%d)", __func__, ldap_err2string(rv), rv);
386
		LOG(ERROR, "ldap_str2dn failed: %s (%d)", ldap_err2string(rv), rv);
390
		return rv;
387
		return rv;
391
	}
388
	}
392
389
393
	if (ldapdn == NULL) {
390
	if (ldapdn == NULL) {
394
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: ldap_str2dn NULL: %s (%d): %s", __func__, ldap_err2string(rv), rv, dn);
391
		LOG(ERROR, "ldap_str2dn NULL: %s (%d): %s", ldap_err2string(rv), rv, dn);
395
		return 1;
392
		return 1;
396
	}
393
	}
397
394
398
	if (create == true) {
395
	if (create == true) {
399
		rv = dntree_get_id4ldapdn(id2dn_cursor_p, ldapdn, dnid);
396
		rv = dntree_get_id4ldapdn(id2dn_cursor_p, ldapdn, dnid);
400
		if (rv != MDB_SUCCESS) {
397
		if (rv != MDB_SUCCESS) {
401
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: failed for: %s", __func__, dn);
398
			LOG(ERROR, "failed for: %s", dn);
402
		}
399
		}
403
400
404
	} else {
401
	} else {
405
		rv = dntree_lookup_id4ldapdn(id2dn_cursor_p, ldapdn, dnid, NULL);
402
		rv = dntree_lookup_id4ldapdn(id2dn_cursor_p, ldapdn, dnid, NULL);
406
		if (rv == MDB_NOTFOUND) {
403
		if (rv == MDB_NOTFOUND) {
407
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "%s: DN %s not in id2dn", __func__, dn);
404
			LOG(INFO, "DN %s not in id2dn", dn);
408
		}
405
		}
409
	}
406
	}
410
407
 Lines 421-439   int dntree_init(MDB_dbi *dbi_p, MDB_txn *cache_init_txn_p, int mdb_flags) { Link Here 
421
	bool readonly = (mdb_flags & MDB_RDONLY) != 0;
418
	bool readonly = (mdb_flags & MDB_RDONLY) != 0;
422
419
423
	if (readonly) {
420
	if (readonly) {
424
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "dntree_init: MDB_RDONLY");
421
		LOG(INFO, "dntree_init: MDB_RDONLY");
425
	} else {
422
	} else {
426
		mdb_dbi_flags |= MDB_CREATE;
423
		mdb_dbi_flags |= MDB_CREATE;
427
	}
424
	}
428
425
429
	rv = mdb_dbi_open(cache_init_txn_p, "id2dn", mdb_dbi_flags, dbi_p);
426
	rv = mdb_dbi_open(cache_init_txn_p, "id2dn", mdb_dbi_flags, dbi_p);
430
	if (rv != MDB_SUCCESS) {
427
	if (rv != MDB_SUCCESS) {
431
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_dbi_open: %s (%d)", __func__, mdb_strerror(rv), rv);
428
		LOG(ERROR, "mdb_dbi_open: %s (%d)", mdb_strerror(rv), rv);
432
		return rv;
429
		return rv;
433
	};
430
	};
434
	rv = mdb_set_dupsort(cache_init_txn_p, *dbi_p, mdb_dupsort);
431
	rv = mdb_set_dupsort(cache_init_txn_p, *dbi_p, mdb_dupsort);
435
	if (rv != MDB_SUCCESS) {
432
	if (rv != MDB_SUCCESS) {
436
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_set_dupsort: %s (%d)", __func__, mdb_strerror(rv), rv);
433
		LOG(ERROR, "mdb_set_dupsort: %s (%d)", mdb_strerror(rv), rv);
437
		return rv;
434
		return rv;
438
	};
435
	};
439
436
 Lines 443-449   int dntree_init(MDB_dbi *dbi_p, MDB_txn *cache_init_txn_p, int mdb_flags) { Link Here 
443
440
444
	rv = mdb_cursor_open(cache_init_txn_p, *dbi_p, &cur);
441
	rv = mdb_cursor_open(cache_init_txn_p, *dbi_p, &cur);
445
	if (rv != MDB_SUCCESS) {
442
	if (rv != MDB_SUCCESS) {
446
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s: mdb_cursor_open: %s (%d)", __func__, mdb_strerror(rv), rv);
443
		LOG(ERROR, "mdb_cursor_open: %s (%d)", mdb_strerror(rv), rv);
447
		return rv;
444
		return rv;
448
	};
445
	};
449
446
(-)a/management/univention-directory-listener/src/cache_entry.c (-28 / +27 lines)
 Lines 37-43    Link Here 
37
#include <assert.h>
37
#include <assert.h>
38
#include <ldap.h>
38
#include <ldap.h>
39
39
40
#include <univention/debug.h>
41
#include <univention/config.h>
40
#include <univention/config.h>
42
41
43
#include "cache_entry.h"
42
#include "cache_entry.h"
 Lines 190-201   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
190
		struct berval **val, **v;
189
		struct berval **val, **v;
191
190
192
		if ((cache_entry->attributes = realloc(cache_entry->attributes, (cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute *))) == NULL) {
191
		if ((cache_entry->attributes = realloc(cache_entry->attributes, (cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute *))) == NULL) {
193
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of attributes array failed");
192
			LOG(ERROR, "realloc of attributes array failed");
194
			rv = 1;
193
			rv = 1;
195
			goto result;
194
			goto result;
196
		}
195
		}
197
		if ((cache_entry->attributes[cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
196
		if ((cache_entry->attributes[cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
198
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for CacheEntryAttribute failed");
197
			LOG(ERROR, "malloc for CacheEntryAttribute failed");
199
			rv = 1;
198
			rv = 1;
200
			goto result;
199
			goto result;
201
		}
200
		}
 Lines 226-240   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
226
			}
225
			}
227
		}
226
		}
228
		if ((val = ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
227
		if ((val = ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
229
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ldap_get_values failed");
228
			LOG(ERROR, "ldap_get_values failed");
230
			rv = 1;
229
			rv = 1;
231
			goto result;
230
			goto result;
232
		}
231
		}
233
		for (v = val; *v != NULL; v++) {
232
		for (v = val; *v != NULL; v++) {
234
			if ((*v)->bv_val == NULL) {
233
			if ((*v)->bv_val == NULL) {
235
				// check here, strlen behavior might be undefined in this case
234
				// check here, strlen behavior might be undefined in this case
236
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: ignoring bv_val of NULL with bv_len=%ld, ignoring, check attribute: %s of DN: %s", (*v)->bv_len,
235
				LOG(ERROR, "ignoring bv_val of NULL with bv_len=%ld, ignoring, check attribute: %s of DN: %s",
237
				                 cache_entry->attributes[cache_entry->attribute_count]->name, *dn);
236
				    (*v)->bv_len, cache_entry->attributes[cache_entry->attribute_count]->name, *dn);
238
				rv = 1;
237
				rv = 1;
239
				goto result;
238
				goto result;
240
			}
239
			}
 Lines 244-252   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
244
				duplicateMemberUid = 0;
243
				duplicateMemberUid = 0;
245
				for (i = 0; i < cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
244
				for (i = 0; i < cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
246
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len + 1)) {
245
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len + 1)) {
247
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate memberUid entry:");
246
						LOG(ERROR, "Found a duplicate memberUid entry:");
248
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s", *dn);
247
						LOG(ERROR, "DN: %s", *dn);
249
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "memberUid: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
248
						LOG(ERROR, "memberUid: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
250
						duplicateMemberUid = true;
249
						duplicateMemberUid = true;
251
						break;
250
						break;
252
					}
251
					}
 Lines 260-268   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
260
				duplicateUniqueMember = false;
259
				duplicateUniqueMember = false;
261
				for (i = 0; i < cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
260
				for (i = 0; i < cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
262
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len + 1)) {
261
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len + 1)) {
263
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate uniqueMember entry:");
262
						LOG(ERROR, "Found a duplicate uniqueMember entry:");
264
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s", *dn);
263
						LOG(ERROR, "DN: %s", *dn);
265
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "uniqueMember: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
264
						LOG(ERROR, "uniqueMember: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
266
						duplicateUniqueMember = true;
265
						duplicateUniqueMember = true;
267
						break;
266
						break;
268
					}
267
					}
 Lines 273-291   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
273
			}
272
			}
274
			if ((cache_entry->attributes[cache_entry->attribute_count]->values =
273
			if ((cache_entry->attributes[cache_entry->attribute_count]->values =
275
			         realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count + 2) * sizeof(char *))) == NULL) {
274
			         realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count + 2) * sizeof(char *))) == NULL) {
276
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
275
				LOG(ERROR, "realloc of values array failed");
277
				rv = 1;
276
				rv = 1;
278
				goto result;
277
				goto result;
279
			}
278
			}
280
			if ((cache_entry->attributes[cache_entry->attribute_count]->length =
279
			if ((cache_entry->attributes[cache_entry->attribute_count]->length =
281
			         realloc(cache_entry->attributes[cache_entry->attribute_count]->length, (cache_entry->attributes[cache_entry->attribute_count]->value_count + 2) * sizeof(int))) == NULL) {
280
			         realloc(cache_entry->attributes[cache_entry->attribute_count]->length, (cache_entry->attributes[cache_entry->attribute_count]->value_count + 2) * sizeof(int))) == NULL) {
282
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed");
281
				LOG(ERROR, "realloc of length array failed");
283
				rv = 1;
282
				rv = 1;
284
				goto result;
283
				goto result;
285
			}
284
			}
286
			if ((*v)->bv_len == strlen((*v)->bv_val)) {
285
			if ((*v)->bv_len == strlen((*v)->bv_val)) {
287
				if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count] = strdup((*v)->bv_val)) == NULL) {
286
				if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count] = strdup((*v)->bv_val)) == NULL) {
288
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: strdup of value failed");
287
					LOG(ERROR, "strdup of value failed");
289
					rv = 1;
288
					rv = 1;
290
					goto result;
289
					goto result;
291
				}
290
				}
 Lines 295-301   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
295
				// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe
294
				// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe
296
				if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count] = malloc(((*v)->bv_len + 1) * sizeof(char))) ==
295
				if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count] = malloc(((*v)->bv_len + 1) * sizeof(char))) ==
297
				    NULL) {
296
				    NULL) {
298
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed");
297
					LOG(ERROR, "malloc for value failed");
299
					rv = 1;
298
					rv = 1;
300
					goto result;
299
					goto result;
301
				}
300
				}
 Lines 371-382   int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) { Link Here 
371
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
370
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
372
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
371
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
373
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute *))) == NULL) {
372
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute *))) == NULL) {
374
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
373
			LOG(ERROR, "realloc of attributes array failed");
375
			rv = 1;
374
			rv = 1;
376
			goto result;
375
			goto result;
377
		}
376
		}
378
		if ((backup_cache_entry->attributes[backup_cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
377
		if ((backup_cache_entry->attributes[backup_cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
379
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
378
			LOG(ERROR, "malloc for CacheEntryAttribute failed");
380
			rv = 1;
379
			rv = 1;
381
			goto result;
380
			goto result;
382
		}
381
		}
 Lines 389-413   int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) { Link Here 
389
388
390
		for (i = 0; i < (*cur1)->value_count; i++) {
389
		for (i = 0; i < (*cur1)->value_count; i++) {
391
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count + 2) * sizeof(char *))) == NULL) {
390
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count + 2) * sizeof(char *))) == NULL) {
392
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
391
				LOG(ERROR, "realloc of values array failed");
393
				rv = 1;
392
				rv = 1;
394
				goto result;
393
				goto result;
395
			}
394
			}
396
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count + 2) * sizeof(int))) == NULL) {
395
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count + 2) * sizeof(int))) == NULL) {
397
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
396
				LOG(ERROR, "realloc of length array failed");
398
				rv = 1;
397
				rv = 1;
399
				goto result;
398
				goto result;
400
			}
399
			}
401
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
400
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
402
				if (((*cur2)->values[(*cur2)->value_count] = strdup((*cur1)->values[i])) == NULL) {
401
				if (((*cur2)->values[(*cur2)->value_count] = strdup((*cur1)->values[i])) == NULL) {
403
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
402
					LOG(ERROR, "strdup of value failed");
404
					rv = 1;
403
					rv = 1;
405
					goto result;
404
					goto result;
406
				}
405
				}
407
				(*cur2)->length[(*cur2)->value_count] = strlen((*cur2)->values[(*cur2)->value_count]) + 1;
406
				(*cur2)->length[(*cur2)->value_count] = strlen((*cur2)->values[(*cur2)->value_count]) + 1;
408
			} else {
407
			} else {
409
				if (((*cur2)->values[(*cur2)->value_count] = malloc(((*cur1)->length[i]) * sizeof(char))) == NULL) {
408
				if (((*cur2)->values[(*cur2)->value_count] = malloc(((*cur1)->length[i]) * sizeof(char))) == NULL) {
410
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
409
					LOG(ERROR, "malloc for value failed");
411
					rv = 1;
410
					rv = 1;
412
					goto result;
411
					goto result;
413
				}
412
				}
 Lines 478-498   static CacheEntryAttribute *_cache_entry_force_value(CacheEntryAttribute *attr, Link Here 
478
477
479
	tmp = realloc(attr->values, (attr->value_count + 2) * sizeof(char *));
478
	tmp = realloc(attr->values, (attr->value_count + 2) * sizeof(char *));
480
	if (!tmp) {
479
	if (!tmp) {
481
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s:%d realloc() failed", __FILE__, __LINE__);
480
		LOG(ERROR, "realloc() failed");
482
		return NULL;
481
		return NULL;
483
	}
482
	}
484
	attr->values = tmp;
483
	attr->values = tmp;
485
484
486
	tmp = realloc(attr->length, (attr->value_count + 2) * sizeof(int));
485
	tmp = realloc(attr->length, (attr->value_count + 2) * sizeof(int));
487
	if (!tmp) {
486
	if (!tmp) {
488
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s:%d realloc() failed", __FILE__, __LINE__);
487
		LOG(ERROR, "realloc() failed");
489
		return NULL;
488
		return NULL;
490
	}
489
	}
491
	attr->length = tmp;
490
	attr->length = tmp;
492
491
493
	attr->length[attr->value_count] = BER2STR(&ava->la_value, &attr->values[attr->value_count]) + 1;
492
	attr->length[attr->value_count] = BER2STR(&ava->la_value, &attr->values[attr->value_count]) + 1;
494
	if (!attr->values[attr->value_count]) {
493
	if (!attr->values[attr->value_count]) {
495
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s:%d BER2STR() failed", __FILE__, __LINE__);
494
		LOG(ERROR, "BER2STR() failed");
496
		return NULL;
495
		return NULL;
497
	}
496
	}
498
	attr->value_count++;
497
	attr->value_count++;
 Lines 503-523   static CacheEntryAttribute *_cache_entry_force_value(CacheEntryAttribute *attr, Link Here 
503
static CacheEntryAttribute *_cache_entry_add_new_attribute(CacheEntry *entry, LDAPAVA *ava) {
502
static CacheEntryAttribute *_cache_entry_add_new_attribute(CacheEntry *entry, LDAPAVA *ava) {
504
	CacheEntryAttribute *attr = malloc(sizeof(CacheEntryAttribute));
503
	CacheEntryAttribute *attr = malloc(sizeof(CacheEntryAttribute));
505
	if (!attr) {
504
	if (!attr) {
506
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
505
		LOG(ERROR, "malloc() failed");
507
		return NULL;
506
		return NULL;
508
	}
507
	}
509
	memset(attr, 0, sizeof(CacheEntryAttribute));
508
	memset(attr, 0, sizeof(CacheEntryAttribute));
510
509
511
	void *tmp = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute *));
510
	void *tmp = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute *));
512
	if (!tmp) {
511
	if (!tmp) {
513
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s:%d realloc() failed", __FILE__, __LINE__);
512
		LOG(ERROR, "realloc() failed");
514
		goto error;
513
		goto error;
515
	}
514
	}
516
	entry->attributes = tmp;
515
	entry->attributes = tmp;
517
516
518
	BER2STR(&ava->la_attr, &attr->name);
517
	BER2STR(&ava->la_attr, &attr->name);
519
	if (!&attr->name) {
518
	if (!&attr->name) {
520
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s:%d BER2STR() failed", __FILE__, __LINE__);
519
		LOG(ERROR, "BER2STR() failed");
521
		goto error;
520
		goto error;
522
	}
521
	}
523
	if (!_cache_entry_force_value(attr, ava))
522
	if (!_cache_entry_force_value(attr, ava))
(-)a/management/univention-directory-listener/src/cache_lowlevel.c (-35 / +33 lines)
 Lines 40-47    Link Here 
40
#include <errno.h>
40
#include <errno.h>
41
#include <sys/types.h>
41
#include <sys/types.h>
42
42
43
#include <univention/debug.h>
44
45
#include "common.h"
43
#include "common.h"
46
#include "cache_lowlevel.h"
44
#include "cache_lowlevel.h"
47
45
 Lines 52-58   struct cache_entry_header { Link Here 
52
};
50
};
53
51
54
52
55
void hex_dump(int level, void *data, u_int32_t start, u_int32_t size) {
53
static void hex_dump(void *data, u_int32_t start, u_int32_t size) {
56
	int i;
54
	int i;
57
	int pos;
55
	int pos;
58
	char hex[80];
56
	char hex[80];
 Lines 60-89   void hex_dump(int level, void *data, u_int32_t start, u_int32_t size) { Link Here 
60
	const int per_line = 10;
58
	const int per_line = 10;
61
59
62
	pos = 0;
60
	pos = 0;
63
	memset(hex, 0, 80);
61
	memset(hex, 0, sizeof(hex));
64
	memset(str, 0, 80);
62
	memset(str, 0, sizeof(str));
65
63
66
	for (i = 0; i < size; i++) {
64
	for (i = 0; i < size; i++) {
67
		snprintf(hex + (pos * 3), 80 - (pos * 3), "%02x ", ((u_int8_t *)data + start)[i]);
65
		snprintf(hex + (pos * 3), 80 - (pos * 3), "%02x ", ((u_int8_t *)data + start)[i]);
68
		snprintf(str + pos, 80 - pos, "%c", isprint(((char *)data + start)[i]) ? ((char *)data + start)[i] : '?');
66
		snprintf(str + pos, 80 - pos, "%c", isprint(((char *)data + start)[i]) ? ((char *)data + start)[i] : '?');
69
		pos += 1;
67
		pos += 1;
70
		if ((i + 1) % per_line == 0) {
68
		if ((i + 1) % per_line == 0) {
71
			univention_debug(UV_DEBUG_LISTENER, level, "%s| %s (%08d)", hex, str, start + i - per_line);
69
			LOG(ERROR, "%s | %s (%08d)", hex, str, start + i - per_line);
72
			// fprintf(stderr, "%s| %s (%08d)\n", hex, str, start+i-per_line);
70
			// fprintf(stderr, "%s| %s (%08d)\n", hex, str, start+i-per_line);
73
			memset(hex, 0, 80);
71
			memset(hex, 0, sizeof(hex));
74
			memset(str, 0, 80);
72
			memset(str, 0, sizeof(str));
75
			pos = 0;
73
			pos = 0;
76
		}
74
		}
77
	}
75
	}
78
	if (pos != 0)
76
	if (pos != 0)
79
		univention_debug(UV_DEBUG_LISTENER, level, "%s | %s", hex, str);
77
		LOG(ERROR, "%s | %s", hex, str);
80
}
78
}
81
79
82
/* assumption: enough memory as been allocated for us */
80
/* assumption: enough memory as been allocated for us */
83
static int append_buffer(void **data, u_int32_t *pos, void *blob_data, u_int32_t blob_size) {
81
static int append_buffer(void **data, u_int32_t *pos, void *blob_data, u_int32_t blob_size) {
84
	if (blob_size > 0) {
82
	if (blob_size > 0) {
85
		memcpy((void *)(((char *)*data) + *pos), blob_data, blob_size);
83
		memcpy((void *)(((char *)*data) + *pos), blob_data, blob_size);
86
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "position was=%d is=%d", *pos, *pos + blob_size);
84
		LOG(ALL, "position was=%d is=%d", *pos, *pos + blob_size);
87
		*pos += blob_size;
85
		*pos += blob_size;
88
	}
86
	}
89
	return 0;
87
	return 0;
 Lines 93-106   static int write_header(void **data, u_int32_t *size, u_int32_t *pos, u_int16_t Link Here 
93
	struct cache_entry_header h;
91
	struct cache_entry_header h;
94
	u_int32_t need_memory;
92
	u_int32_t need_memory;
95
93
96
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "write_header key_size=%d data_size=%d", key_size, data_size);
94
	LOG(ALL, "key_size=%d data_size=%d", key_size, data_size);
97
95
98
	need_memory = sizeof(struct cache_entry_header) + key_size + data_size;
96
	need_memory = sizeof(struct cache_entry_header) + key_size + data_size;
99
	if (*size < *pos + need_memory) {
97
	if (*size < *pos + need_memory) {
100
		while (*size < *pos + need_memory)
98
		while (*size < *pos + need_memory)
101
			*size += BUFSIZ;
99
			*size += BUFSIZ;
102
		if ((*data = realloc(*data, *size)) == NULL) {
100
		if ((*data = realloc(*data, *size)) == NULL) {
103
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to allocate memory");
101
			LOG(ERROR, "failed to allocate memory");
104
			return 1;
102
			return 1;
105
		}
103
		}
106
	}
104
	}
 Lines 143-159   static int read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_da Link Here 
143
	struct cache_entry_header *h;
141
	struct cache_entry_header *h;
144
142
145
	if (*pos == size) {
143
	if (*pos == size) {
146
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "end of buffer pos=size=%d", *pos);
144
		LOG(ALL, "end of buffer pos=size=%d", *pos);
147
		return 0;
145
		return 0;
148
	} else if (*pos + sizeof(struct cache_entry_header) > size) {
146
	} else if (*pos + sizeof(struct cache_entry_header) > size) {
149
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "buffer exceeded pos=%d size=%d", *pos, size);
147
		LOG(ERROR, "buffer exceeded pos=%d size=%d", *pos, size);
150
		return -1;
148
		return -1;
151
	}
149
	}
152
150
153
	h = (struct cache_entry_header *)((char *)data + *pos);
151
	h = (struct cache_entry_header *)((char *)data + *pos);
154
152
155
	if ((h->type != 1 && h->type != 2) || h->key_size == 0) {
153
	if ((h->type != 1 && h->type != 2) || h->key_size == 0) {
156
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "read_header pos=%d type=%d key_size=%d data_size=%d", *pos, h->type, h->key_size, h->data_size);
154
		LOG(ALL, "pos=%d type=%d key_size=%d data_size=%d", *pos, h->type, h->key_size, h->data_size);
157
		*key_size = 0;
155
		*key_size = 0;
158
		*key_data = NULL;
156
		*key_data = NULL;
159
		*data_size = 0;
157
		*data_size = 0;
 Lines 162-168   static int read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_da Link Here 
162
	}
160
	}
163
	*pos += sizeof(struct cache_entry_header);
161
	*pos += sizeof(struct cache_entry_header);
164
	if (*pos + h->key_size + h->data_size > size) {
162
	if (*pos + h->key_size + h->data_size > size) {
165
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "buffer exceeded pos=%d size=%d", *pos, size);
163
		LOG(ERROR, "buffer exceeded pos=%d size=%d", *pos, size);
166
		return -1;
164
		return -1;
167
	}
165
	}
168
166
 Lines 178-185   static int read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_da Link Here 
178
		*data_size = 0;
176
		*data_size = 0;
179
		*data_data = NULL;
177
		*data_data = NULL;
180
	}
178
	}
181
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "read_header pos=%d type=%d key_size=%d data_size=%d key_data=[%s] data_data=[%s]", *pos, h->type, h->key_size, h->data_size, (char *)*key_data,
179
	LOG(ALL, "pos=%d type=%d key_size=%d data_size=%d key_data=[%s] data_data=[%s]",
182
	                 (char *)*data_data);
180
	    *pos, h->type, h->key_size, h->data_size, (char *)*key_data, (char *)*data_data);
183
181
184
	return h->type;
182
	return h->type;
185
}
183
}
 Lines 199-208   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) { Link Here 
199
		if (type == 1) {
197
		if (type == 1) {
200
			CacheEntryAttribute **attribute, *c_attr;
198
			CacheEntryAttribute **attribute, *c_attr;
201
199
202
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "attribute is \"%s\"", (char *)key_data);
200
			LOG(ALL, "attribute is \"%s\"", (char *)key_data);
203
201
204
			for (attribute = entry->attributes, c_attr = NULL; attribute != NULL && *attribute != NULL; attribute++) {
202
			for (attribute = entry->attributes, c_attr = NULL; attribute != NULL && *attribute != NULL; attribute++) {
205
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "current attribute is \"%s\"", (*attribute)->name);
203
				LOG(ALL, "current attribute is \"%s\"", (*attribute)->name);
206
				if (strcmp((*attribute)->name, (char *)key_data) == 0) {
204
				if (strcmp((*attribute)->name, (char *)key_data) == 0) {
207
					c_attr = *attribute;
205
					c_attr = *attribute;
208
					break;
206
					break;
 Lines 210-224   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) { Link Here 
210
			}
208
			}
211
			if (!c_attr) {
209
			if (!c_attr) {
212
				if (!(entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute *)))) {
210
				if (!(entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute *)))) {
213
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
211
					LOG(ERROR, "realloc failed");
214
					abort();  // FIXME
212
					abort();  // FIXME
215
				}
213
				}
216
				if (!(c_attr = malloc(sizeof(CacheEntryAttribute)))) {
214
				if (!(c_attr = malloc(sizeof(CacheEntryAttribute)))) {
217
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "malloc failed");
215
					LOG(ERROR, "malloc failed");
218
					abort();  // FIXME
216
					abort();  // FIXME
219
				}
217
				}
220
				if (!(c_attr->name = strndup((char *)key_data, key_size))) {
218
				if (!(c_attr->name = strndup((char *)key_data, key_size))) {
221
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
219
					LOG(ERROR, "strndup failed");
222
					abort();  // FIXME
220
					abort();  // FIXME
223
				}
221
				}
224
				c_attr->values = NULL;
222
				c_attr->values = NULL;
 Lines 227-254   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) { Link Here 
227
				entry->attributes[entry->attribute_count++] = c_attr;
225
				entry->attributes[entry->attribute_count++] = c_attr;
228
				entry->attributes[entry->attribute_count] = NULL;
226
				entry->attributes[entry->attribute_count] = NULL;
229
227
230
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s is at %p", c_attr->name, c_attr);
228
				LOG(ALL, "%s is at %p", c_attr->name, c_attr);
231
			}
229
			}
232
			if (!(c_attr->values = realloc(c_attr->values, (c_attr->value_count + 2) * sizeof(char *)))) {
230
			if (!(c_attr->values = realloc(c_attr->values, (c_attr->value_count + 2) * sizeof(char *)))) {
233
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
231
				LOG(ERROR, "realloc failed");
234
				abort();  // FIXME
232
				abort();  // FIXME
235
			}
233
			}
236
			if (!(c_attr->length = realloc(c_attr->length, (c_attr->value_count + 2) * sizeof(int)))) {
234
			if (!(c_attr->length = realloc(c_attr->length, (c_attr->value_count + 2) * sizeof(int)))) {
237
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
235
				LOG(ERROR, "realloc failed");
238
				abort();  // FIXME
236
				abort();  // FIXME
239
			}
237
			}
240
			if (!(c_attr->values[c_attr->value_count] = malloc(data_size))) {
238
			if (!(c_attr->values[c_attr->value_count] = malloc(data_size))) {
241
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "malloc() failed");
239
				LOG(ERROR, "malloc() failed");
242
				abort();  // FIXME
240
				abort();  // FIXME
243
			}
241
			}
244
			c_attr->length[c_attr->value_count] = data_size;
242
			c_attr->length[c_attr->value_count] = data_size;
245
			memcpy(c_attr->values[c_attr->value_count], data_data, data_size);
243
			memcpy(c_attr->values[c_attr->value_count], data_data, data_size);
246
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", c_attr->values[c_attr->value_count]);
244
			LOG(ALL, "value is \"%s\"", c_attr->values[c_attr->value_count]);
247
			c_attr->values[++c_attr->value_count] = NULL;
245
			c_attr->values[++c_attr->value_count] = NULL;
248
		} else if (type == 2) {
246
		} else if (type == 2) {
249
			entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char *));
247
			entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char *));
250
			if (!(entry->modules[entry->module_count] = strndup((char *)key_data, key_size))) {
248
			if (!(entry->modules[entry->module_count] = strndup((char *)key_data, key_size))) {
251
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
249
				LOG(ERROR, "strndup failed");
252
				abort();  // FIXME
250
				abort();  // FIXME
253
			}
251
			}
254
			entry->modules[++entry->module_count] = NULL;
252
			entry->modules[++entry->module_count] = NULL;
 Lines 258-270   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) { Link Here 
258
			u_int32_t len;
256
			u_int32_t len;
259
			int rv;
257
			int rv;
260
258
261
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "bad data block at position %d:", pos);
259
			LOG(ERROR, "bad data block at position %d:", pos);
262
			len = pos < 1000 ? pos : 1000;
260
			len = pos < 1000 ? pos : 1000;
263
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "last %d bytes of previous entry:", len);
261
			LOG(ERROR, "last %d bytes of previous entry:", len);
264
			hex_dump(UV_DEBUG_ERROR, data, pos < 1000 ? 0 : pos - 1000, len);
262
			hex_dump(data, pos < 1000 ? 0 : pos - 1000, len);
265
			len = pos + 1000 > size ? size - pos : 1000;
263
			len = pos + 1000 > size ? size - pos : 1000;
266
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "first %d bytes of current entry:", len);
264
			LOG(ERROR, "first %d bytes of current entry:", len);
267
			hex_dump(UV_DEBUG_ERROR, data, pos, len);
265
			hex_dump(data, pos, len);
268
266
269
			rv = snprintf(filename, PATH_MAX, "%s/bad_cache", cache_dir);
267
			rv = snprintf(filename, PATH_MAX, "%s/bad_cache", cache_dir);
270
			if (rv < 0 || rv >= PATH_MAX)
268
			if (rv < 0 || rv >= PATH_MAX)
 Lines 284-289   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) { Link Here 
284
}
282
}
285
283
286
void abort_io(const char *func, const char *filename) {
284
void abort_io(const char *func, const char *filename) {
287
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Fatal %s(%s): %s", func, filename, strerror(errno));
285
	LOG(ERROR, "Fatal %s(%s): %s", func, filename, strerror(errno));
288
	abort();
286
	abort();
289
}
287
}
(-)a/management/univention-directory-listener/src/cache_lowlevel.h (-1 lines)
 Lines 37-43    Link Here 
37
37
38
int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry);
38
int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry);
39
int parse_entry(void *data, u_int32_t size, CacheEntry *entry);
39
int parse_entry(void *data, u_int32_t size, CacheEntry *entry);
40
void hex_dump(int level, void *data, u_int32_t start, u_int32_t size);
41
void abort_io(const char *func, const char *filename) __attribute__((noreturn));
40
void abort_io(const char *func, const char *filename) __attribute__((noreturn));
42
41
43
#endif /* _CACHE_LOWLEVEL_ */
42
#endif /* _CACHE_LOWLEVEL_ */
(-)a/management/univention-directory-listener/src/change.c (-51 / +50 lines)
 Lines 42-48    Link Here 
42
#include <string.h>
42
#include <string.h>
43
#include <lmdb.h>
43
#include <lmdb.h>
44
44
45
#include <univention/debug.h>
46
#include <univention/config.h>
45
#include <univention/config.h>
47
46
48
#include "common.h"
47
#include "common.h"
 Lines 78-93   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
78
	int i;
77
	int i;
79
	bool abort_init = false;
78
	bool abort_init = false;
80
79
81
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "initializing module %s", handler->name);
80
	LOG(WARN, "initializing module %s", handler->name);
82
81
83
	memset(&old_cache_entry, 0, sizeof(CacheEntry));
82
	memset(&old_cache_entry, 0, sizeof(CacheEntry));
84
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "call handler_clean for module %s", handler->name);
83
	LOG(INFO, "call handler_clean for module %s", handler->name);
85
	handler_clean(handler);
84
	handler_clean(handler);
86
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "call handler_initialize for module %s", handler->name);
85
	LOG(INFO, "call handler_initialize for module %s", handler->name);
87
	handler_initialize(handler);
86
	handler_initialize(handler);
88
87
89
	/* remove old entries for module */
88
	/* remove old entries for module */
90
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "remove old entries for module %s", handler->name);
89
	LOG(INFO, "remove old entries for module %s", handler->name);
91
	for (rv = cache_first_entry(&id2entry_cursor_p, &id2dn_cursor_p, &dn, &cache_entry); rv != MDB_NOTFOUND; rv = cache_next_entry(&id2entry_cursor_p, &id2dn_cursor_p, &dn, &cache_entry)) {
90
	for (rv = cache_first_entry(&id2entry_cursor_p, &id2dn_cursor_p, &dn, &cache_entry); rv != MDB_NOTFOUND; rv = cache_next_entry(&id2entry_cursor_p, &id2dn_cursor_p, &dn, &cache_entry)) {
92
		if (rv == -1)
91
		if (rv == -1)
93
			continue;
92
			continue;
 Lines 99-112   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
99
		cache_free_entry(&dn, &cache_entry);
98
		cache_free_entry(&dn, &cache_entry);
100
	}
99
	}
101
100
102
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "call cache_free_cursor for module %s", handler->name);
101
	LOG(INFO, "call cache_free_cursor for module %s", handler->name);
103
	cache_free_cursor(id2entry_cursor_p, id2dn_cursor_p);
102
	cache_free_cursor(id2entry_cursor_p, id2dn_cursor_p);
104
103
105
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "initialize schema for module %s", handler->name);
104
	LOG(INFO, "initialize schema for module %s", handler->name);
106
	/* initialize schema; if it's not in cache yet (it really should be), it'll
105
	/* initialize schema; if it's not in cache yet (it really should be), it'll
107
	   be initialized on the regular schema check after ldapsearches */
106
	   be initialized on the regular schema check after ldapsearches */
108
	if ((rv = cache_get_entry_lower_upper("cn=Subschema", &cache_entry)) != 0 && rv != MDB_NOTFOUND) {
107
	if ((rv = cache_get_entry_lower_upper("cn=Subschema", &cache_entry)) != 0 && rv != MDB_NOTFOUND) {
109
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while reading from database");
108
		LOG(WARN, "error while reading from database");
110
		return LDAP_OTHER;
109
		return LDAP_OTHER;
111
	} else if (rv == 0) {
110
	} else if (rv == 0) {
112
		signals_block();
111
		signals_block();
 Lines 116-122   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
116
		cache_free_entry(NULL, &cache_entry);
115
		cache_free_entry(NULL, &cache_entry);
117
	}
116
	}
118
117
119
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "module %s for relating objects", handler->name);
118
	LOG(INFO, "module %s for relating objects", handler->name);
120
	rv = LDAP_SUCCESS;
119
	rv = LDAP_SUCCESS;
121
	for (f = handler->filters; !abort_init && f != NULL && *f != NULL; f++) {
120
	for (f = handler->filters; !abort_init && f != NULL && *f != NULL; f++) {
122
		/* When initializing a module, only search for the DNs. If the
121
		/* When initializing a module, only search for the DNs. If the
 Lines 136-142   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
136
		int sizelimit0 = 0;
135
		int sizelimit0 = 0;
137
		rv = LDAP_RETRY(lp, ldap_search_ext_s(lp->ld, (*f)->base, (*f)->scope, (*f)->filter, _attrs, attrsonly1, serverctrls, clientctrls, &timeout, sizelimit0, &res));
136
		rv = LDAP_RETRY(lp, ldap_search_ext_s(lp->ld, (*f)->base, (*f)->scope, (*f)->filter, _attrs, attrsonly1, serverctrls, clientctrls, &timeout, sizelimit0, &res));
138
		if (rv != LDAP_SUCCESS) {
137
		if (rv != LDAP_SUCCESS) {
139
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not get DNs when initializing %s: %s", handler->name, ldap_err2string(rv));
138
			LOG(ERROR, "could not get DNs when initializing %s: %s", handler->name, ldap_err2string(rv));
140
			return rv;
139
			return rv;
141
		}
140
		}
142
141
 Lines 150-156   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
150
		}
149
		}
151
150
152
		if (!(dns = malloc(dn_count * sizeof(struct dn_list)))) {
151
		if (!(dns = malloc(dn_count * sizeof(struct dn_list)))) {
153
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "malloc failed");
152
			LOG(ERROR, "malloc failed");
154
			abort();  // FIXME
153
			abort();  // FIXME
155
		}
154
		}
156
155
 Lines 172-178   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
172
		}
171
		}
173
172
174
		for (i = 0; i < dn_count; i++) {
173
		for (i = 0; i < dn_count; i++) {
175
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "DN: %s", dns[i].dn);
174
			LOG(ALL, "DN: %s", dns[i].dn);
176
175
177
			if ((rv = cache_get_entry_lower_upper(dns[i].dn, &cache_entry)) == MDB_NOTFOUND) { /* XXX */
176
			if ((rv = cache_get_entry_lower_upper(dns[i].dn, &cache_entry)) == MDB_NOTFOUND) { /* XXX */
178
				LDAPMessage *res2, *first;
177
				LDAPMessage *res2, *first;
 Lines 183-189   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
183
					cache_new_entry_from_ldap(NULL, &cache_entry, lp->ld, first);
182
					cache_new_entry_from_ldap(NULL, &cache_entry, lp->ld, first);
184
					ldap_msgfree(res2);
183
					ldap_msgfree(res2);
185
				} else if (rv != LDAP_NO_SUCH_OBJECT) {
184
				} else if (rv != LDAP_NO_SUCH_OBJECT) {
186
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not get DN %s for handler %s: %s", dns[i].dn, handler->name, ldap_err2string(rv));
185
					LOG(ERROR, "could not get DN %s for handler %s: %s", dns[i].dn, handler->name, ldap_err2string(rv));
187
					cache_free_entry(NULL, &cache_entry);
186
					cache_free_entry(NULL, &cache_entry);
188
					abort_init = true;
187
					abort_init = true;
189
					goto cleanup;
188
					goto cleanup;
 Lines 192-198   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
192
				   deleted after we do the ldapsearch. We
191
				   deleted after we do the ldapsearch. We
193
				   shouldn't need to care here. */
192
				   shouldn't need to care here. */
194
			} else if (rv != 0) {
193
			} else if (rv != 0) {
195
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while reading from database");
194
				LOG(WARN, "error while reading from database");
196
				rv = LDAP_OTHER;
195
				rv = LDAP_OTHER;
197
				abort_init = true;
196
				abort_init = true;
198
				goto cleanup;
197
				goto cleanup;
 Lines 211-217   static int change_init_module(univention_ldap_parameters_t *lp, Handler *handler Link Here 
211
		free(dns);
210
		free(dns);
212
	}
211
	}
213
	cache_free_entry(NULL, &old_cache_entry);
212
	cache_free_entry(NULL, &old_cache_entry);
214
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "finished initializing module %s with rv=%d", handler->name, rv);
213
	LOG(WARN, "finished initializing module %s with rv=%d", handler->name, rv);
215
	return rv;
214
	return rv;
216
}
215
}
217
216
 Lines 250-266   int change_update_entry(univention_ldap_parameters_t *lp, NotifierID id, LDAPMes Link Here 
250
	memset(&old_cache_entry, 0, sizeof(CacheEntry));
249
	memset(&old_cache_entry, 0, sizeof(CacheEntry));
251
250
252
	if ((rv = cache_new_entry_from_ldap(&dn, &cache_entry, lp->ld, ldap_entry)) != 0) {
251
	if ((rv = cache_new_entry_from_ldap(&dn, &cache_entry, lp->ld, ldap_entry)) != 0) {
253
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while converting LDAP entry to cache entry");
252
		LOG(WARN, "error while converting LDAP entry to cache entry");
254
		goto result;
253
		goto result;
255
	}
254
	}
256
	if ((rv = cache_get_entry_lower_upper(dn, &old_cache_entry)) != 0 && rv != MDB_NOTFOUND) {
255
	if ((rv = cache_get_entry_lower_upper(dn, &old_cache_entry)) != 0 && rv != MDB_NOTFOUND) {
257
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while reading from database");
256
		LOG(WARN, "error while reading from database");
258
		rv = LDAP_OTHER;
257
		rv = LDAP_OTHER;
259
	} else {
258
	} else {
260
		signals_block();
259
		signals_block();
261
		handlers_update(dn, &cache_entry, &old_cache_entry, command);
260
		handlers_update(dn, &cache_entry, &old_cache_entry, command);
262
		if ((rv = cache_update_entry_lower(id, dn, &cache_entry)) != 0) {
261
		if ((rv = cache_update_entry_lower(id, dn, &cache_entry)) != 0) {
263
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while writing to database");
262
			LOG(WARN, "error while writing to database");
264
		}
263
		}
265
		rv = 0;
264
		rv = 0;
266
		signals_unblock();
265
		signals_unblock();
 Lines 281-295   static void change_delete(struct transaction *trans) { Link Here 
281
280
282
	rv = handlers_delete(trans->cur.notify.dn, &trans->cur.cache, 'd');
281
	rv = handlers_delete(trans->cur.notify.dn, &trans->cur.cache, 'd');
283
	if (rv == 0)
282
	if (rv == 0)
284
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "deleted from cache: %s", trans->cur.notify.dn);
283
		LOG(INFO, "deleted from cache: %s", trans->cur.notify.dn);
285
	if (cache_entry_valid(&trans->cur.cache)) {
284
	if (cache_entry_valid(&trans->cur.cache)) {
286
		if (rv != 0)
285
		if (rv != 0)
287
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "at least one delete handler failed");
286
			LOG(WARN, "at least one delete handler failed");
288
		cache_delete_entry_lower_upper(trans->cur.notify.id, trans->cur.notify.dn);
287
		cache_delete_entry_lower_upper(trans->cur.notify.id, trans->cur.notify.dn);
289
		cache_free_entry(NULL, &trans->cur.cache);
288
		cache_free_entry(NULL, &trans->cur.cache);
290
	} else {
289
	} else {
291
		if (rv != 0)
290
		if (rv != 0)
292
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "not in cache: %s", trans->cur.notify.dn);
291
			LOG(INFO, "not in cache: %s", trans->cur.notify.dn);
293
	}
292
	}
294
293
295
	signals_unblock();
294
	signals_unblock();
 Lines 320-326   int change_update_schema(univention_ldap_parameters_t *lp) { Link Here 
320
	free(server_role);
319
	free(server_role);
321
320
322
	if ((notifier_get_schema_id_s(NULL, &new_id)) != 0) {
321
	if ((notifier_get_schema_id_s(NULL, &new_id)) != 0) {
323
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get schema DN");
322
		LOG(ERROR, "failed to get schema DN");
324
		return LDAP_OTHER;
323
		return LDAP_OTHER;
325
	}
324
	}
326
325
 Lines 328-346   int change_update_schema(univention_ldap_parameters_t *lp) { Link Here 
328
		rv = LDAP_RETRY(lp, ldap_search_ext_s(lp->ld, "cn=Subschema", LDAP_SCOPE_BASE, "(objectClass=*)", attrs, attrsonly0, serverctrls, clientctrls, &timeout, sizelimit0, &res));
327
		rv = LDAP_RETRY(lp, ldap_search_ext_s(lp->ld, "cn=Subschema", LDAP_SCOPE_BASE, "(objectClass=*)", attrs, attrsonly0, serverctrls, clientctrls, &timeout, sizelimit0, &res));
329
		if (rv == LDAP_SUCCESS) {
328
		if (rv == LDAP_SUCCESS) {
330
			if ((cur = ldap_first_entry(lp->ld, res)) == NULL) {
329
			if ((cur = ldap_first_entry(lp->ld, res)) == NULL) {
331
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "got no entry for schema");
330
				LOG(ERROR, "got no entry for schema");
332
				return LDAP_OTHER;
331
				return LDAP_OTHER;
333
			} else {
332
			} else {
334
				rv = change_update_entry(lp, new_id, cur, 'n');
333
				rv = change_update_entry(lp, new_id, cur, 'n');
335
			}
334
			}
336
			ldap_memfree(res);
335
			ldap_memfree(res);
337
		} else {
336
		} else {
338
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not receive schema (%s)", ldap_err2string(rv));
337
			LOG(ERROR, "could not receive schema (%s)", ldap_err2string(rv));
339
		}
338
		}
340
		cache_master_entry.schema_id = new_id;
339
		cache_master_entry.schema_id = new_id;
341
		rv = cache_update_master_entry(&cache_master_entry);
340
		rv = cache_update_master_entry(&cache_master_entry);
342
		if (cache_set_schema_id(new_id))
341
		if (cache_set_schema_id(new_id))
343
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "failed to write schema ID");
342
			LOG(WARN, "failed to write schema ID");
344
	}
343
	}
345
344
346
	return rv;
345
	return rv;
 Lines 384-390   static int fake_container(struct transaction *trans, char *dn) { Link Here 
384
		} else if (!strcasecmp(name, "dc")) {
383
		} else if (!strcasecmp(name, "dc")) {
385
			cache_entry_add1(&cache_entry, "objectClass", "domain");
384
			cache_entry_add1(&cache_entry, "objectClass", "domain");
386
		} else {
385
		} else {
387
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "unknown container: %s", name);
386
			LOG(ERROR, "unknown container: %s", name);
388
			goto out;
387
			goto out;
389
		}
388
		}
390
		free(name);
389
		free(name);
 Lines 400-406   static int fake_container(struct transaction *trans, char *dn) { Link Here 
400
399
401
	// 5. Store cache entry at intermediate location
400
	// 5. Store cache entry at intermediate location
402
	if ((rv = cache_update_entry_lower(trans->cur.notify.id, dn, &cache_entry)) != 0)
401
	if ((rv = cache_update_entry_lower(trans->cur.notify.id, dn, &cache_entry)) != 0)
403
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while writing to database");
402
		LOG(WARN, "error while writing to database");
404
403
405
out:
404
out:
406
	free(name);
405
	free(name);
 Lines 418-424   static int check_parent_dn(struct transaction *trans, char *dn) { Link Here 
418
		return LDAP_SUCCESS;
417
		return LDAP_SUCCESS;
419
418
420
	if (same_dn(dn, trans->lp_local->base)) {
419
	if (same_dn(dn, trans->lp_local->base)) {
421
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "Ignore parent_dn check because dn is ldap base.");
420
		LOG(INFO, "Ignore parent_dn check because dn is ldap base.");
422
		return LDAP_SUCCESS;
421
		return LDAP_SUCCESS;
423
	}
422
	}
424
423
 Lines 433-439   static int check_parent_dn(struct transaction *trans, char *dn) { Link Here 
433
		return rv;
432
		return rv;
434
433
435
	if (same_dn(parent_dn, trans->lp_local->base)) {
434
	if (same_dn(parent_dn, trans->lp_local->base)) {
436
		// univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "parent of DN: %s is base", dn);
435
		// LOG(INFO, "parent of DN: %s is base", dn);
437
		goto out;
436
		goto out;
438
	}
437
	}
439
438
 Lines 449-461   static int check_parent_dn(struct transaction *trans, char *dn) { Link Here 
449
	};
448
	};
450
	int sizelimit0 = 0;
449
	int sizelimit0 = 0;
451
450
452
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "checking parent_dn of %s in local LDAP", dn);
451
	LOG(INFO, "checking parent_dn of %s in local LDAP", dn);
453
452
454
	/* try to open a connection to the local LDAP for the parent DN check */
453
	/* try to open a connection to the local LDAP for the parent DN check */
455
	if (trans->lp_local->ld == NULL) {
454
	if (trans->lp_local->ld == NULL) {
456
		rv = univention_ldap_open(trans->lp_local);
455
		rv = univention_ldap_open(trans->lp_local);
457
		if (rv != LDAP_SUCCESS) {
456
		if (rv != LDAP_SUCCESS) {
458
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "check_parent_dn: bind to local LDAP failed");
457
			LOG(ERROR, "bind to local LDAP failed");
459
			goto out;
458
			goto out;
460
		}
459
		}
461
	}
460
	}
 Lines 469-475   static int check_parent_dn(struct transaction *trans, char *dn) { Link Here 
469
			/* lookup parent_dn object in remote LDAP */
468
			/* lookup parent_dn object in remote LDAP */
470
			rv = LDAP_RETRY(trans->lp, ldap_search_ext_s(trans->lp->ld, parent_dn, LDAP_SCOPE_BASE, filter, attrs, attrsonly0, serverctrls, clientctrls, &timeout, sizelimit0, &res));
469
			rv = LDAP_RETRY(trans->lp, ldap_search_ext_s(trans->lp->ld, parent_dn, LDAP_SCOPE_BASE, filter, attrs, attrsonly0, serverctrls, clientctrls, &timeout, sizelimit0, &res));
471
			if (rv == LDAP_NO_SUCH_OBJECT) {
470
			if (rv == LDAP_NO_SUCH_OBJECT) {
472
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not find parent container of dn: %s from %s (%s)", dn, trans->lp->host, ldap_err2string(rv));
471
				LOG(ERROR, "could not find parent container of dn: %s from %s (%s)", dn, trans->lp->host, ldap_err2string(rv));
473
				if (is_move(trans))
472
				if (is_move(trans))
474
					rv = fake_container(trans, parent_dn);
473
					rv = fake_container(trans, parent_dn);
475
			} else { /* parent_dn found in remote LDAP */
474
			} else { /* parent_dn found in remote LDAP */
 Lines 478-490   static int check_parent_dn(struct transaction *trans, char *dn) { Link Here 
478
					/* entry exists (since we didn't get NO_SUCH_OBJECT),
477
					/* entry exists (since we didn't get NO_SUCH_OBJECT),
479
					 * but was probably excluded through ACLs which makes it
478
					 * but was probably excluded through ACLs which makes it
480
					 * non-existent for us */
479
					 * non-existent for us */
481
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not get parent object of dn: %s from %s (%s)", dn, trans->lp->host, ldap_err2string(rv));
480
					LOG(ERROR, "could not get parent object of dn: %s from %s (%s)", dn, trans->lp->host, ldap_err2string(rv));
482
					if (is_move(trans))
481
					if (is_move(trans))
483
						rv = fake_container(trans, parent_dn);
482
						rv = fake_container(trans, parent_dn);
484
					else
483
					else
485
						rv = LDAP_INSUFFICIENT_ACCESS;
484
						rv = LDAP_INSUFFICIENT_ACCESS;
486
				} else { /* found data for parent_dn in remote LDAP */
485
				} else { /* found data for parent_dn in remote LDAP */
487
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_PROCESS, "change_update_entry for parent_dn: %s", parent_dn);
486
					LOG(PROCESS, "change_update_entry for parent_dn: %s", parent_dn);
488
					rv = change_update_entry(trans->lp, trans->cur.notify.id, cur, 'n'); /* add parent_dn object */
487
					rv = change_update_entry(trans->lp, trans->cur.notify.id, cur, 'n'); /* add parent_dn object */
489
				}
488
				}
490
			}
489
			}
 Lines 560-578   static int process_move(struct transaction *trans) { Link Here 
560
	rv = check_parent_dn(trans, current_dn);
559
	rv = check_parent_dn(trans, current_dn);
561
	signals_block();
560
	signals_block();
562
	if (same_dn(trans->prev.notify.dn, current_dn))
561
	if (same_dn(trans->prev.notify.dn, current_dn))
563
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_PROCESS, "move_same_dn(%s)", current_dn);
562
		LOG(PROCESS, "move_same_dn(%s)", current_dn);
564
	rv = handlers_delete(trans->prev.notify.dn, &trans->prev.cache, 'r');
563
	rv = handlers_delete(trans->prev.notify.dn, &trans->prev.cache, 'r');
565
	rv = handlers_update(current_dn, &trans->cur.cache, &dummy, 'a');
564
	rv = handlers_update(current_dn, &trans->cur.cache, &dummy, 'a');
566
	signals_unblock();
565
	signals_unblock();
567
566
568
	// 5. Store cache entry at new location
567
	// 5. Store cache entry at new location
569
	if ((rv = cache_update_entry_lower(trans->cur.notify.id, current_dn, &trans->cur.cache)) != 0) {
568
	if ((rv = cache_update_entry_lower(trans->cur.notify.id, current_dn, &trans->cur.cache)) != 0) {
570
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while writing to database");
569
		LOG(WARN, "error while writing to database");
571
	}
570
	}
572
571
573
	// 6. Check for final destination
572
	// 6. Check for final destination
574
	if (final) {
573
	if (final) {
575
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Object finally moved to '%s'", current_dn);
574
		LOG(ALL, "Object finally moved to '%s'", current_dn);
576
		rv = change_update_entry(trans->lp, trans->cur.notify.id, trans->ldap, 'm');
575
		rv = change_update_entry(trans->lp, trans->cur.notify.id, trans->ldap, 'm');
577
	}
576
	}
578
577
 Lines 592-605   static int change_update_cache(struct transaction *trans) { Link Here 
592
591
593
	trans->cur.ldap_dn = ldap_get_dn(trans->lp->ld, trans->ldap);
592
	trans->cur.ldap_dn = ldap_get_dn(trans->lp->ld, trans->ldap);
594
	if (!trans->cur.ldap_dn) {
593
	if (!trans->cur.ldap_dn) {
595
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get current DN %s", trans->cur.notify.dn);
594
		LOG(ERROR, "failed to get current DN %s", trans->cur.notify.dn);
596
		goto out;
595
		goto out;
597
	}
596
	}
598
597
599
	switch (trans->cur.notify.command) {
598
	switch (trans->cur.notify.command) {
600
	case 'm':  // modify
599
	case 'm':  // modify
601
		if (!same_dn(trans->cur.notify.dn, trans->cur.ldap_dn)) {
600
		if (!same_dn(trans->cur.notify.dn, trans->cur.ldap_dn)) {
602
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_PROCESS, "Delaying update for '%s' until moved to '%s'", trans->cur.notify.dn, trans->cur.ldap_dn);
601
			LOG(PROCESS, "Delaying update for '%s' until moved to '%s'", trans->cur.notify.dn, trans->cur.ldap_dn);
603
		} else {
602
		} else {
604
			rv = check_parent_dn(trans, trans->cur.ldap_dn);
603
			rv = check_parent_dn(trans, trans->cur.ldap_dn);
605
			rv = change_update_entry(trans->lp, trans->cur.notify.id, trans->ldap, trans->cur.notify.command);
604
			rv = change_update_entry(trans->lp, trans->cur.notify.id, trans->ldap, trans->cur.notify.command);
 Lines 610-623   static int change_update_cache(struct transaction *trans) { Link Here 
610
			rv = process_move(trans);
609
			rv = process_move(trans);
611
		} else {  // add
610
		} else {  // add
612
			if (!same_dn(trans->cur.notify.dn, trans->cur.ldap_dn))
611
			if (!same_dn(trans->cur.notify.dn, trans->cur.ldap_dn))
613
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Schizophrenia: a NEW object '%s' is added, which ALREADY is in our cache for '%s'?", trans->cur.ldap_dn, trans->cur.notify.dn);
612
				LOG(WARN, "Schizophrenia: a NEW object '%s' is added, which ALREADY is in our cache for '%s'?",
613
				    trans->cur.ldap_dn, trans->cur.notify.dn);
614
			rv = check_parent_dn(trans, trans->cur.ldap_dn);
614
			rv = check_parent_dn(trans, trans->cur.ldap_dn);
615
			rv = change_update_entry(trans->lp, trans->cur.notify.id, trans->ldap, trans->cur.notify.command);
615
			rv = change_update_entry(trans->lp, trans->cur.notify.id, trans->ldap, trans->cur.notify.command);
616
		}
616
		}
617
		break;
617
		break;
618
	case 'd':  // delete
618
	case 'd':  // delete
619
		if (!same_dn(trans->cur.notify.dn, trans->cur.ldap_dn))
619
		if (!same_dn(trans->cur.notify.dn, trans->cur.ldap_dn))
620
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Resurrection: DELETED object '%s' will re-appear at '%s'?", trans->cur.notify.dn, trans->cur.ldap_dn);
620
			LOG(WARN, "Resurrection: DELETED object '%s' will re-appear at '%s'?", trans->cur.notify.dn, trans->cur.ldap_dn);
621
		change_delete(trans);
621
		change_delete(trans);
622
		rv = 0;
622
		rv = 0;
623
		break;
623
		break;
 Lines 628-634   static int change_update_cache(struct transaction *trans) { Link Here 
628
		rv = 0;
628
		rv = 0;
629
		break;
629
		break;
630
	default:
630
	default:
631
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Unknown command: %c", trans->cur.notify.command);
631
		LOG(ERROR, "Unknown command: %c", trans->cur.notify.command);
632
	}
632
	}
633
633
634
out:
634
out:
 Lines 655-665   int change_update_dn(struct transaction *trans) { Link Here 
655
	int rv;
655
	int rv;
656
	const char *uuid = NULL;
656
	const char *uuid = NULL;
657
657
658
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_PROCESS, "updating '%s' command %c", trans->cur.notify.dn, trans->cur.notify.command);
658
	LOG(PROCESS, "updating '%s' command %c", trans->cur.notify.dn, trans->cur.notify.command);
659
659
660
	rv = cache_get_entry_lower_upper(trans->cur.notify.dn, &trans->cur.cache);
660
	rv = cache_get_entry_lower_upper(trans->cur.notify.dn, &trans->cur.cache);
661
	if (rv != 0 && rv != MDB_NOTFOUND) {
661
	if (rv != 0 && rv != MDB_NOTFOUND) {
662
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error reading database for %s", trans->cur.notify.dn);
662
		LOG(WARN, "error reading database for %s", trans->cur.notify.dn);
663
		return LDAP_OTHER;
663
		return LDAP_OTHER;
664
	}
664
	}
665
	switch (trans->prev.notify.command) {
665
	switch (trans->prev.notify.command) {
 Lines 669-679   int change_update_dn(struct transaction *trans) { Link Here 
669
		break;
669
		break;
670
	case 'r':  // move_from ... move_to
670
	case 'r':  // move_from ... move_to
671
		if (!cache_entry_valid(&trans->prev.cache)) {
671
		if (!cache_entry_valid(&trans->prev.cache)) {
672
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "move_to without history '%s'", trans->prev.notify.dn);
672
			LOG(ERROR, "move_to without history '%s'", trans->prev.notify.dn);
673
			break;
673
			break;
674
		}
674
		}
675
		if (rv == 0) {
675
		if (rv == 0) {
676
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "move_to collision at '%s'", trans->cur.notify.dn);
676
			LOG(INFO, "move_to collision at '%s'", trans->cur.notify.dn);
677
			cache_free_entry(NULL, &trans->cur.cache);
677
			cache_free_entry(NULL, &trans->cur.cache);
678
		}
678
		}
679
		if (is_move(trans)) {
679
		if (is_move(trans)) {
 Lines 684-704   int change_update_dn(struct transaction *trans) { Link Here 
684
			break;
684
			break;
685
		}
685
		}
686
	default:
686
	default:
687
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "non consecutive move: %ld:%c:%s << %ld:%c:%s", trans->prev.notify.id, trans->prev.notify.command, trans->prev.notify.dn, trans->cur.notify.id,
687
		LOG(ERROR, "non consecutive move: %ld:%c:%s << %ld:%c:%s", trans->prev.notify.id, trans->prev.notify.command, trans->prev.notify.dn, trans->cur.notify.id, trans->cur.notify.command, trans->cur.notify.dn);
688
		                 trans->cur.notify.command, trans->cur.notify.dn);
689
		rv = 1;
688
		rv = 1;
690
		goto out;
689
		goto out;
691
	}
690
	}
692
691
693
	if (uuid) {
692
	if (uuid) {
694
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "updating by UUID %s", uuid);
693
		LOG(ALL, "updating by UUID %s", uuid);
695
		base = trans->lp->base;
694
		base = trans->lp->base;
696
		scope = LDAP_SCOPE_SUBTREE;
695
		scope = LDAP_SCOPE_SUBTREE;
697
		snprintf(filter, sizeof(filter), "(entryUUID=%s)", uuid);
696
		snprintf(filter, sizeof(filter), "(entryUUID=%s)", uuid);
698
		trans->cur.uuid = strdup(uuid);
697
		trans->cur.uuid = strdup(uuid);
699
	} else {
698
	} else {
700
	retry_dn:
699
	retry_dn:
701
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "updating by DN %s", trans->cur.notify.dn);
700
		LOG(ALL, "updating by DN %s", trans->cur.notify.dn);
702
		base = trans->cur.notify.dn;
701
		base = trans->cur.notify.dn;
703
		scope = LDAP_SCOPE_BASE;
702
		scope = LDAP_SCOPE_BASE;
704
		snprintf(filter, sizeof(filter), "(objectClass=*)");
703
		snprintf(filter, sizeof(filter), "(objectClass=*)");
 Lines 719-725   int change_update_dn(struct transaction *trans) { Link Here 
719
		}
718
		}
720
		trans->ldap = NULL;
719
		trans->ldap = NULL;
721
	} else {
720
	} else {
722
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error searching DN %s: %d", trans->cur.notify.dn, rv);
721
		LOG(WARN, "error searching DN %s: %d", trans->cur.notify.dn, rv);
723
		_free_transaction_op(&trans->cur);
722
		_free_transaction_op(&trans->cur);
724
	}
723
	}
725
	ldap_msgfree(res);
724
	ldap_msgfree(res);
(-)a/management/univention-directory-listener/src/convert.c (-5 / +3 lines)
 Lines 39-46    Link Here 
39
#include <pwd.h>
39
#include <pwd.h>
40
#include <sys/types.h>
40
#include <sys/types.h>
41
41
42
#include <univention/debug.h>
43
44
#include "cache_bdb.h"
42
#include "cache_bdb.h"
45
#include "cache.h"
43
#include "cache.h"
46
#include "common.h"
44
#include "common.h"
 Lines 54-60   static void exit_if_cache_mdb_exists(void) { Link Here 
54
		abort();
52
		abort();
55
53
56
	if (access(cache_mdb_filename, F_OK) != -1) {
54
	if (access(cache_mdb_filename, F_OK) != -1) {
57
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "%s already exists", cache_mdb_filename);
55
		LOG(ERROR, "%s already exists", cache_mdb_filename);
58
		exit(EXIT_FAILURE);
56
		exit(EXIT_FAILURE);
59
	}
57
	}
60
}
58
}
 Lines 131-139   int main(int argc, char *argv[]) { Link Here 
131
129
132
	for (rv = bdb_cache_first_entry(&cur, &dn, &entry); rv != DB_NOTFOUND; rv = bdb_cache_next_entry(&cur, &dn, &entry)) {
130
	for (rv = bdb_cache_first_entry(&cur, &dn, &entry); rv != DB_NOTFOUND; rv = bdb_cache_next_entry(&cur, &dn, &entry)) {
133
		if (rv != 0) {
131
		if (rv != 0) {
134
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "error while reading database");
132
			LOG(ERROR, "error while reading database");
135
		} else if ((rv = cache_update_entry_lower(0, dn, &entry)) != MDB_SUCCESS) {
133
		} else if ((rv = cache_update_entry_lower(0, dn, &entry)) != MDB_SUCCESS) {
136
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "error while writing to database");
134
			LOG(ERROR, "error while writing to database");
137
		}
135
		}
138
		cache_free_entry(&dn, &entry);
136
		cache_free_entry(&dn, &entry);
139
		if (rv < -1)
137
		if (rv < -1)
(-)a/management/univention-directory-listener/src/demo.c (-2 lines)
 Lines 35-42    Link Here 
35
#include <unistd.h>
35
#include <unistd.h>
36
#include <string.h>
36
#include <string.h>
37
37
38
#include <univention/debug.h>
39
40
#include "network.h"
38
#include "network.h"
41
#include "common.h"
39
#include "common.h"
42
40
(-)a/management/univention-directory-listener/src/dump.c (-3 / +1 lines)
 Lines 40-47    Link Here 
40
#include <pwd.h>
40
#include <pwd.h>
41
#include <sys/types.h>
41
#include <sys/types.h>
42
42
43
#include <univention/debug.h>
44
45
#include "cache.h"
43
#include "cache.h"
46
#include "common.h"
44
#include "common.h"
47
45
 Lines 120-126   int main(int argc, char *argv[]) { Link Here 
120
		fp = stdout;
118
		fp = stdout;
121
	}
119
	}
122
	if (fp == NULL) {
120
	if (fp == NULL) {
123
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Couldn't open dump file");
121
		LOG(ERROR, "Couldn't open dump file");
124
		exit(1);
122
		exit(1);
125
	}
123
	}
126
	rv = snprintf(cache_mdb_dir, PATH_MAX, "%s/cache", cache_dir);
124
	rv = snprintf(cache_mdb_dir, PATH_MAX, "%s/cache", cache_dir);
(-)a/management/univention-directory-listener/src/handlers.c (-30 / +29 lines)
 Lines 45-51    Link Here 
45
#include <python2.7/compile.h>
45
#include <python2.7/compile.h>
46
#include <python2.7/marshal.h>
46
#include <python2.7/marshal.h>
47
#include <python2.7/node.h>
47
#include <python2.7/node.h>
48
#include <univention/debug.h>
49
48
50
#include "cache_lowlevel.h"
49
#include "cache_lowlevel.h"
51
#include "base64.h"
50
#include "base64.h"
 Lines 81-87   static PyObject *module_import(char *filename) { Link Here 
81
80
82
	if ((fp = fopen(filename, "r")) == NULL)
81
	if ((fp = fopen(filename, "r")) == NULL)
83
		return NULL;
82
		return NULL;
84
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Load file %s", filename);
83
	LOG(ALL, "Load file %s", filename);
85
84
86
	namep = strrchr(filename, '.');
85
	namep = strrchr(filename, '.');
87
	if ((namep != NULL) && (strcmp(namep, ".pyo") == 0)) {
86
	if ((namep != NULL) && (strcmp(namep, ".pyo") == 0)) {
 Lines 95-106   static PyObject *module_import(char *filename) { Link Here 
95
	} else {
94
	} else {
96
		node *n;
95
		node *n;
97
96
98
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Parse file %s", filename);
97
		LOG(ALL, "Parse file %s", filename);
99
		if ((n = PyParser_SimpleParseFile(fp, filename, Py_file_input)) == NULL) {
98
		if ((n = PyParser_SimpleParseFile(fp, filename, Py_file_input)) == NULL) {
100
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Parse failed %s", filename);
99
			LOG(ALL, "Parse failed %s", filename);
101
			return NULL;
100
			return NULL;
102
		}
101
		}
103
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "pyNode compile %s", filename);
102
		LOG(ALL, "pyNode compile %s", filename);
104
		co = PyNode_Compile(n, filename);
103
		co = PyNode_Compile(n, filename);
105
		PyNode_Free(n);
104
		PyNode_Free(n);
106
	}
105
	}
 Lines 112-121   static PyObject *module_import(char *filename) { Link Here 
112
		return NULL;
111
		return NULL;
113
	}
112
	}
114
113
115
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "execCodeModuleEx %s", filename);
114
	LOG(ALL, "execCodeModuleEx %s", filename);
116
	m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, filename);
115
	m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, filename);
117
	free(name);
116
	free(name);
118
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "Module done %s", filename);
117
	LOG(ALL, "Module done %s", filename);
119
118
120
	return m;
119
	return m;
121
}
120
}
 Lines 184-197   static int handler_import(char *filename) { Link Here 
184
	Handler *handler;
183
	Handler *handler;
185
	int rv;
184
	int rv;
186
185
187
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "importing handler %s", filename);
186
	LOG(INFO, "importing handler %s", filename);
188
187
189
	if ((handler = malloc(sizeof(Handler))) == NULL)
188
	if ((handler = malloc(sizeof(Handler))) == NULL)
190
		return 1;
189
		return 1;
191
	memset(handler, 0, sizeof(Handler));
190
	memset(handler, 0, sizeof(Handler));
192
191
193
	if ((handler->module = module_import(filename)) == NULL) {
192
	if ((handler->module = module_import(filename)) == NULL) {
194
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "import of filename=%s failed", filename);
193
		LOG(ERROR, "import of filename=%s failed", filename);
195
		error_msg = "module_import()";
194
		error_msg = "module_import()";
196
		goto error;
195
		goto error;
197
	}
196
	}
 Lines 259-265   static int handler_import(char *filename) { Link Here 
259
	} else {
258
	} else {
260
		rv = fscanf(state_fp, "%u", &handler->state);
259
		rv = fscanf(state_fp, "%u", &handler->state);
261
		if (rv != 1)
260
		if (rv != 1)
262
			univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed reading %s: %s", state_filename, strerror(errno));
261
			LOG(WARN, "Failed reading %s: %s", state_filename, strerror(errno));
263
		fclose(state_fp);
262
		fclose(state_fp);
264
	}
263
	}
265
264
 Lines 304-310   error: Link Here 
304
	free(handler->modrdn);
303
	free(handler->modrdn);
305
	free(handler->name);
304
	free(handler->name);
306
	free(handler);
305
	free(handler);
307
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "import of filename=%s failed in %s", filename, error_msg ? error_msg : "???");
306
	LOG(ERROR, "import of filename=%s failed in %s", filename, error_msg ? error_msg : "???");
308
	return 1;
307
	return 1;
309
}
308
}
310
309
 Lines 329-335   static int handler_prerun(Handler *handler) { Link Here 
329
328
330
/* run postrun handler */
329
/* run postrun handler */
331
static int handler_postrun(Handler *handler) {
330
static int handler_postrun(Handler *handler) {
332
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "postrun handler: %s (prepared=%d)", handler->name, handler->prepared);
331
	LOG(INFO, "%s (prepared=%d)", handler->name, handler->prepared);
333
	if (!handler->prepared)
332
	if (!handler->prepared)
334
		return 0;
333
		return 0;
335
	if (handler->postrun) {
334
	if (handler->postrun) {
 Lines 366-374   static int handler_exec(Handler *handler, const char *dn, CacheEntry *new, Cache Link Here 
366
365
367
	if ((handler->state & HANDLER_READY) != HANDLER_READY) {
366
	if ((handler->state & HANDLER_READY) != HANDLER_READY) {
368
		if (INIT_ONLY) {
367
		if (INIT_ONLY) {
369
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "handler: %s (not ready) (ignore)", handler->name);
368
			LOG(WARN, "%s (not ready) (ignore)", handler->name);
370
		} else {
369
		} else {
371
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "handler: %s (not ready)", handler->name);
370
			LOG(WARN, "%s (not ready)", handler->name);
372
			return 1;
371
			return 1;
373
		}
372
		}
374
	}
373
	}
 Lines 533-539   void handler_write_state(Handler *handler) { Link Here 
533
		abort();
532
		abort();
534
	state_fp = fopen(state_filename, "w");
533
	state_fp = fopen(state_filename, "w");
535
	if (state_fp == NULL) {
534
	if (state_fp == NULL) {
536
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not open %s", state_filename);
535
		LOG(ERROR, "could not open %s", state_filename);
537
	} else {
536
	} else {
538
		fprintf(state_fp, "%d", handler->state);
537
		fprintf(state_fp, "%d", handler->state);
539
		rv = fclose(state_fp);
538
		rv = fclose(state_fp);
 Lines 693-699   static int attribute_has_changed(char **changes, char *attribute) { Link Here 
693
	char **cur;
692
	char **cur;
694
693
695
	for (cur = changes; cur != NULL && *cur != NULL; cur++) {
694
	for (cur = changes; cur != NULL && *cur != NULL; cur++) {
696
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s ? %s", *cur, attribute);
695
		LOG(ALL, "%s ? %s", *cur, attribute);
697
		if (strcmp(*cur, attribute) == 0)
696
		if (strcmp(*cur, attribute) == 0)
698
			return 1;
697
			return 1;
699
	}
698
	}
 Lines 707-713   static int handler__update(Handler *handler, const char *dn, CacheEntry *new, Ca Link Here 
707
	int matched;
706
	int matched;
708
	int rv = 0;
707
	int rv = 0;
709
708
710
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "handler: %s considered", handler->name);
709
	LOG(ALL, "%s considered", handler->name);
711
710
712
	/* check if attributes for handler have changed
711
	/* check if attributes for handler have changed
713
712
 Lines 733-739   static int handler__update(Handler *handler, const char *dn, CacheEntry *new, Ca Link Here 
733
732
734
	up_to_date:
733
	up_to_date:
735
		if (uptodate) {
734
		if (uptodate) {
736
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (up-to-date)", handler->name);
735
			LOG(INFO, "%s (up-to-date)", handler->name);
737
			cache_entry_module_add(new, handler->name);
736
			cache_entry_module_add(new, handler->name);
738
			return 0;
737
			return 0;
739
		}
738
		}
 Lines 742-757   static int handler__update(Handler *handler, const char *dn, CacheEntry *new, Ca Link Here 
742
	/* check if the handler's search filter matches */
741
	/* check if the handler's search filter matches */
743
	matched = cache_entry_ldap_filter_match(handler->filters, dn, new);
742
	matched = cache_entry_ldap_filter_match(handler->filters, dn, new);
744
	if (!matched) {
743
	if (!matched) {
745
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "handler: %s (filter doesn't match)", handler->name);
744
		LOG(ALL, "%s (filter doesn't match)", handler->name);
746
		return 0;
745
		return 0;
747
	}
746
	}
748
747
749
	/* run handler */
748
	/* run handler */
750
	if (handler_exec(handler, dn, new, old, command) == 0) {
749
	if (handler_exec(handler, dn, new, old, command) == 0) {
751
		cache_entry_module_add(new, handler->name);
750
		cache_entry_module_add(new, handler->name);
752
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (successful)", handler->name);
751
		LOG(INFO, "%s (successful)", handler->name);
753
	} else {
752
	} else {
754
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "handler: %s (failed)", handler->name);
753
		LOG(WARN, "%s (failed)", handler->name);
755
		rv = 1;
754
		rv = 1;
756
	}
755
	}
757
756
 Lines 765-771   int handlers_update(const char *dn, CacheEntry *new, CacheEntry *old, char comma Link Here 
765
	char **changes;
764
	char **changes;
766
	int rv = 0;
765
	int rv = 0;
767
766
768
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "running handlers for %s", dn);
767
	LOG(INFO, "running handlers for %s", dn);
769
768
770
	changes = cache_entry_changed_attributes(new, old);
769
	changes = cache_entry_changed_attributes(new, old);
771
770
 Lines 790-796   int handler_update(const char *dn, CacheEntry *new, CacheEntry *old, Handler *ha Link Here 
790
	char **changes;
789
	char **changes;
791
	int rv = 0;
790
	int rv = 0;
792
791
793
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "running handlers [%s] for %s", handler->name, dn);
792
	LOG(INFO, "running handlers [%s] for %s", handler->name, dn);
794
793
795
	changes = cache_entry_changed_attributes(new, old);
794
	changes = cache_entry_changed_attributes(new, old);
796
795
 Lines 807-825   int handlers_delete(const char *dn, CacheEntry *old, char command) { Link Here 
807
	Handler *handler;
806
	Handler *handler;
808
	int rv = 0;
807
	int rv = 0;
809
808
810
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "delete handlers for %s", dn);
809
	LOG(INFO, "delete handlers for %s", dn);
811
810
812
	for (handler = handlers; handler != NULL; handler = handler->next) {
811
	for (handler = handlers; handler != NULL; handler = handler->next) {
813
		/* run the replication handler in any case, see Bug #29475 */
812
		/* run the replication handler in any case, see Bug #29475 */
814
		if (!cache_entry_module_present(old, handler->name) && strcmp(handler->name, "replication")) {
813
		if (!cache_entry_module_present(old, handler->name) && strcmp(handler->name, "replication")) {
815
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (skipped)", handler->name);
814
			LOG(INFO, "%s (skipped)", handler->name);
816
			continue;
815
			continue;
817
		}
816
		}
818
		if (handler_exec(handler, dn, NULL, old, command) == 0) {
817
		if (handler_exec(handler, dn, NULL, old, command) == 0) {
819
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (successful)", handler->name);
818
			LOG(INFO, "%s (successful)", handler->name);
820
			cache_entry_module_remove(old, handler->name);
819
			cache_entry_module_remove(old, handler->name);
821
		} else {
820
		} else {
822
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (failed)", handler->name);
821
			LOG(INFO, "%s (failed)", handler->name);
823
			rv = 1;
822
			rv = 1;
824
		}
823
		}
825
	}
824
	}
 Lines 868-874   int handlers_set_data_all(char *key, char *value) { Link Here 
868
	PyObject *argtuple;
867
	PyObject *argtuple;
869
	__attribute__((unused)) int rv = 1;
868
	__attribute__((unused)) int rv = 1;
870
869
871
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "setting data for all handlers: key=%s  value=%s", key, strcmp("bindpw", key) ? value : "<HIDDEN>");
870
	LOG(INFO, "setting data for all handlers: key=%s  value=%s", key, strcmp("bindpw", key) ? value : "<HIDDEN>");
872
871
873
	/* make argument list */
872
	/* make argument list */
874
	if ((argtuple = PyTuple_New(2)) == NULL)
873
	if ((argtuple = PyTuple_New(2)) == NULL)
 Lines 877-888   int handlers_set_data_all(char *key, char *value) { Link Here 
877
	PyTuple_SetItem(argtuple, 0, PyString_FromString(key));
876
	PyTuple_SetItem(argtuple, 0, PyString_FromString(key));
878
	PyTuple_SetItem(argtuple, 1, PyString_FromString(value));
877
	PyTuple_SetItem(argtuple, 1, PyString_FromString(value));
879
878
880
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "DEBUG: handlers=%p", handlers);
879
	LOG(ALL, "handlers=%p", handlers);
881
	if (handlers == NULL)
880
	if (handlers == NULL)
882
		return 0;
881
		return 0;
883
882
884
	for (handler = handlers; handler != NULL; handler = handler->next) {
883
	for (handler = handlers; handler != NULL; handler = handler->next) {
885
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "DEBUG: handler=%p", handler);
884
		LOG(ALL, "handler=%p", handler);
886
		if (handler_set_data(handler, argtuple) < 0)
885
		if (handler_set_data(handler, argtuple) < 0)
887
			rv = -1;
886
			rv = -1;
888
	}
887
	}
(-)a/management/univention-directory-listener/src/main.c (-27 / +29 lines)
 Lines 42-48    Link Here 
42
#include <pwd.h>
42
#include <pwd.h>
43
#include <sys/types.h>
43
#include <sys/types.h>
44
44
45
#include <univention/debug.h>
46
#include <univention/ldap.h>
45
#include <univention/ldap.h>
47
#include <univention/config.h>
46
#include <univention/config.h>
48
47
 Lines 101-109   static void daemonize(int lock_fd) { Link Here 
101
	fd = open(pidfile, O_WRONLY | O_CREAT | O_EXCL, 0644);
100
	fd = open(pidfile, O_WRONLY | O_CREAT | O_EXCL, 0644);
102
	if (fd < 0) {
101
	if (fd < 0) {
103
		if (errno == EEXIST)
102
		if (errno == EEXIST)
104
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "pidfile %s exists, aborting...%d %s", pidfile, errno, strerror(errno));
103
			LOG(ERROR, "pidfile %s exists, aborting...%d %s", pidfile, errno, strerror(errno));
105
		else
104
		else
106
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Can not create pidfile %s: %s, aborting...", pidfile, strerror(errno));
105
			LOG(ERROR, "Can not create pidfile %s: %s, aborting...", pidfile, strerror(errno));
107
		exit(EXIT_FAILURE);
106
		exit(EXIT_FAILURE);
108
	}
107
	}
109
108
 Lines 146-156   static void daemonize(int lock_fd) { Link Here 
146
			abort();
145
			abort();
147
		rv = write(fd, buf, rv);
146
		rv = write(fd, buf, rv);
148
		if (rv)
147
		if (rv)
149
			univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to write %s: %s", pidfile, strerror(errno));
148
			LOG(WARN, "Failed to write %s: %s", pidfile, strerror(errno));
150
	}
149
	}
151
	rv = close(fd);
150
	rv = close(fd);
152
	if (rv)
151
	if (rv)
153
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close %s: %s", pidfile, strerror(errno));
152
		LOG(WARN, "Failed to close %s: %s", pidfile, strerror(errno));
154
153
155
	// Set new file permissions
154
	// Set new file permissions
156
	umask(0);
155
	umask(0);
 Lines 158-167   static void daemonize(int lock_fd) { Link Here 
158
	// Change the working directory to the root directory
157
	// Change the working directory to the root directory
159
	rv = chdir("/");
158
	rv = chdir("/");
160
	if (rv)
159
	if (rv)
161
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to change directory: %s", strerror(errno));
160
		LOG(WARN, "Failed to change directory: %s", strerror(errno));
162
161
163
	if ((null = open("/dev/null", O_RDWR)) == -1) {
162
	if ((null = open("/dev/null", O_RDWR)) == -1) {
164
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not open /dev/null: %s", strerror(errno));
163
		LOG(ERROR, "could not open /dev/null: %s", strerror(errno));
165
		exit(EXIT_FAILURE);
164
		exit(EXIT_FAILURE);
166
	}
165
	}
167
	dup2(null, STDIN_FILENO);
166
	dup2(null, STDIN_FILENO);
 Lines 170-182   static void daemonize(int lock_fd) { Link Here 
170
		dup2(log, STDERR_FILENO);
169
		dup2(log, STDERR_FILENO);
171
		rv = close(log);
170
		rv = close(log);
172
		if (rv)
171
		if (rv)
173
			univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close /var/log/univention/listener.log: %s", strerror(errno));
172
			LOG(WARN, "Failed to close /var/log/univention/listener.log: %s", strerror(errno));
174
	} else {
173
	} else {
175
		dup2(null, STDERR_FILENO);
174
		dup2(null, STDERR_FILENO);
176
	}
175
	}
177
	rv = close(null);
176
	rv = close(null);
178
	if (rv)
177
	if (rv)
179
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close /dev/null: %s", strerror(errno));
178
		LOG(WARN, "Failed to close /dev/null: %s", strerror(errno));
180
179
181
	// Close all open file descriptors
180
	// Close all open file descriptors
182
	for (fd = sysconf(_SC_OPEN_MAX); fd > STDERR_FILENO; fd--)
181
	for (fd = sysconf(_SC_OPEN_MAX); fd > STDERR_FILENO; fd--)
 Lines 192-207   void drop_privileges(void) { Link Here 
192
		return;
191
		return;
193
192
194
	if ((listener_user = getpwnam("listener")) == NULL) {
193
	if ((listener_user = getpwnam("listener")) == NULL) {
195
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get passwd entry for listener");
194
		LOG(ERROR, "failed to get passwd entry for listener");
196
		exit(1);
195
		exit(1);
197
	}
196
	}
198
197
199
	if (setegid(listener_user->pw_gid) != 0) {
198
	if (setegid(listener_user->pw_gid) != 0) {
200
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to change to listener gid");
199
		LOG(ERROR, "failed to change to listener gid");
201
		exit(1);
200
		exit(1);
202
	}
201
	}
203
	if (seteuid(listener_user->pw_uid) != 0) {
202
	if (seteuid(listener_user->pw_uid) != 0) {
204
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to change to listener uid");
203
		LOG(ERROR, "failed to change to listener uid");
205
		exit(1);
204
		exit(1);
206
	}
205
	}
207
}
206
}
 Lines 240-246   static void purge_cache(const char *cache_dir) { Link Here 
240
	char dirname[PATH_MAX];
239
	char dirname[PATH_MAX];
241
	int rv;
240
	int rv;
242
241
243
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "purging cache");
242
	LOG(INFO, "purging cache");
244
	if ((dir = opendir(cache_dir)) != NULL) {
243
	if ((dir = opendir(cache_dir)) != NULL) {
245
		while ((dirent = readdir(dir))) {
244
		while ((dirent = readdir(dir))) {
246
			char path[PATH_MAX];
245
			char path[PATH_MAX];
 Lines 316-322   static int do_connection(univention_ldap_parameters_t *lp) { Link Here 
316
	int sizelimit0 = 0;
315
	int sizelimit0 = 0;
317
316
318
	if (univention_ldap_open(lp) != LDAP_SUCCESS) {
317
	if (univention_ldap_open(lp) != LDAP_SUCCESS) {
319
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "can not connect to LDAP server %s:%d", lp->host, lp->port);
318
		LOG(WARN, "can not connect to LDAP server %s:%d", lp->host, lp->port);
320
		goto fail;
319
		goto fail;
321
	}
320
	}
322
	if (notifier_client_new(NULL, lp->host, 1) != 0)
321
	if (notifier_client_new(NULL, lp->host, 1) != 0)
 Lines 329-338   static int do_connection(univention_ldap_parameters_t *lp) { Link Here 
329
	case LDAP_SUCCESS:
328
	case LDAP_SUCCESS:
330
		return 0;
329
		return 0;
331
	case LDAP_NO_SUCH_OBJECT:
330
	case LDAP_NO_SUCH_OBJECT:
332
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Failed to find \"(objectClass=univentionBase)\" on LDAP server %s:%d", lp->host, lp->port);
331
		LOG(ERROR, "Failed to find \"(objectClass=univentionBase)\" on LDAP server %s:%d", lp->host, lp->port);
333
		break;
332
		break;
334
	default:
333
	default:
335
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Failed to search for \"(objectClass=univentionBase)\" on LDAP server %s:%d with message %s", lp->host, lp->port, ldap_err2string(rc));
334
		LOG(ERROR, "Failed to search for \"(objectClass=univentionBase)\" on LDAP "
335
		           "server %s:%d with message %s",
336
		    lp->host, lp->port, ldap_err2string(rc));
336
		break;
337
		break;
337
	}
338
	}
338
fail:
339
fail:
 Lines 483-488   int main(int argc, char *argv[]) { Link Here 
483
	}
484
	}
484
485
485
	univention_debug_set_level(UV_DEBUG_LISTENER, debugging);
486
	univention_debug_set_level(UV_DEBUG_LISTENER, debugging);
487
	univention_debug_set_level(UV_DEBUG_TRANSFILE, debugging);
486
	univention_debug_set_level(UV_DEBUG_LDAP, debugging);
488
	univention_debug_set_level(UV_DEBUG_LDAP, debugging);
487
489
488
	{
490
	{
 Lines 491-497   int main(int argc, char *argv[]) { Link Here 
491
		if (rv < 0 || rv >= PATH_MAX)
493
		if (rv < 0 || rv >= PATH_MAX)
492
			abort();
494
			abort();
493
		if (stat(filename, &stbuf) == 0) {
495
		if (stat(filename, &stbuf) == 0) {
494
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Corrupt cache");
496
			LOG(ERROR, "Corrupt cache");
495
			exit(3);
497
			exit(3);
496
		}
498
		}
497
	}
499
	}
 Lines 513-536   int main(int argc, char *argv[]) { Link Here 
513
	/* choose server to connect to */
515
	/* choose server to connect to */
514
	if (lp->host == NULL && lp->uri == NULL) {
516
	if (lp->host == NULL && lp->uri == NULL) {
515
		select_server(lp);
517
		select_server(lp);
516
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "no server given, choosing one by myself (%s)", lp->host);
518
		LOG(INFO, "no server given, choosing one by myself (%s)", lp->host);
517
	}
519
	}
518
520
519
	while (do_connection(lp) != 0) {
521
	while (do_connection(lp) != 0) {
520
		if (suspend_connect()) {
522
		if (suspend_connect()) {
521
			if (initialize_only) {
523
			if (initialize_only) {
522
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "can not connect any server, exit");
524
				LOG(ERROR, "can not connect any server, exit");
523
				exit(1);
525
				exit(1);
524
			}
526
			}
525
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "can not connect any server, retrying in 30 seconds");
527
			LOG(WARN, "can not connect any server, retrying in 30 seconds");
526
			sleep(30);
528
			sleep(30);
527
		}
529
		}
528
530
529
		select_server(lp);
531
		select_server(lp);
530
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "chosen server: %s:%d", lp->host, lp->port);
532
		LOG(WARN, "chosen server: %s:%d", lp->host, lp->port);
531
	}
533
	}
532
534
533
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "connection okay to host %s:%d", lp->host, lp->port);
535
	LOG(INFO, "connection okay to host %s:%d", lp->host, lp->port);
534
536
535
	/* connect to local LDAP server */
537
	/* connect to local LDAP server */
536
	server_role = univention_config_get_string("server/role");
538
	server_role = univention_config_get_string("server/role");
 Lines 566-572   int main(int argc, char *argv[]) { Link Here 
566
		handlers_set_data_all("ldapserver", lp->host);
568
		handlers_set_data_all("ldapserver", lp->host);
567
569
568
	if (notifier_get_id_s(NULL, &id) != 0) {
570
	if (notifier_get_id_s(NULL, &id) != 0) {
569
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to receive current ID");
571
		LOG(ERROR, "failed to receive current ID");
570
		return 1;
572
		return 1;
571
	}
573
	}
572
574
 Lines 581-587   int main(int argc, char *argv[]) { Link Here 
581
		if (cache_master_entry.id == -1) {
583
		if (cache_master_entry.id == -1) {
582
			rv = notifier_get_id_s(NULL, &cache_master_entry.id);
584
			rv = notifier_get_id_s(NULL, &cache_master_entry.id);
583
			if (rv != 0) {
585
			if (rv != 0) {
584
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to receive current ID");
586
				LOG(ERROR, "failed to receive current ID");
585
				return 1;
587
				return 1;
586
			}
588
			}
587
		}
589
		}
 Lines 594-600   int main(int argc, char *argv[]) { Link Here 
594
		return rv;
596
		return rv;
595
	/* Legacy file for Nagios et al. */
597
	/* Legacy file for Nagios et al. */
596
	if (cache_set_int("notifier_id", cache_master_entry.id))
598
	if (cache_set_int("notifier_id", cache_master_entry.id))
597
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "failed to write notifier ID");
599
		LOG(WARN, "failed to write notifier ID");
598
600
599
	/* update schema */
601
	/* update schema */
600
	if ((rv = change_update_schema(lp)) != LDAP_SUCCESS)
602
	if ((rv = change_update_schema(lp)) != LDAP_SUCCESS)
 Lines 602-608   int main(int argc, char *argv[]) { Link Here 
602
604
603
	/* do initial import of entries */
605
	/* do initial import of entries */
604
	if ((rv = change_new_modules(lp)) != LDAP_SUCCESS) {
606
	if ((rv = change_new_modules(lp)) != LDAP_SUCCESS) {
605
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "change_new_modules: %s", ldap_err2string(rv));
607
		LOG(ERROR, "change_new_modules: %s", ldap_err2string(rv));
606
		return rv;
608
		return rv;
607
	}
609
	}
608
	signals_unblock();
610
	signals_unblock();
 Lines 612-618   int main(int argc, char *argv[]) { Link Here 
612
	}
614
	}
613
615
614
	if (rv != 0)
616
	if (rv != 0)
615
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "listener: %d", rv);
617
		LOG(ERROR, "listener: %d", rv);
616
618
617
	univention_ldap_close(lp);
619
	univention_ldap_close(lp);
618
	univention_ldap_close(lp_local);
620
	univention_ldap_close(lp_local);
(-)a/management/univention-directory-listener/src/network.c (-27 / +26 lines)
 Lines 51-57    Link Here 
51
#include <sys/stat.h>
51
#include <sys/stat.h>
52
#include <errno.h>
52
#include <errno.h>
53
53
54
#include <univention/debug.h>
55
#include <univention/config.h>
54
#include <univention/config.h>
56
55
57
#include "common.h"
56
#include "common.h"
 Lines 109-115   static int parse_entry(const char *line, NotifierEntry *entry) { Link Here 
109
108
110
/* Send buffer in blocking mode. */
109
/* Send buffer in blocking mode. */
111
static int send_block(NotifierClient *client, const char *buf, size_t len) {
110
static int send_block(NotifierClient *client, const char *buf, size_t len) {
112
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, ">>>%s", buf);
111
	LOG(ALL, ">>>%s", buf);
113
	return write(client->fd, buf, len);
112
	return write(client->fd, buf, len);
114
}
113
}
115
114
 Lines 137-155   static int recv_block(NotifierClient *client, char **back, time_t timeout) { Link Here 
137
	while (result == NULL || (pos = strstr(result, "\n\n")) == NULL) {
136
	while (result == NULL || (pos = strstr(result, "\n\n")) == NULL) {
138
		ssize_t r;
137
		ssize_t r;
139
138
140
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "RESULT: [%s]", result);
139
		LOG(ALL, "RESULT: [%s]", result);
141
		if ((rv = notifier_wait(client, timeout)) == 0) {
140
		if ((rv = notifier_wait(client, timeout)) == 0) {
142
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "timeout when receiving data");
141
			LOG(ERROR, "timeout when receiving data");
143
			return 0;
142
			return 0;
144
		} else if (rv < 0)
143
		} else if (rv < 0)
145
			return 0;
144
			return 0;
146
145
147
		r = read(client->fd, buf, BUFSIZ);
146
		r = read(client->fd, buf, BUFSIZ);
148
		if (r == 0) {
147
		if (r == 0) {
149
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "connection to notifier was closed");
148
			LOG(ERROR, "connection to notifier was closed");
150
			return 0;
149
			return 0;
151
		} else if (r < 0) {
150
		} else if (r < 0) {
152
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "error %d: %s while receiving from notifier", errno, strerror(errno));
151
			LOG(ERROR, "error %d: %s while receiving from notifier", errno, strerror(errno));
153
			return 0;
152
			return 0;
154
		}
153
		}
155
154
 Lines 170-176   static int recv_block(NotifierClient *client, char **back, time_t timeout) { Link Here 
170
		client->buf = NULL;
169
		client->buf = NULL;
171
	}
170
	}
172
171
173
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "<<<%s", *back);
172
	LOG(ALL, "<<<%s", *back);
174
	return strlen(*back);
173
	return strlen(*back);
175
}
174
}
176
175
 Lines 201-207   int notifier_recv_result(NotifierClient *client, time_t timeout) { Link Here 
201
	assert(client->fd > -1);
200
	assert(client->fd > -1);
202
201
203
	if ((rv = notifier_wait(client, timeout)) == 0) {
202
	if ((rv = notifier_wait(client, timeout)) == 0) {
204
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "no data is available (i.e. timeout elapsed)");
203
		LOG(WARN, "no data is available (i.e. timeout elapsed)");
205
		return 0;
204
		return 0;
206
	} else if (rv < 0)
205
	} else if (rv < 0)
207
		return 0;
206
		return 0;
 Lines 319-325   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
319
		client = &global_client;
318
		client = &global_client;
320
319
321
	if (starttls >= 2) {
320
	if (starttls >= 2) {
322
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "This version does not support TLS");
321
		LOG(ERROR, "This version does not support TLS");
323
		return 1;
322
		return 1;
324
	}
323
	}
325
324
 Lines 352-362   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
352
	address6.sin6_family = AF_INET6;
351
	address6.sin6_family = AF_INET6;
353
	address6.sin6_port = htons(NOTIFIER_PORT_PROTOCOL2);
352
	address6.sin6_port = htons(NOTIFIER_PORT_PROTOCOL2);
354
353
355
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "connecting to notifier %s:%d", client->server, NOTIFIER_PORT_PROTOCOL2);
354
	LOG(INFO, "connecting to notifier %s:%d", client->server, NOTIFIER_PORT_PROTOCOL2);
356
355
357
	err = getaddrinfo(client->server, NULL, &hints, &result_addrinfo);
356
	err = getaddrinfo(client->server, NULL, &hints, &result_addrinfo);
358
	if (err != 0) {
357
	if (err != 0) {
359
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "address resolution of %s failed with errorcode %d: %s", client->server, err, gai_strerror(err));
358
		LOG(WARN, "address resolution of %s failed with errorcode %d: %s", client->server, err, gai_strerror(err));
360
		free(client->server);
359
		free(client->server);
361
		client->server = NULL;
360
		client->server = NULL;
362
		return 1;
361
		return 1;
 Lines 367-373   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
367
		switch (res->ai_family) {
366
		switch (res->ai_family) {
368
		case AF_INET:
367
		case AF_INET:
369
			if ((client->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
368
			if ((client->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
370
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "creating IPv4 socket descriptor failed with errorcode %d: %s", errno, strerror(errno));
369
				LOG(WARN, "creating IPv4 socket descriptor failed with errorcode %d: %s", errno, strerror(errno));
371
				continue;
370
				continue;
372
			}
371
			}
373
			memcpy(&address4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(address4.sin_addr));
372
			memcpy(&address4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(address4.sin_addr));
 Lines 379-385   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
379
378
380
		case AF_INET6:
379
		case AF_INET6:
381
			if ((client->fd = socket(AF_INET6, SOCK_STREAM, 0)) == -1) {
380
			if ((client->fd = socket(AF_INET6, SOCK_STREAM, 0)) == -1) {
382
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "creating IPv6 socket descriptor failed with errorcode %d: %s", errno, strerror(errno));
381
				LOG(WARN, "creating IPv6 socket descriptor failed with errorcode %d: %s", errno, strerror(errno));
383
				continue;
382
				continue;
384
			}
383
			}
385
			memcpy(&address6.sin6_addr, &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr, sizeof(address6.sin6_addr));
384
			memcpy(&address6.sin6_addr, &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr, sizeof(address6.sin6_addr));
 Lines 401-431   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
401
			int ret;
400
			int ret;
402
			ret = setsockopt(client->fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
401
			ret = setsockopt(client->fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
403
			if (ret < 0)
402
			if (ret < 0)
404
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Failed to set SO_RCVTIMEO");
403
				LOG(WARN, "Failed to set SO_RCVTIMEO");
405
			ret = setsockopt(client->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
404
			ret = setsockopt(client->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
406
			if (ret < 0)
405
			if (ret < 0)
407
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Failed to set SO_SNDTIMEO");
406
				LOG(WARN, "Failed to set SO_SNDTIMEO");
408
407
409
			const int enable = 1;
408
			const int enable = 1;
410
			ret = setsockopt(client->fd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable));
409
			ret = setsockopt(client->fd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable));
411
			if (ret < 0)
410
			if (ret < 0)
412
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Failed to enable TCP KEEPALIVE");
411
				LOG(WARN, "Failed to enable TCP KEEPALIVE");
413
			const int idle = 60;
412
			const int idle = 60;
414
			ret = setsockopt(client->fd, SOL_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
413
			ret = setsockopt(client->fd, SOL_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
415
			if (ret < 0)
414
			if (ret < 0)
416
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Failed to set TCP_KEEPIDLE");
415
				LOG(WARN, "Failed to set TCP_KEEPIDLE");
417
			const int probes = 12;
416
			const int probes = 12;
418
			ret = setsockopt(client->fd, SOL_TCP, TCP_KEEPCNT, &probes, sizeof(probes));
417
			ret = setsockopt(client->fd, SOL_TCP, TCP_KEEPCNT, &probes, sizeof(probes));
419
			if (ret < 0)
418
			if (ret < 0)
420
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Failed to set TCP_KEEPCNT");
419
				LOG(WARN, "Failed to set TCP_KEEPCNT");
421
			const int interval = 5;
420
			const int interval = 5;
422
			ret = setsockopt(client->fd, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
421
			ret = setsockopt(client->fd, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof(interval));
423
			if (ret < 0)
422
			if (ret < 0)
424
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "Failed to set TCP_KEEPINTVL");
423
				LOG(WARN, "Failed to set TCP_KEEPINTVL");
425
		}
424
		}
426
425
427
		if (connect(client->fd, address, addrlen) == -1) {
426
		if (connect(client->fd, address, addrlen) == -1) {
428
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "connection to %s failed with errorcode %d: %s", addrstr, errno, strerror(errno));
427
			LOG(INFO, "connection to %s failed with errorcode %d: %s", addrstr, errno, strerror(errno));
429
			close(client->fd);
428
			close(client->fd);
430
			client->fd = -1;
429
			client->fd = -1;
431
			continue;
430
			continue;
 Lines 435-460   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
435
	freeaddrinfo(result_addrinfo);
434
	freeaddrinfo(result_addrinfo);
436
435
437
	if (client->fd == -1) {
436
	if (client->fd == -1) {
438
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to connect to any notifier");
437
		LOG(ERROR, "failed to connect to any notifier");
439
		free(client->server);
438
		free(client->server);
440
		client->server = NULL;
439
		client->server = NULL;
441
		return 2;
440
		return 2;
442
	}
441
	}
443
442
444
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "established connection to %s port %d", addrstr, NOTIFIER_PORT_PROTOCOL2);
443
	LOG(INFO, "established connection to %s port %d", addrstr, NOTIFIER_PORT_PROTOCOL2);
445
444
446
	const char *header = "Version: 2\nCapabilities: \n\n";
445
	const char *header = "Version: 2\nCapabilities: \n\n";
447
	const size_t len = strlen(header);
446
	const size_t len = strlen(header);
448
	char *result, *tok;
447
	char *result, *tok;
449
448
450
	if (send_block(client, header, len) != len) {
449
	if (send_block(client, header, len) != len) {
451
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "couldn't send header");
450
		LOG(ERROR, "couldn't send header");
452
		free(client->server);
451
		free(client->server);
453
		client->server = NULL;
452
		client->server = NULL;
454
		return 1;
453
		return 1;
455
	}
454
	}
456
	if (recv_block(client, &result, NOTIFIER_TIMEOUT) < 1) {
455
	if (recv_block(client, &result, NOTIFIER_TIMEOUT) < 1) {
457
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "couldn't receive header");
456
		LOG(ERROR, "couldn't receive header");
458
		free(client->server);
457
		free(client->server);
459
		client->server = NULL;
458
		client->server = NULL;
460
		return 1;
459
		return 1;
 Lines 464-470   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
464
	for (tok = strtok(result, "\n"); tok != NULL; tok = strtok(NULL, "\n")) {
463
	for (tok = strtok(result, "\n"); tok != NULL; tok = strtok(NULL, "\n")) {
465
		char *val;
464
		char *val;
466
		if ((val = strchr(tok, ':')) == NULL) {
465
		if ((val = strchr(tok, ':')) == NULL) {
467
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ignoring bad header: [%s]", tok);
466
			LOG(ERROR, "ignoring bad header: [%s]", tok);
468
			continue;
467
			continue;
469
		}
468
		}
470
		*val++ = '\0';
469
		*val++ = '\0';
 Lines 479-485   int notifier_client_new(NotifierClient *client, const char *server, int starttls Link Here 
479
	free(result);
478
	free(result);
480
479
481
	if (client->protocol != 2) {
480
	if (client->protocol != 2) {
482
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Protocol version %d is not supported", client->protocol);
481
		LOG(ERROR, "Protocol version %d is not supported", client->protocol);
483
		free(client->server);
482
		free(client->server);
484
		client->server = NULL;
483
		client->server = NULL;
485
		return 1;
484
		return 1;
 Lines 523-529   int notifier_wait(NotifierClient *client, time_t timeout) { Link Here 
523
		}
522
		}
524
	} while (rv == -1 && errno == EINTR);
523
	} while (rv == -1 && errno == EINTR);
525
	if (rv == -1) {
524
	if (rv == -1) {
526
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "select: %s", strerror(errno));
525
		LOG(ERROR, "select: %s", strerror(errno));
527
	}
526
	}
528
527
529
	return rv;
528
	return rv;
(-)a/management/univention-directory-listener/src/notifier.c (-15 / +14 lines)
 Lines 46-52    Link Here 
46
#include <sys/time.h>
46
#include <sys/time.h>
47
#include <sys/statvfs.h>
47
#include <sys/statvfs.h>
48
48
49
#include <univention/debug.h>
50
#include <univention/config.h>
49
#include <univention/config.h>
51
#include <univention/ldap.h>
50
#include <univention/ldap.h>
52
51
 Lines 66-80    Link Here 
66
65
67
static int connect_to_ldap(univention_ldap_parameters_t *lp) {
66
static int connect_to_ldap(univention_ldap_parameters_t *lp) {
68
	while (univention_ldap_open(lp) != LDAP_SUCCESS) {
67
	while (univention_ldap_open(lp) != LDAP_SUCCESS) {
69
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "can not connect to ldap server (%s)", lp->host);
68
		LOG(WARN, "can not connect to ldap server (%s)", lp->host);
70
69
71
		if (suspend_connect()) {
70
		if (suspend_connect()) {
72
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "can not connect to any ldap server, retrying in 30 seconds");
71
			LOG(WARN, "can not connect to any ldap server, retrying in 30 seconds");
73
			sleep(30);
72
			sleep(30);
74
		}
73
		}
75
74
76
		select_server(lp);
75
		select_server(lp);
77
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "chosen server: %s:%d", lp->host, lp->port);
76
		LOG(WARN, "chosen server: %s:%d", lp->host, lp->port);
78
	}
77
	}
79
78
80
	return LDAP_SUCCESS;
79
	return LDAP_SUCCESS;
 Lines 101-107   static void check_free_space() { Link Here 
101
		if (free_mib >= min_mib)
100
		if (free_mib >= min_mib)
102
			continue;
101
			continue;
103
102
104
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "File system '%s' full: %" PRId64 " < %" PRId64, *dirname, free_mib, min_mib);
103
		LOG(ERROR, "File system '%s' full: %" PRId64 " < %" PRId64, *dirname, free_mib, min_mib);
105
		abort();
104
		abort();
106
	}
105
	}
107
}
106
}
 Lines 120-126   int notifier_listen(univention_ldap_parameters_t *lp, bool write_transaction_fil Link Here 
120
119
121
		check_free_space();
120
		check_free_space();
122
121
123
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "Last Notifier ID: %lu", id);
122
		LOG(INFO, "Last Notifier ID: %lu", id);
124
		if ((msgid = notifier_get_dn(NULL, id + 1)) < 1)
123
		if ((msgid = notifier_get_dn(NULL, id + 1)) < 1)
125
			break;
124
			break;
126
125
 Lines 132-138   int notifier_listen(univention_ldap_parameters_t *lp, bool write_transaction_fil Link Here 
132
			if ((rv = notifier_wait(NULL, timeout)) == 0) {
131
			if ((rv = notifier_wait(NULL, timeout)) == 0) {
133
				if (timeout == DELAY_ALIVE) {
132
				if (timeout == DELAY_ALIVE) {
134
					if (notifier_alive_s(NULL) == 1) {
133
					if (notifier_alive_s(NULL) == 1) {
135
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get alive answer");
134
						LOG(ERROR, "failed to get alive answer");
136
						return 1;
135
						return 1;
137
					}
136
					}
138
					notifier_resend_get_dn(NULL, msgid, id + 1);
137
					notifier_resend_get_dn(NULL, msgid, id + 1);
 Lines 145-157   int notifier_listen(univention_ldap_parameters_t *lp, bool write_transaction_fil Link Here 
145
						ldap_unbind_ext(trans.lp_local->ld, NULL, NULL);
144
						ldap_unbind_ext(trans.lp_local->ld, NULL, NULL);
146
						trans.lp_local->ld = NULL;
145
						trans.lp_local->ld = NULL;
147
					}
146
					}
148
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "running postrun handlers");
147
					LOG(INFO, "running postrun handlers");
149
					handlers_postrun_all();
148
					handlers_postrun_all();
150
					timeout = DELAY_ALIVE;
149
					timeout = DELAY_ALIVE;
151
				}
150
				}
152
				continue;
151
				continue;
153
			} else if (rv > 0 && notifier_recv_result(NULL, NOTIFIER_TIMEOUT) == 0) {
152
			} else if (rv > 0 && notifier_recv_result(NULL, NOTIFIER_TIMEOUT) == 0) {
154
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to recv result");
153
				LOG(ERROR, "failed to recv result");
155
				return 1;
154
				return 1;
156
			} else if (rv < 0) {
155
			} else if (rv < 0) {
157
				return 1;
156
				return 1;
 Lines 160-172   int notifier_listen(univention_ldap_parameters_t *lp, bool write_transaction_fil Link Here 
160
159
161
		memset(&trans.cur, 0, sizeof(trans.cur));
160
		memset(&trans.cur, 0, sizeof(trans.cur));
162
		if (notifier_get_dn_result(NULL, msgid, &trans.cur.notify) != 0) {
161
		if (notifier_get_dn_result(NULL, msgid, &trans.cur.notify) != 0) {
163
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to get dn result");
162
			LOG(ERROR, "failed to get dn result");
164
			return 1;
163
			return 1;
165
		}
164
		}
166
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "notifier returned = id: %ld\tdn: %s\tcmd: %c", trans.cur.notify.id, trans.cur.notify.dn, trans.cur.notify.command);
165
		LOG(INFO, "notifier returned = id: %ld\tdn: %s\tcmd: %c", trans.cur.notify.id, trans.cur.notify.dn, trans.cur.notify.command);
167
166
168
		if (trans.cur.notify.id != id + 1) {
167
		if (trans.cur.notify.id != id + 1) {
169
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "notifier returned transaction id %ld (%ld expected)", trans.cur.notify.id, id + 1);
168
			LOG(ERROR, "notifier returned transaction id %ld (%ld expected)", trans.cur.notify.id, id + 1);
170
			rv = 1;
169
			rv = 1;
171
			goto out;
170
			goto out;
172
		}
171
		}
 Lines 175-181   int notifier_listen(univention_ldap_parameters_t *lp, bool write_transaction_fil Link Here 
175
		/* ensure that LDAP connection is open */
174
		/* ensure that LDAP connection is open */
176
		if (trans.lp->ld == NULL) {
175
		if (trans.lp->ld == NULL) {
177
			if ((rv = connect_to_ldap(trans.lp)) != 0) {
176
			if ((rv = connect_to_ldap(trans.lp)) != 0) {
178
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to connect to LDAP");
177
				LOG(ERROR, "failed to connect to LDAP");
179
				goto out;
178
				goto out;
180
			}
179
			}
181
		}
180
		}
 Lines 183-189   int notifier_listen(univention_ldap_parameters_t *lp, bool write_transaction_fil Link Here 
183
		/* Try to do the change. If the LDAP server is down, try
182
		/* Try to do the change. If the LDAP server is down, try
184
		   to reconnect */
183
		   to reconnect */
185
		while ((rv = change_update_dn(&trans)) != LDAP_SUCCESS) {
184
		while ((rv = change_update_dn(&trans)) != LDAP_SUCCESS) {
186
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "change_update_dn failed: %d", rv);
185
			LOG(ERROR, "change_update_dn failed: %d", rv);
187
			if (rv == LDAP_SERVER_DOWN)
186
			if (rv == LDAP_SERVER_DOWN)
188
				if ((rv = connect_to_ldap(trans.lp)) == 0)
187
				if ((rv = connect_to_ldap(trans.lp)) == 0)
189
					continue;
188
					continue;
 Lines 211-217   int notifier_listen(univention_ldap_parameters_t *lp, bool write_transaction_fil Link Here 
211
		cache_master_entry.id = id;
210
		cache_master_entry.id = id;
212
		cache_update_master_entry(&cache_master_entry);
211
		cache_update_master_entry(&cache_master_entry);
213
		if (cache_set_int("notifier_id", id))
212
		if (cache_set_int("notifier_id", id))
214
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "failed to write notifier ID");
213
			LOG(WARN, "failed to write notifier ID");
215
		change_free_transaction_op(&trans.cur);
214
		change_free_transaction_op(&trans.cur);
216
	}
215
	}
217
216
(-)a/management/univention-directory-listener/src/select_server.c (-7 / +7 lines)
 Lines 35-41    Link Here 
35
#include <stdlib.h>
35
#include <stdlib.h>
36
#include <time.h>
36
#include <time.h>
37
#include "select_server.h"
37
#include "select_server.h"
38
#include <univention/debug.h>
38
#include "common.h"
39
#include <univention/ldap.h>
39
#include <univention/ldap.h>
40
#include <univention/config.h>
40
#include <univention/config.h>
41
41
 Lines 119-128   void select_server(univention_ldap_parameters_t *lp) { Link Here 
119
				if (!name[0])
119
				if (!name[0])
120
					continue;
120
					continue;
121
				server_list[server_list_entries++].server_name = strdup(name);
121
				server_list[server_list_entries++].server_name = strdup(name);
122
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "Backup found: %s", name);
122
				LOG(INFO, "Backup found: %s", name);
123
			}
123
			}
124
			if (server_list_entries >= ARRAY_SIZE(server_list))
124
			if (server_list_entries >= ARRAY_SIZE(server_list))
125
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Too many (more than %zd) backup-servers found", ARRAY_SIZE(server_list));
125
				LOG(ERROR, "Too many (more than %zd) backup-servers found", ARRAY_SIZE(server_list));
126
			/* Append notifier on DC Master unless explicitly disabled */
126
			/* Append notifier on DC Master unless explicitly disabled */
127
			if (server_list_entries < ARRAY_SIZE(server_list) && !backup_notifier)
127
			if (server_list_entries < ARRAY_SIZE(server_list) && !backup_notifier)
128
				server_list[server_list_entries++].server_name = strdup(ldap_master);
128
				server_list[server_list_entries++].server_name = strdup(ldap_master);
 Lines 139-148   void select_server(univention_ldap_parameters_t *lp) { Link Here 
139
			if (!seed) {
139
			if (!seed) {
140
				seed = getpid() * time(NULL);
140
				seed = getpid() * time(NULL);
141
				srandom(seed);
141
				srandom(seed);
142
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "rands with seed %ud ", seed);
142
				LOG(INFO, "rands with seed %ud ", seed);
143
			}
143
			}
144
			int randval = random() % server_list_entries;
144
			int randval = random() % server_list_entries;
145
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "randval = %d ", randval);
145
			LOG(INFO, "randval = %d ", randval);
146
146
147
			// server_list[randval].conn_attemp++;
147
			// server_list[randval].conn_attemp++;
148
			lp->host = strdup(server_list[randval].server_name);
148
			lp->host = strdup(server_list[randval].server_name);
 Lines 155-161   void select_server(univention_ldap_parameters_t *lp) { Link Here 
155
					lp->port = backup_port;
155
					lp->port = backup_port;
156
			}
156
			}
157
		} else {
157
		} else {
158
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "No Backup found, server is ldap/master");
158
			LOG(INFO, "No Backup found, server is ldap/master");
159
			lp->host = strdup(ldap_master);
159
			lp->host = strdup(ldap_master);
160
			if (ldap_master_port > 0)
160
			if (ldap_master_port > 0)
161
				lp->port = ldap_master_port;
161
				lp->port = ldap_master_port;
 Lines 166-170   result: Link Here 
166
	free(ldap_master);
166
	free(ldap_master);
167
	free(server_role);
167
	free(server_role);
168
168
169
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "LDAP-Server is %s:%d", lp->host, lp->port);
169
	LOG(INFO, "LDAP-Server is %s:%d", lp->host, lp->port);
170
}
170
}
(-)a/management/univention-directory-listener/src/signals.c (-11 / +9 lines)
 Lines 38-45    Link Here 
38
#include <stdio.h>
38
#include <stdio.h>
39
#include <unistd.h>
39
#include <unistd.h>
40
40
41
#include <univention/debug.h>
42
43
#include "handlers.h"
41
#include "handlers.h"
44
#include "cache.h"
42
#include "cache.h"
45
#include "common.h"
43
#include "common.h"
 Lines 52-58   sigset_t block_mask; Link Here 
52
void signals_block(void) {
50
void signals_block(void) {
53
	static int init_done = 0;
51
	static int init_done = 0;
54
52
55
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "blocking signals (was %d)", sig_block_count);
53
	LOG(ALL, "blocking signals (was %d)", sig_block_count);
56
	if ((++sig_block_count) != 1)
54
	if ((++sig_block_count) != 1)
57
		return;
55
		return;
58
56
 Lines 72-78   void signals_block(void) { Link Here 
72
}
70
}
73
71
74
void signals_unblock(void) {
72
void signals_unblock(void) {
75
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "unblocking signals (was %d)", sig_block_count);
73
	LOG(ALL, "unblocking signals (was %d)", sig_block_count);
76
	if ((--sig_block_count) != 0)
74
	if ((--sig_block_count) != 0)
77
		return;
75
		return;
78
	sigprocmask(SIG_UNBLOCK, &block_mask, NULL);
76
	sigprocmask(SIG_UNBLOCK, &block_mask, NULL);
 Lines 80-100   void signals_unblock(void) { Link Here 
80
78
81
79
82
void sig_usr1_handler(int sig) {
80
void sig_usr1_handler(int sig) {
83
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "received signal %d", sig);
81
	LOG(WARN, "received signal %d", sig);
84
	int loglevel = univention_debug_get_level(UV_DEBUG_LISTENER);
82
	int loglevel = univention_debug_get_level(UV_DEBUG_LISTENER);
85
	if (loglevel < UV_DEBUG_ALL) {
83
	if (loglevel < UV_DEBUG_ALL) {
86
		loglevel += 1;
84
		loglevel += 1;
87
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "increasing univention_debug_level to %d", loglevel);
85
		LOG(WARN, "increasing univention_debug_level to %d", loglevel);
88
		univention_debug_set_level(UV_DEBUG_LISTENER, loglevel);
86
		univention_debug_set_level(UV_DEBUG_LISTENER, loglevel);
89
	}
87
	}
90
}
88
}
91
89
92
void sig_usr2_handler(int sig) {
90
void sig_usr2_handler(int sig) {
93
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "received signal %d", sig);
91
	LOG(WARN, "received signal %d", sig);
94
	int loglevel = univention_debug_get_level(UV_DEBUG_LISTENER);
92
	int loglevel = univention_debug_get_level(UV_DEBUG_LISTENER);
95
	if (loglevel > UV_DEBUG_ERROR) {
93
	if (loglevel > UV_DEBUG_ERROR) {
96
		loglevel -= 1;
94
		loglevel -= 1;
97
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "decreasing univention_debug_level to %d", loglevel);
95
		LOG(WARN, "decreasing univention_debug_level to %d", loglevel);
98
		univention_debug_set_level(UV_DEBUG_LISTENER, loglevel);
96
		univention_debug_set_level(UV_DEBUG_LISTENER, loglevel);
99
	}
97
	}
100
}
98
}
 Lines 104-116   void exit_handler(int sig) { Link Here 
104
	static bool exit_handler_running = false;
102
	static bool exit_handler_running = false;
105
103
106
	if (exit_handler_running) {
104
	if (exit_handler_running) {
107
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "received another signal %d, ignoring", sig);
105
		LOG(WARN, "received another signal %d, ignoring", sig);
108
		return;
106
		return;
109
	}
107
	}
110
	exit_handler_running = true;
108
	exit_handler_running = true;
111
109
112
	if (sig)
110
	if (sig)
113
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "received signal %d", sig);
111
		LOG(WARN, "received signal %d", sig);
114
112
115
	cache_close();
113
	cache_close();
116
	unlink(pidfile);
114
	unlink(pidfile);
 Lines 131-137   void exit_handler(int sig) { Link Here 
131
}
129
}
132
130
133
void reload_handler(int sig) {
131
void reload_handler(int sig) {
134
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "received signal %d", sig);
132
	LOG(WARN, "received signal %d", sig);
135
	handlers_reload_all_paths();
133
	handlers_reload_all_paths();
136
}
134
}
137
135
(-)a/management/univention-directory-listener/src/transfile.c (-12 / +11 lines)
 Lines 40-47    Link Here 
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <sys/stat.h>
41
#include <sys/stat.h>
42
42
43
#include <univention/debug.h>
43
#define LOG_CATEGORY UV_DEBUG_TRANSFILE
44
45
#include "common.h"
44
#include "common.h"
46
#include "transfile.h"
45
#include "transfile.h"
47
46
 Lines 60-66   static FILE *fopen_lock(const char *name, const char *type, FILE **l_file) { Link Here 
60
	snprintf(buf, sizeof(buf), "%s.lock", name);
59
	snprintf(buf, sizeof(buf), "%s.lock", name);
61
60
62
	if ((*l_file = fopen(buf, "a")) == NULL) {
61
	if ((*l_file = fopen(buf, "a")) == NULL) {
63
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Could not open lock file [%s]", buf);
62
		LOG(WARN, "Could not open lock file [%s]", buf);
64
		return NULL;
63
		return NULL;
65
	}
64
	}
66
65
 Lines 69-89   static FILE *fopen_lock(const char *name, const char *type, FILE **l_file) { Link Here 
69
		int rc = lockf(l_fd, F_TLOCK, 0);
68
		int rc = lockf(l_fd, F_TLOCK, 0);
70
		if (!rc)
69
		if (!rc)
71
			break;
70
			break;
72
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_INFO, "Could not get lock for file [%s]; count=%d", buf, count);
71
		LOG(INFO, "Could not get lock for file [%s]; count=%d", buf, count);
73
		count++;
72
		count++;
74
		if (count > listener_lock_count) {
73
		if (count > listener_lock_count) {
75
			univention_debug(UV_DEBUG_TRANSFILE, UV_DEBUG_ERROR, "Could not get lock for file [%s]; exit", buf);
74
			LOG(ERROR, "Could not get lock for file [%s]; exit", buf);
76
			exit(0);
75
			exit(0);
77
		}
76
		}
78
		usleep(1000);
77
		usleep(1000);
79
	}
78
	}
80
79
81
	if ((file = fopen(name, type)) == NULL) {
80
	if ((file = fopen(name, type)) == NULL) {
82
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Could not open file [%s]", name);
81
		LOG(WARN, "Could not open file [%s]", name);
83
82
84
		int rc = lockf(l_fd, F_ULOCK, 0);
83
		int rc = lockf(l_fd, F_ULOCK, 0);
85
		if (rc)
84
		if (rc)
86
			univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to unlock %s: %s", buf, strerror(errno));
85
			LOG(WARN, "Failed to unlock %s: %s", buf, strerror(errno));
87
		fclose(*l_file);
86
		fclose(*l_file);
88
		*l_file = NULL;
87
		*l_file = NULL;
89
	}
88
	}
 Lines 105-111   static int fclose_lock(FILE **file, FILE **l_file) { Link Here 
105
		int l_fd = fileno(*l_file);
104
		int l_fd = fileno(*l_file);
106
		int rc = lockf(l_fd, F_ULOCK, 0);
105
		int rc = lockf(l_fd, F_ULOCK, 0);
107
		if (rc)
106
		if (rc)
108
			univention_debug(UV_DEBUG_LDAP, UV_DEBUG_ALL, "unlockf(): %d", rc);
107
			LOG(ALL, "unlockf(): %d", rc);
109
		rv |= fclose(*l_file);
108
		rv |= fclose(*l_file);
110
		*l_file = NULL;
109
		*l_file = NULL;
111
	}
110
	}
 Lines 119-125   bool notifier_has_failed_ldif(void) { Link Here 
119
118
120
	if (stat(failed_ldif_file, &stat_buf) != 0)
119
	if (stat(failed_ldif_file, &stat_buf) != 0)
121
		return false;
120
		return false;
122
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "'failed.ldif' exists. Check for %s", failed_ldif_file);
121
	LOG(ERROR, "'failed.ldif' exists. Check for %s", failed_ldif_file);
123
	return true;
122
	return true;
124
}
123
}
125
124
 Lines 136-150   int notifier_write_transaction_file(NotifierEntry entry) { Link Here 
136
	assert(!notifier_has_failed_ldif());
135
	assert(!notifier_has_failed_ldif());
137
136
138
	if ((file = fopen_lock(transaction_file, "a+", &l_file)) == NULL) {
137
	if ((file = fopen_lock(transaction_file, "a+", &l_file)) == NULL) {
139
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Could not open %s", transaction_file);
138
		LOG(ERROR, "Could not open %s", transaction_file);
140
		return res;
139
		return res;
141
	}
140
	}
142
141
143
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "write to transaction file dn=[%s], command=[%c]", entry.dn, entry.command);
142
	LOG(INFO, "write to transaction file dn=[%s], command=[%c]", entry.dn, entry.command);
144
	fprintf(file, "%ld %s %c\n", entry.id, entry.dn, entry.command);
143
	fprintf(file, "%ld %s %c\n", entry.id, entry.dn, entry.command);
145
	res = fclose_lock(&file, &l_file);
144
	res = fclose_lock(&file, &l_file);
146
	if (res != 0)
145
	if (res != 0)
147
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "failed to write to transaction file %s: %d", transaction_file, res);
146
		LOG(ERROR, "failed to write to transaction file %s: %d", transaction_file, res);
148
147
149
	return res;
148
	return res;
150
}
149
}
(-)a/management/univention-directory-listener/src/verify.c (-3 lines)
 Lines 40-47    Link Here 
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <ldap.h>
41
#include <ldap.h>
42
42
43
#include <univention/debug.h>
44
45
#include "cache.h"
43
#include "cache.h"
46
#include "common.h"
44
#include "common.h"
47
#include "utils.h"
45
#include "utils.h"
48
- 

Return to bug 35707