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

(-)a/branches/ucs-3.2/ucs-3.2-1/management/univention-directory-listener/src/cache_entry.c (-133 lines)
 Lines 377-512   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
377
377
378
	return changes;
378
	return changes;
379
}
379
}
380
381
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
382
	CacheEntryAttribute **cur1, **cur2;
383
	int i=0;
384
	int rv=0;
385
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
386
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
387
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) {
388
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
389
			rv = 1;
390
			goto result;
391
		}
392
		if ((backup_cache_entry->attributes[backup_cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
393
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
394
			rv = 1;
395
			goto result;
396
		}
397
		cur2 = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
398
		(*cur2)->name=strdup((*cur1)->name);
399
		(*cur2)->values=NULL;
400
		(*cur2)->length=NULL;
401
		(*cur2)->value_count=0;
402
		backup_cache_entry->attributes[backup_cache_entry->attribute_count+1]=NULL;
403
404
		for (i = 0; i < (*cur1)->value_count; i++) {
405
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count+2)*sizeof(char*))) == NULL) {
406
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
407
				rv = 1;
408
				goto result;
409
			}
410
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count+2)*sizeof(int))) == NULL) {
411
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
412
				rv = 1;
413
				goto result;
414
			}
415
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
416
				if (((*cur2)->values[(*cur2)->value_count]=strdup((*cur1)->values[i])) == NULL) {
417
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
418
					rv = 1;
419
					goto result;
420
				}
421
				(*cur2)->length[(*cur2)->value_count]=strlen((*cur2)->values[(*cur2)->value_count])+1;
422
			} else {
423
				if (((*cur2)->values[(*cur2)->value_count]=malloc(((*cur1)->length[i])*sizeof(char))) == NULL) {
424
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
425
					rv = 1;
426
					goto result;
427
				}
428
				memcpy((*cur2)->values[(*cur2)->value_count],(*cur1)->values[i],(*cur1)->length[i]);
429
				(*cur2)->length[(*cur2)->value_count]=(*cur1)->length[i];
430
			}
431
			(*cur2)->values[(*cur2)->value_count+1]=NULL;
432
			(*cur2)->value_count++;
433
		}
434
		backup_cache_entry->attribute_count++;
435
	}
436
	char **module_ptr;
437
	for (module_ptr=cache_entry->modules; module_ptr != NULL && *module_ptr != NULL; module_ptr++) {
438
		backup_cache_entry->modules = realloc(backup_cache_entry->modules, (backup_cache_entry->module_count+2)*sizeof(char*));
439
		backup_cache_entry->modules[backup_cache_entry->module_count] = strdup(*module_ptr);
440
		backup_cache_entry->modules[backup_cache_entry->module_count+1] = NULL;
441
		backup_cache_entry->module_count++;
442
	}
443
result:
444
	return rv;
445
}
446
447
void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry)
448
{
449
	char		**changes;
450
	char		**cur;
451
	int i=0;
452
453
	changes = cache_entry_changed_attributes(lentry, rentry);
454
455
	for (cur = changes; cur != NULL && *cur != NULL; cur++) {
456
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     %s differs\n", *cur);
457
458
		for (i=0; lentry->attributes != NULL && lentry->attributes[i] != NULL; i++) {
459
			if (STREQ(lentry->attributes[i]->name, *cur))
460
				break;
461
		}
462
		if (lentry->attributes == NULL || lentry->attributes[i] == NULL) {
463
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         lentry = []\n");
464
		} else {
465
			int j;
466
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         lentry = [");
467
			for (j=0; lentry->attributes[i]->values &&
468
					lentry->attributes[i]->values[j] != NULL;
469
					j++) {
470
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", lentry->attributes[i]->values[j]);
471
			}
472
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "]\n");
473
		}
474
475
		for (i=0; rentry->attributes != NULL && rentry->attributes[i] != NULL; i++) {
476
			if (STREQ(rentry->attributes[i]->name, *cur))
477
				break;
478
		}
479
		if (rentry->attributes == NULL || rentry->attributes[i] == NULL) {
480
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         rentry = []\n");
481
		} else {
482
			int j;
483
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         rentry = [");
484
			for (j=0; rentry->attributes[i]->values &&
485
					rentry->attributes[i]->values[j] != NULL;
486
					j++) {
487
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", rentry->attributes[i]->values[j]);
488
			}
489
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "]\n");
490
		}
491
	}
492
	free(changes);
493
494
	char		**cur1, **cur2;
495
496
	for (cur1=lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++) {
497
		for (cur2=rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++)
498
			if (STREQ(*cur1, *cur2))
499
				break;
500
		if (cur2 != NULL && *cur2 != NULL)
501
			continue;
502
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on lentry missing on rentry\n", *cur1);
503
	}
504
	for (cur2=rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++) {
505
		for (cur1=lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++)
506
			if (STREQ(*cur1, *cur2))
507
				break;
508
		if (cur1 != NULL && *cur1 != NULL)
509
			continue;
510
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on rentry missing on lentry\n", *cur2);
511
	}
512
}
(-)a/branches/ucs-3.2/ucs-3.2-1/management/univention-directory-listener/src/cache_entry.h (-6 lines)
 Lines 68-77   int cache_entry_module_present (CacheEntry *entry, Link Here 
68
char**	cache_entry_changed_attributes	(CacheEntry	 *new,
68
char**	cache_entry_changed_attributes	(CacheEntry	 *new,
69
					 CacheEntry	 *old);
69
					 CacheEntry	 *old);
70
70
71
int	copy_cache_entry		(CacheEntry *cache_entry,
72
					 CacheEntry *backup_cache_entry);
73
74
void	compare_cache_entries		(CacheEntry *lentry,
75
					 CacheEntry *rentry);
76
77
#endif /* _CACHE_ENTRY_H_ */
71
#endif /* _CACHE_ENTRY_H_ */
(-)a/branches/ucs-3.2/ucs-3.2-1/management/univention-directory-listener/src/change.c (-18 / +6 lines)
 Lines 118-124   int change_init_module(univention_ldap_parameters_t *lp, Handler *handler) Link Here 
118
	} else if (rv == 0) {
118
	} else if (rv == 0) {
119
		signals_block();
119
		signals_block();
120
		cache_update_entry(0, "cn=subschema", &cache_entry);
120
		cache_update_entry(0, "cn=subschema", &cache_entry);
121
		handler_update("cn=Subschema", &cache_entry, &old_cache_entry, handler, 'n', NULL);
121
		handler_update("cn=Subschema", &cache_entry, &old_cache_entry, handler, 'n');
122
		signals_unblock();
122
		signals_unblock();
123
		cache_free_entry(NULL, &cache_entry);
123
		cache_free_entry(NULL, &cache_entry);
124
	}
124
	}
 Lines 186-200   int change_init_module(univention_ldap_parameters_t *lp, Handler *handler) Link Here 
186
			}
186
			}
187
187
188
			signals_block();
188
			signals_block();
189
189
			handler_update(dns[i].dn, &cache_entry, &old_cache_entry, handler, 'n');
190
			/* First copy the entry for the local cache to be sure the entry in the cache is untouched. Bug #21914 */
190
			cache_update_entry_lower(0, dns[i].dn, &cache_entry);
191
			CacheEntry updated_cache_entry;
192
			copy_cache_entry(&cache_entry, &updated_cache_entry);
193
			handler_update(dns[i].dn, &cache_entry, &old_cache_entry, handler, 'n', &updated_cache_entry);
194
			//compare_cache_entries(&cache_entry, &updated_cache_entry);
195
			cache_update_entry_lower(0, dns[i].dn, &updated_cache_entry);
196
			cache_free_entry(NULL, &updated_cache_entry);
197
198
			signals_unblock();
191
			signals_unblock();
199
			cache_free_entry(NULL, &cache_entry);
192
			cache_free_entry(NULL, &cache_entry);
200
		}
193
		}
 Lines 238-249   static Link Here 
238
int change_update_entry(univention_ldap_parameters_t *lp, NotifierID id, LDAPMessage *ldap_entry, char command)
231
int change_update_entry(univention_ldap_parameters_t *lp, NotifierID id, LDAPMessage *ldap_entry, char command)
239
{
232
{
240
	char *dn=NULL;
233
	char *dn=NULL;
241
	CacheEntry cache_entry, old_cache_entry, updated_cache_entry;
234
	CacheEntry cache_entry, old_cache_entry;
242
	int rv = 0;
235
	int rv = 0;
243
236
244
	memset(&cache_entry, 0, sizeof(CacheEntry));
237
	memset(&cache_entry, 0, sizeof(CacheEntry));
245
	memset(&old_cache_entry, 0, sizeof(CacheEntry));
238
	memset(&old_cache_entry, 0, sizeof(CacheEntry));
246
	memset(&updated_cache_entry, 0, sizeof(CacheEntry));
247
239
248
	if ((rv=cache_new_entry_from_ldap(&dn, &cache_entry, lp->ld, ldap_entry)) != 0) {
240
	if ((rv=cache_new_entry_from_ldap(&dn, &cache_entry, lp->ld, ldap_entry)) != 0) {
249
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while converting LDAP entry to cache entry");
241
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while converting LDAP entry to cache entry");
 Lines 254-264   int change_update_entry(univention_ldap_parameters_t *lp, NotifierID id, LDAPMes Link Here 
254
		rv = LDAP_OTHER;
246
		rv = LDAP_OTHER;
255
	} else {
247
	} else {
256
		signals_block();
248
		signals_block();
257
		/* First copy the entry for the local cache to be sure the entry in the cache is untouched. Bug #21914 */
249
		handlers_update(dn, &cache_entry, &old_cache_entry, command);
258
		copy_cache_entry(&cache_entry, &updated_cache_entry);
250
		if ((rv=cache_update_entry_lower(id, dn, &cache_entry)) != 0) {
259
		handlers_update(dn, &cache_entry, &old_cache_entry, command, &updated_cache_entry);
260
		//compare_cache_entries(&cache_entry, &updated_cache_entry);
261
		if ((rv=cache_update_entry_lower(id, dn, &updated_cache_entry)) != 0) {
262
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while writing to database");
251
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "error while writing to database");
263
		}
252
		}
264
		rv=0;
253
		rv=0;
 Lines 268-274   int change_update_entry(univention_ldap_parameters_t *lp, NotifierID id, LDAPMes Link Here 
268
result:
257
result:
269
	cache_free_entry(&dn, &cache_entry);
258
	cache_free_entry(&dn, &cache_entry);
270
	cache_free_entry(NULL, &old_cache_entry);
259
	cache_free_entry(NULL, &old_cache_entry);
271
	cache_free_entry(NULL, &updated_cache_entry);
272
260
273
	return rv;
261
	return rv;
274
}
262
}
(-)a/branches/ucs-3.2/ucs-3.2-1/management/univention-directory-listener/src/handlers.c (-12 / +6 lines)
 Lines 759-765   int attribute_has_changed(char** changes, char* attribute) Link Here 
759
759
760
760
761
/* a little more low-level interface than handler_update */
761
/* a little more low-level interface than handler_update */
762
static int handler__update(Handler *handler, char *dn, CacheEntry *new, CacheEntry *old, char command, char **changes, CacheEntry *scratch)
762
static int handler__update(Handler *handler, char *dn, CacheEntry *new, CacheEntry *old, char command, char **changes)
763
{
763
{
764
	int matched;
764
	int matched;
765
	int rv = 0;
765
	int rv = 0;
 Lines 792-800   static int handler__update(Handler *handler, char *dn, CacheEntry *new, CacheEnt Link Here 
792
		if (uptodate) {
792
		if (uptodate) {
793
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (up-to-date)", handler->name);
793
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (up-to-date)", handler->name);
794
			cache_entry_module_add(new, handler->name);
794
			cache_entry_module_add(new, handler->name);
795
			if ( scratch != NULL ) {
796
				cache_entry_module_add(scratch, handler->name);
797
			}
798
			return 0;
795
			return 0;
799
		}
796
		}
800
	}
797
	}
 Lines 809-817   static int handler__update(Handler *handler, char *dn, CacheEntry *new, CacheEnt Link Here 
809
	/* run handler */
806
	/* run handler */
810
	if (handler_exec(handler, dn, new, old, command) == 0) {
807
	if (handler_exec(handler, dn, new, old, command) == 0) {
811
		cache_entry_module_add(new, handler->name);
808
		cache_entry_module_add(new, handler->name);
812
		if ( scratch != NULL ) {
813
			cache_entry_module_add(scratch, handler->name);
814
		}
815
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (successful)", handler->name);
809
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_INFO, "handler: %s (successful)", handler->name);
816
	} else {
810
	} else {
817
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "handler: %s (failed)", handler->name);
811
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_WARN, "handler: %s (failed)", handler->name);
 Lines 823-829   static int handler__update(Handler *handler, char *dn, CacheEntry *new, CacheEnt Link Here 
823
817
824
818
825
/* run all handlers if object has changed */
819
/* run all handlers if object has changed */
826
int handlers_update(char *dn, CacheEntry *new, CacheEntry *old, char command, CacheEntry *scratch)
820
int handlers_update(char *dn, CacheEntry *new, CacheEntry *old, char command)
827
{
821
{
828
	Handler *handler;
822
	Handler *handler;
829
	char** changes;
823
	char** changes;
 Lines 835-846   int handlers_update(char *dn, CacheEntry *new, CacheEntry *old, char command, Ca Link Here 
835
829
836
	for (handler=handlers; handler != NULL; handler=handler->next) {
830
	for (handler=handlers; handler != NULL; handler=handler->next) {
837
		if (STREQ(handler->name, "replication")) {
831
		if (STREQ(handler->name, "replication")) {
838
			handler__update(handler, dn, new, old, command, changes, scratch);
832
			handler__update(handler, dn, new, old, command, changes);
839
		}
833
		}
840
	}
834
	}
841
	for (handler=handlers; handler != NULL; handler=handler->next) {
835
	for (handler=handlers; handler != NULL; handler=handler->next) {
842
		if (STRNEQ(handler->name, "replication")) {
836
		if (STRNEQ(handler->name, "replication")) {
843
			handler__update(handler, dn, new, old, command, changes, scratch);
837
			handler__update(handler, dn, new, old, command, changes);
844
		}
838
		}
845
	}
839
	}
846
	free(changes);
840
	free(changes);
 Lines 850-856   int handlers_update(char *dn, CacheEntry *new, CacheEntry *old, char command, Ca Link Here 
850
844
851
845
852
/* run given handler if object has changed */
846
/* run given handler if object has changed */
853
int handler_update(char *dn, CacheEntry *new, CacheEntry *old, Handler *handler, char command, CacheEntry *scratch)
847
int handler_update(char *dn, CacheEntry *new, CacheEntry *old, Handler *handler, char command)
854
{
848
{
855
	char** changes;
849
	char** changes;
856
	int rv = 0;
850
	int rv = 0;
 Lines 859-865   int handler_update(char *dn, CacheEntry *new, CacheEntry *old, Handler *handler, Link Here 
859
853
860
	changes = cache_entry_changed_attributes(new, old);
854
	changes = cache_entry_changed_attributes(new, old);
861
855
862
	rv = handler__update(handler, dn, new, old, command, changes, scratch);
856
	rv = handler__update(handler, dn, new, old, command, changes);
863
857
864
	free(changes);
858
	free(changes);
865
859
(-)a/branches/ucs-3.2/ucs-3.2-1/management/univention-directory-listener/src/handlers.h (-4 / +2 lines)
 Lines 87-100   int handlers_dump (void); Link Here 
87
int	handlers_update			(char		*dn,
87
int	handlers_update			(char		*dn,
88
					 CacheEntry	*new,
88
					 CacheEntry	*new,
89
					 CacheEntry	*old,
89
					 CacheEntry	*old,
90
					 char		command,
90
					 char		command);
91
					 CacheEntry *scratch);
92
int	handler_update			(char		*dn,
91
int	handler_update			(char		*dn,
93
					 CacheEntry	*new,
92
					 CacheEntry	*new,
94
					 CacheEntry	*old,
93
					 CacheEntry	*old,
95
					 Handler	*handler,
94
					 Handler	*handler,
96
					 char		command,
95
					 char		command);
97
					 CacheEntry *scratch);
98
int	handlers_delete			(char		*dn,
96
int	handlers_delete			(char		*dn,
99
					 CacheEntry	*old,
97
					 CacheEntry	*old,
100
					 char command);
98
					 char command);

Return to bug 34507