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

(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-2 / +2 lines)
 Lines 275-286   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
275
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
275
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
276
				abort(); // FIXME
276
				abort(); // FIXME
277
			}
277
			}
278
			// TODO: stdndup() copies until the first \0, which would be incorrect if data is binary!
278
			if (!(c_attr->values[c_attr->value_count] = malloc(data_size))) {
279
			if (!(c_attr->values[c_attr->value_count] = strndup((char*)data_data, data_size))) {
280
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
279
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
281
				abort(); // FIXME
280
				abort(); // FIXME
282
			}
281
			}
283
			c_attr->length[c_attr->value_count] = data_size;
282
			c_attr->length[c_attr->value_count] = data_size;
283
			memcpy(c_attr->values[c_attr->value_count], data_data, data_size);
284
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", c_attr->values[c_attr->value_count]);
284
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", c_attr->values[c_attr->value_count]);
285
			c_attr->values[++c_attr->value_count] = NULL;
285
			c_attr->values[++c_attr->value_count] = NULL;
286
			break;
286
			break;
287
   Bug #30227: listener: assert null termination
287
   Bug #30227: listener: assert null termination
288
   
288
   
289
   Check key_len and data_len >= 1.
289
   Check key_len and data_len >= 1.
290
   Check key and data are always '\0' terminated, especially data:
290
   Check key and data are always '\0' terminated, especially data:
291
   C-strings are naturally '\0' terminated, binary data is artifically '\0'
291
   C-strings are naturally '\0' terminated, binary data is artifically '\0'
292
   terminated by us.
292
   terminated by us.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-2 / +8 lines)
 Lines 38-43    Link Here 
38
#include <stdbool.h>
38
#include <stdbool.h>
39
#include <sys/types.h>
39
#include <sys/types.h>
40
40
41
#include <assert.h>
41
#include <univention/debug.h>
42
#include <univention/debug.h>
42
43
43
#include "common.h"
44
#include "common.h"
 Lines 230-244   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
230
			CacheEntryAttribute **attribute, *c_attr;
231
			CacheEntryAttribute **attribute, *c_attr;
231
232
232
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "attribute is \"%s\"", (char*)key_data);
233
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "attribute is \"%s\"", (char*)key_data);
234
			/* key name including '\0' */
235
			assert(key_size >= 1);
236
			assert('\0' == ((char *)key_data)[key_size - 1]);
237
			/* value including '\0' */
238
			assert(data_size >= 1);
239
			assert('\0' == ((char *)data_data)[data_size - 1]);
233
240
234
			for (attribute = entry->attributes, c_attr = NULL;
241
			for (attribute = entry->attributes, c_attr = NULL;
235
					attribute != NULL && *attribute != NULL;
242
					attribute != NULL && *attribute != NULL;
236
					attribute++) {
243
					attribute++) {
237
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "current attribute is \"%s\"", c_attr->name);
244
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "current attribute is \"%s\"", c_attr->name);
238
				if (strcmp(c_attr->name, (char*)key_data) == 0) {
245
				if (strncmp(c_attr->name, (char*)key_data, key_size) == 0)
239
					c_attr = *attribute;
246
					c_attr = *attribute;
240
					break;
247
					break;
241
				}
242
			}
248
			}
243
			if (!c_attr) {
249
			if (!c_attr) {
244
				if (!(entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute*)))) {
250
				if (!(entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute*)))) {
245
   Bug #30227: listener: allocation checking
251
   Bug #30227: listener: allocation checking
246
   
252
   
247
   allocate and check in one statement to reduce code repetition.
253
   allocate and check in one statement to reduce code repetition.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-16 / +8 lines)
 Lines 241-258   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
241
				}
241
				}
242
			}
242
			}
243
			if (!c_attr) {
243
			if (!c_attr) {
244
				entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute*));
244
				if (!(entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute*)))) {
245
				if (entry->attributes == NULL) {
246
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
245
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
247
					abort(); // FIXME
246
					abort(); // FIXME
248
				}
247
				}
249
				c_attr = malloc(sizeof(CacheEntryAttribute));
248
				if (!(c_attr = malloc(sizeof(CacheEntryAttribute)))) {
250
				if (c_attr == NULL) {
251
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "malloc failed");
249
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "malloc failed");
252
					abort(); // FIXME
250
					abort(); // FIXME
253
				}
251
				}
254
				c_attr->name = strndup((char*)key_data, key_size);
252
				if (!(c_attr->name = strndup((char*)key_data, key_size))) {
255
				if (c_attr->name == NULL) {
256
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
253
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
257
					abort(); // FIXME
254
					abort(); // FIXME
258
				}
255
				}
 Lines 264-282   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
264
261
265
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s is at %p", c_attr->name, c_attr);
262
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s is at %p", c_attr->name, c_attr);
266
			}
263
			}
267
			c_attr->values = realloc((*attribute)->values, ((*attribute)->value_count + 2) * sizeof(char*));
264
			if (!(c_attr->length = realloc(c_attr->length, (c_attr->value_count + 2) * sizeof(int)))) {
268
			if (c_attr->values == NULL) {
269
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
265
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
270
				abort(); // FIXME
266
				abort(); // FIXME
271
			}
267
			}
272
			c_attr->length = realloc((*attribute)->length, ((*attribute)->value_count + 2) * sizeof(int));
268
			if (!(c_attr->values = realloc(c_attr->values, (c_attr->value_count + 2) * sizeof(char*)))) {
273
			if (c_attr->length == NULL) {
274
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
269
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
275
				abort(); // FIXME
270
				abort(); // FIXME
276
			}
271
			}
277
			// TODO: stdndup() copies until the first \0, which would be incorrect if data is binary!
272
			// TODO: stdndup() copies until the first \0, which would be incorrect if data is binary!
278
			c_attr->values[c_attr->value_count] = strndup((char*)data_data, data_size);
273
			if (!(c_attr->values[c_attr->value_count] = strndup((char*)data_data, data_size))) {
279
			if (c_attr->values[c_attr->value_count] == NULL) {
280
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
274
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
281
				abort(); // FIXME
275
				abort(); // FIXME
282
			}
276
			}
 Lines 288-300   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
288
282
289
		case TYPE_MODULES:
283
		case TYPE_MODULES:
290
			entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char*));
284
			entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char*));
291
			entry->modules[entry->module_count] = strndup((char*)key_data, key_size);
285
			if (!(entry->modules[entry->module_count] = strndup((char*)key_data, key_size))) {
292
			if (entry->modules[entry->module_count] == NULL) {
293
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
286
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
294
				abort(); // FIXME
287
				abort(); // FIXME
295
			}
288
			}
296
			entry->modules[entry->module_count+1] = NULL;
289
			entry->modules[++entry->module_count] = NULL;
297
			entry->module_count++;
298
			break;
290
			break;
299
291
300
		default: {
292
		default: {
301
   Bug #30227: listener: simplify pointer logic
293
   Bug #30227: listener: simplify pointer logic
302
   
294
   
303
   Track the current CacheAttribute in local variable instead of
295
   Track the current CacheAttribute in local variable instead of
304
   calculating it again and again.
296
   calculating it again and again.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-30 / +25 lines)
 Lines 227-293   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
227
	while ((type = read_header(data, size, &pos, &key_data, &key_size, &data_data, &data_size)) > 0) {
227
	while ((type = read_header(data, size, &pos, &key_data, &key_size, &data_data, &data_size)) > 0) {
228
		switch (type) {
228
		switch (type) {
229
		case TYPE_ATTRIBUTE: {
229
		case TYPE_ATTRIBUTE: {
230
			CacheEntryAttribute **attribute;
230
			CacheEntryAttribute **attribute, *c_attr;
231
			bool found = false;
232
231
233
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "attribute is \"%s\"", (char*)key_data);
232
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "attribute is \"%s\"", (char*)key_data);
234
233
235
			for (attribute = entry->attributes;
234
			for (attribute = entry->attributes, c_attr = NULL;
236
					attribute != NULL && *attribute != NULL;
235
					attribute != NULL && *attribute != NULL;
237
					attribute++) {
236
					attribute++) {
238
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "current attribute is \"%s\"", (*attribute)->name);
237
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "current attribute is \"%s\"", c_attr->name);
239
				if (strcmp((*attribute)->name, (char*)key_data) == 0) {
238
				if (strcmp(c_attr->name, (char*)key_data) == 0) {
240
					found = true;
239
					c_attr = *attribute;
241
					break;
240
					break;
242
				}
241
				}
243
			}
242
			}
244
			if (!found) {
243
			if (!c_attr) {
245
				entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute*));
244
				entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute*));
246
				if (entry->attributes == NULL) {
245
				if (entry->attributes == NULL) {
247
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
246
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
248
					abort(); // FIXME
247
					abort(); // FIXME
249
				}
248
				}
250
				entry->attributes[entry->attribute_count] = malloc(sizeof(CacheEntryAttribute));
249
				c_attr = malloc(sizeof(CacheEntryAttribute));
251
				if (entry->attributes[entry->attribute_count] == NULL) {
250
				if (c_attr == NULL) {
252
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "malloc failed");
251
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "malloc failed");
253
					abort(); // FIXME
252
					abort(); // FIXME
254
				}
253
				}
255
				entry->attributes[entry->attribute_count+1] = NULL;
254
				c_attr->name = strndup((char*)key_data, key_size);
256
255
				if (c_attr->name == NULL) {
257
				attribute=entry->attributes+entry->attribute_count;
258
				(*attribute)->name = strndup((char*)key_data, key_size);
259
				if ((*attribute)->name == NULL) {
260
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
256
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
261
					abort(); // FIXME
257
					abort(); // FIXME
262
				}
258
				}
263
				entry->attributes[entry->attribute_count+1] = NULL;
259
				c_attr->values = NULL;
264
				(*attribute)->values = NULL;
260
				c_attr->length = NULL;
265
				(*attribute)->length = NULL;
261
				c_attr->value_count = 0;
266
				(*attribute)->value_count = 0;
262
				entry->attributes[entry->attribute_count++] = c_attr;
267
				entry->attribute_count++;
263
				entry->attributes[entry->attribute_count] = NULL;
268
264
269
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s is at %p", (*attribute)->name, *attribute);
265
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s is at %p", c_attr->name, c_attr);
270
			}
266
			}
271
			(*attribute)->values = realloc((*attribute)->values, ((*attribute)->value_count + 2) * sizeof(char*));
267
			c_attr->values = realloc((*attribute)->values, ((*attribute)->value_count + 2) * sizeof(char*));
272
			if ((*attribute)->values == NULL) {
268
			if (c_attr->values == NULL) {
273
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
269
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
274
				abort(); // FIXME
270
				abort(); // FIXME
275
			}
271
			}
276
			(*attribute)->length = realloc((*attribute)->length, ((*attribute)->value_count + 2) * sizeof(int));
272
			c_attr->length = realloc((*attribute)->length, ((*attribute)->value_count + 2) * sizeof(int));
277
			if ((*attribute)->length == NULL) {
273
			if (c_attr->length == NULL) {
278
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
274
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
279
				abort(); // FIXME
275
				abort(); // FIXME
280
			}
276
			}
281
			// TODO: stdndup() copies until the first \0, which would be incorrect if data is binary!
277
			// TODO: stdndup() copies until the first \0, which would be incorrect if data is binary!
282
			(*attribute)->values[(*attribute)->value_count] = strndup((char*)data_data, data_size);
278
			c_attr->values[c_attr->value_count] = strndup((char*)data_data, data_size);
283
			if ((*attribute)->values[(*attribute)->value_count] == NULL) {
279
			if (c_attr->values[c_attr->value_count] == NULL) {
284
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
280
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
285
				abort(); // FIXME
281
				abort(); // FIXME
286
			}
282
			}
287
			(*attribute)->length[(*attribute)->value_count] = data_size;
283
			c_attr->length[c_attr->value_count] = data_size;
288
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", (*attribute)->values[(*attribute)->value_count]);
284
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", c_attr->values[c_attr->value_count]);
289
			(*attribute)->values[(*attribute)->value_count+1] = NULL;
285
			c_attr->values[++c_attr->value_count] = NULL;
290
			(*attribute)->value_count++;
291
			break;
286
			break;
292
		}
287
		}
293
288
294
   Bug #30227: listener: convert if() to switch()
289
   Bug #30227: listener: convert if() to switch()
295
   
290
   
296
   Use switch() instead of multiple if()s to handle different types.
291
   Use switch() instead of multiple if()s to handle different types.
297
   Move variables to section where they are needed.
292
   Move variables to section where they are needed.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-5 / +13 lines)
 Lines 214-225   static enum type read_header(void *data, u_int32_t size, u_int32_t *pos, void ** Link Here 
214
/* Decode CacheEntry from data chunk. */
214
/* Decode CacheEntry from data chunk. */
215
int parse_entry(void *data, u_int32_t size, CacheEntry *entry)
215
int parse_entry(void *data, u_int32_t size, CacheEntry *entry)
216
{
216
{
217
	FILE *file;
218
	enum type type;
217
	enum type type;
219
	void *key_data, *data_data;
218
	void *key_data, *data_data;
220
	u_int32_t key_size, data_size;
219
	u_int32_t key_size, data_size;
221
	u_int32_t pos=0;
220
	u_int32_t pos=0;
222
	char *f;
223
221
224
	entry->attributes=NULL;
222
	entry->attributes=NULL;
225
	entry->attribute_count=0;
223
	entry->attribute_count=0;
 Lines 227-233   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
227
	entry->module_count=0;
225
	entry->module_count=0;
228
226
229
	while ((type = read_header(data, size, &pos, &key_data, &key_size, &data_data, &data_size)) > 0) {
227
	while ((type = read_header(data, size, &pos, &key_data, &key_size, &data_data, &data_size)) > 0) {
230
		if (type == TYPE_ATTRIBUTE) {
228
		switch (type) {
229
		case TYPE_ATTRIBUTE: {
231
			CacheEntryAttribute **attribute;
230
			CacheEntryAttribute **attribute;
232
			bool found = false;
231
			bool found = false;
233
232
 Lines 289-295   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
289
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", (*attribute)->values[(*attribute)->value_count]);
288
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", (*attribute)->values[(*attribute)->value_count]);
290
			(*attribute)->values[(*attribute)->value_count+1] = NULL;
289
			(*attribute)->values[(*attribute)->value_count+1] = NULL;
291
			(*attribute)->value_count++;
290
			(*attribute)->value_count++;
292
		} else if (type == TYPE_MODULES) {
291
			break;
292
		}
293
294
		case TYPE_MODULES:
293
			entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char*));
295
			entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char*));
294
			entry->modules[entry->module_count] = strndup((char*)key_data, key_size);
296
			entry->modules[entry->module_count] = strndup((char*)key_data, key_size);
295
			if (entry->modules[entry->module_count] == NULL) {
297
			if (entry->modules[entry->module_count] == NULL) {
 Lines 298-304   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
298
			}
300
			}
299
			entry->modules[entry->module_count+1] = NULL;
301
			entry->modules[entry->module_count+1] = NULL;
300
			entry->module_count++;
302
			entry->module_count++;
301
		} else {
303
			break;
304
305
		default: {
306
			FILE *file;
307
			char *f;
308
302
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "bad data block at position %d:", pos);
309
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "bad data block at position %d:", pos);
303
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "last 100 bytes of previous entry:");
310
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "last 100 bytes of previous entry:");
304
			hex_dump(UV_DEBUG_ERROR, data, pos-1000 < 0 ? 0 : pos-1000, pos-1000 < 0 ? pos : 1000);
311
			hex_dump(UV_DEBUG_ERROR, data, pos-1000 < 0 ? 0 : pos-1000, pos-1000 < 0 ? pos : 1000);
 Lines 315-320   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
315
322
316
			return -1;
323
			return -1;
317
		}
324
		}
325
		}
318
	}
326
	}
319
327
320
	return 0;
328
	return 0;
321
   Bug #30227: listener: white space cleanup
329
   Bug #30227: listener: white space cleanup
322
   
330
   
323
   Remove traling blanks.
331
   Remove traling blanks.
324
   Break long lines.
332
   Break long lines.
325
   Insert blanks before assignment, comparison, after keyword.
333
   Insert blanks before assignment, comparison, after keyword.
326
   Reformat header files.
334
   Reformat header files.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-10 / +22 lines)
 Lines 100-106   static int write_header(void **data, u_int32_t *size, u_int32_t *pos, enum type Link Here 
100
100
101
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "write_header key_size=%d data_size=%d", key_size, data_size);
101
	univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "write_header key_size=%d data_size=%d", key_size, data_size);
102
102
103
	need_memory = sizeof(struct cache_entry_header)+key_size+data_size;
103
	need_memory = sizeof(struct cache_entry_header) + key_size + data_size;
104
	if (*size < *pos+need_memory) {
104
	if (*size < *pos+need_memory) {
105
		while (*size < *pos+need_memory)
105
		while (*size < *pos+need_memory)
106
			*size += BUFSIZ;
106
			*size += BUFSIZ;
 Lines 121-126   static int write_header(void **data, u_int32_t *size, u_int32_t *pos, enum type Link Here 
121
	return 0;
121
	return 0;
122
}
122
}
123
123
124
/* Encode CacheEntry to data chunk. */
124
int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry)
125
int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry)
125
{
126
{
126
	CacheEntryAttribute **attribute;
127
	CacheEntryAttribute **attribute;
 Lines 130-137   int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry) Link Here 
130
	int i, rv = -1;
131
	int i, rv = -1;
131
	u_int32_t pos=0;
132
	u_int32_t pos=0;
132
133
133
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
134
	for (attribute = entry->attributes;
134
		for (value=(*attribute)->values, i=0, length=(*attribute)->length; *value != NULL; value++, i++) {
135
			attribute != NULL && *attribute != NULL;
136
			attribute++) {
137
		length = (*attribute)->length;
138
		for (value = (*attribute)->values, i = 0;
139
				*value != NULL;
140
				value++, i++) {
135
			rv = write_header(data, size, &pos, TYPE_ATTRIBUTE,
141
			rv = write_header(data, size, &pos, TYPE_ATTRIBUTE,
136
					(*attribute)->name, strlen((*attribute)->name) + 1,
142
					(*attribute)->name, strlen((*attribute)->name) + 1,
137
					*value, length[i]);
143
					*value, length[i]);
 Lines 139-145   int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry) Link Here 
139
				goto out;
145
				goto out;
140
		}
146
		}
141
	}
147
	}
142
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
148
	for (module = entry->modules;
149
			module != NULL && *module != NULL;
150
			module++) {
143
		rv = write_header(data, size, &pos, TYPE_MODULES,
151
		rv = write_header(data, size, &pos, TYPE_MODULES,
144
				*module, strlen(*module) + 1,
152
				*module, strlen(*module) + 1,
145
				NULL, 0);
153
				NULL, 0);
 Lines 203-208   static enum type read_header(void *data, u_int32_t size, u_int32_t *pos, void ** Link Here 
203
	return h->type;
211
	return h->type;
204
}
212
}
205
213
214
/* Decode CacheEntry from data chunk. */
206
int parse_entry(void *data, u_int32_t size, CacheEntry *entry)
215
int parse_entry(void *data, u_int32_t size, CacheEntry *entry)
207
{
216
{
208
	FILE *file;
217
	FILE *file;
 Lines 224-230   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
224
233
225
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "attribute is \"%s\"", (char*)key_data);
234
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "attribute is \"%s\"", (char*)key_data);
226
235
227
			for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
236
			for (attribute = entry->attributes;
237
					attribute != NULL && *attribute != NULL;
238
					attribute++) {
228
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "current attribute is \"%s\"", (*attribute)->name);
239
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "current attribute is \"%s\"", (*attribute)->name);
229
				if (strcmp((*attribute)->name, (char*)key_data) == 0) {
240
				if (strcmp((*attribute)->name, (char*)key_data) == 0) {
230
					found = true;
241
					found = true;
 Lines 232-238   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
232
				}
243
				}
233
			}
244
			}
234
			if (!found) {
245
			if (!found) {
235
				entry->attributes = realloc(entry->attributes, (entry->attribute_count+2)*sizeof(CacheEntryAttribute*));
246
				entry->attributes = realloc(entry->attributes, (entry->attribute_count + 2) * sizeof(CacheEntryAttribute*));
236
				if (entry->attributes == NULL) {
247
				if (entry->attributes == NULL) {
237
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
248
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
238
					abort(); // FIXME
249
					abort(); // FIXME
 Lines 258-269   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
258
269
259
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s is at %p", (*attribute)->name, *attribute);
270
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "%s is at %p", (*attribute)->name, *attribute);
260
			}
271
			}
261
			(*attribute)->values = realloc((*attribute)->values, ((*attribute)->value_count+2)*sizeof(char*));
272
			(*attribute)->values = realloc((*attribute)->values, ((*attribute)->value_count + 2) * sizeof(char*));
262
			if ((*attribute)->values == NULL) {
273
			if ((*attribute)->values == NULL) {
263
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
274
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
264
				abort(); // FIXME
275
				abort(); // FIXME
265
			}
276
			}
266
			(*attribute)->length = realloc((*attribute)->length, ((*attribute)->value_count+2)*sizeof(int));
277
			(*attribute)->length = realloc((*attribute)->length, ((*attribute)->value_count + 2) * sizeof(int));
267
			if ((*attribute)->length == NULL) {
278
			if ((*attribute)->length == NULL) {
268
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
279
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "realloc failed");
269
				abort(); // FIXME
280
				abort(); // FIXME
 Lines 279-285   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
279
			(*attribute)->values[(*attribute)->value_count+1] = NULL;
290
			(*attribute)->values[(*attribute)->value_count+1] = NULL;
280
			(*attribute)->value_count++;
291
			(*attribute)->value_count++;
281
		} else if (type == TYPE_MODULES) {
292
		} else if (type == TYPE_MODULES) {
282
			entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
293
			entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char*));
283
			entry->modules[entry->module_count] = strndup((char*)key_data, key_size);
294
			entry->modules[entry->module_count] = strndup((char*)key_data, key_size);
284
			if (entry->modules[entry->module_count] == NULL) {
295
			if (entry->modules[entry->module_count] == NULL) {
285
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
296
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "strndup failed");
 Lines 294-300   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
294
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "first 100 bytes of current entry:");
305
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "first 100 bytes of current entry:");
295
			hex_dump(UV_DEBUG_ERROR, data, pos, pos+1000 > size ? size-pos : 1000);
306
			hex_dump(UV_DEBUG_ERROR, data, pos, pos+1000 > size ? size-pos : 1000);
296
307
297
			if (asprintf(&f, "%s/bad_cache", cache_dir) < 0) abort();
308
			if (asprintf(&f, "%s/bad_cache", cache_dir) < 0)
309
				abort();
298
			if ((file = fopen(f, "w")) != NULL) {
310
			if ((file = fopen(f, "w")) != NULL) {
299
				fprintf(file, "Check log file");
311
				fprintf(file, "Check log file");
300
				fclose(file);
312
				fclose(file);
301
   Bug #30227: listener: handle allocation failures
313
   Bug #30227: listener: handle allocation failures
302
   
314
   
303
   Abort on failed allocations and writes.
315
   Abort on failed allocations and writes.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-4 / +10 lines)
 Lines 127-152   int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry) Link Here 
127
	char **value;
127
	char **value;
128
	char **module;
128
	char **module;
129
	int *length;
129
	int *length;
130
	int i;
130
	int i, rv = -1;
131
	u_int32_t pos=0;
131
	u_int32_t pos=0;
132
132
133
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
133
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
134
		for (value=(*attribute)->values, i=0, length=(*attribute)->length; *value != NULL; value++, i++) {
134
		for (value=(*attribute)->values, i=0, length=(*attribute)->length; *value != NULL; value++, i++) {
135
			write_header(data, size, &pos, TYPE_ATTRIBUTE,
135
			rv = write_header(data, size, &pos, TYPE_ATTRIBUTE,
136
					(*attribute)->name, strlen((*attribute)->name) + 1,
136
					(*attribute)->name, strlen((*attribute)->name) + 1,
137
					*value, length[i]);
137
					*value, length[i]);
138
			if (rv)
139
				goto out;
138
		}
140
		}
139
	}
141
	}
140
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
142
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
141
		write_header(data, size, &pos, TYPE_MODULES,
143
		rv = write_header(data, size, &pos, TYPE_MODULES,
142
				*module, strlen(*module) + 1,
144
				*module, strlen(*module) + 1,
143
				NULL, 0);
145
				NULL, 0);
146
		if (rv)
147
			goto out;
144
	}
148
	}
145
149
146
	/* allocated memory maybe bigger than size, but doesn't matter anyhow... */
150
	/* allocated memory maybe bigger than size, but doesn't matter anyhow... */
147
	*size = pos;
151
	*size = pos;
152
	rv = 0;
148
153
149
	return 0;
154
out:
155
	return rv;
150
}
156
}
151
157
152
static enum type read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_data, u_int32_t *key_size, void **data_data, u_int32_t *data_size)
158
static enum type read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_data, u_int32_t *key_size, void **data_data, u_int32_t *data_size)
153
   Bug #30227: listener: change function signature
159
   Bug #30227: listener: change function signature
154
   
160
   
155
   No need to use pointer indirection.
161
   No need to use pointer indirection.
156
   Change function to void as it does not return anything.
162
   Change function to void as it does not return anything.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-9 / +8 lines)
 Lines 84-97   void hex_dump(int level, void *data, u_int32_t start, u_int32_t size) Link Here 
84
}
84
}
85
85
86
/* assumption: enough memory as been allocated for us */
86
/* assumption: enough memory as been allocated for us */
87
static int append_buffer(void **data, u_int32_t *size, u_int32_t *pos, void* blob_data, u_int32_t blob_size)
87
static void append_buffer(void *data, u_int32_t size, u_int32_t *pos, void *blob_data, u_int32_t blob_size)
88
{
88
{
89
	if (blob_size > 0) {
89
	if (blob_size > 0) {
90
		memcpy((void*)(((char*)*data)+*pos), blob_data, blob_size);
90
		memcpy(((char*)data) + *pos, blob_data, blob_size);
91
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "position was=%d is=%d", *pos, *pos+blob_size);
91
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "position was=%d is=%d", *pos, *pos+blob_size);
92
		*pos += blob_size;
92
		*pos += blob_size;
93
	}
93
	}
94
	return 0;
95
}
94
}
96
95
97
static int write_header(void **data, u_int32_t *size, u_int32_t *pos, enum type type, void* key_data, u_int32_t key_size, void* data_data, u_int32_t data_size)
96
static int write_header(void **data, u_int32_t *size, u_int32_t *pos, enum type type, void* key_data, u_int32_t key_size, void* data_data, u_int32_t data_size)
 Lines 115-123   static int write_header(void **data, u_int32_t *size, u_int32_t *pos, enum type Link Here 
115
	h.key_size = key_size;
114
	h.key_size = key_size;
116
	h.data_size = data_size;
115
	h.data_size = data_size;
117
116
118
	append_buffer(data, size, pos, (void*) &h, sizeof(struct cache_entry_header));
117
	append_buffer(*data, *size, pos, &h, sizeof(struct cache_entry_header));
119
	append_buffer(data, size, pos, key_data, key_size);
118
	append_buffer(*data, *size, pos, key_data, key_size);
120
	append_buffer(data, size, pos, data_data, data_size);
119
	append_buffer(*data, *size, pos, data_data, data_size);
121
120
122
	return 0;
121
	return 0;
123
}
122
}
 Lines 134-146   int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry) Link Here 
134
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
133
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
135
		for (value=(*attribute)->values, i=0, length=(*attribute)->length; *value != NULL; value++, i++) {
134
		for (value=(*attribute)->values, i=0, length=(*attribute)->length; *value != NULL; value++, i++) {
136
			write_header(data, size, &pos, TYPE_ATTRIBUTE,
135
			write_header(data, size, &pos, TYPE_ATTRIBUTE,
137
					(void*) (*attribute)->name, strlen((*attribute)->name)+1,
136
					(*attribute)->name, strlen((*attribute)->name) + 1,
138
					(void*) *value, length[i]);
137
					*value, length[i]);
139
		}
138
		}
140
	}
139
	}
141
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
140
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
142
		write_header(data, size, &pos, TYPE_MODULES,
141
		write_header(data, size, &pos, TYPE_MODULES,
143
				(void*) *module, strlen(*module)+1,
142
				*module, strlen(*module) + 1,
144
				NULL, 0);
143
				NULL, 0);
145
	}
144
	}
146
145
147
   Bug #30227: listener: magic types
146
   Bug #30227: listener: magic types
148
   
147
   
149
   Replace magic numbers for attributes and modules by named enum.
148
   Replace magic numbers for attributes and modules by named enum.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.c (-8 / +13 lines)
 Lines 43-48    Link Here 
43
#include "common.h"
43
#include "common.h"
44
#include "cache_lowlevel.h"
44
#include "cache_lowlevel.h"
45
45
46
enum type {
47
	TYPE_ATTRIBUTE = 1,
48
	TYPE_MODULES = 2,
49
};
50
46
struct cache_entry_header {
51
struct cache_entry_header {
47
	u_int16_t type;
52
	u_int16_t type;
48
	u_int32_t key_size;
53
	u_int32_t key_size;
 Lines 89-95   static int append_buffer(void **data, u_int32_t *size, u_int32_t *pos, void* blo Link Here 
89
	return 0;
94
	return 0;
90
}
95
}
91
96
92
static int write_header(void **data, u_int32_t *size, u_int32_t *pos, u_int16_t type, void* key_data, u_int32_t key_size, void* data_data, u_int32_t data_size)
97
static int write_header(void **data, u_int32_t *size, u_int32_t *pos, enum type type, void* key_data, u_int32_t key_size, void* data_data, u_int32_t data_size)
93
{
98
{
94
	struct cache_entry_header h;
99
	struct cache_entry_header h;
95
	u_int32_t need_memory;
100
	u_int32_t need_memory;
 Lines 128-140   int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry) Link Here 
128
133
129
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
134
	for (attribute=entry->attributes; attribute != NULL && *attribute != NULL; attribute++) {
130
		for (value=(*attribute)->values, i=0, length=(*attribute)->length; *value != NULL; value++, i++) {
135
		for (value=(*attribute)->values, i=0, length=(*attribute)->length; *value != NULL; value++, i++) {
131
			write_header(data, size, &pos, 1,
136
			write_header(data, size, &pos, TYPE_ATTRIBUTE,
132
					(void*) (*attribute)->name, strlen((*attribute)->name)+1,
137
					(void*) (*attribute)->name, strlen((*attribute)->name)+1,
133
					(void*) *value, length[i]);
138
					(void*) *value, length[i]);
134
		}
139
		}
135
	}
140
	}
136
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
141
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
137
		write_header(data, size, &pos, 2,
142
		write_header(data, size, &pos, TYPE_MODULES,
138
				(void*) *module, strlen(*module)+1,
143
				(void*) *module, strlen(*module)+1,
139
				NULL, 0);
144
				NULL, 0);
140
	}
145
	}
 Lines 145-151   int unparse_entry(void **data, u_int32_t *size, CacheEntry *entry) Link Here 
145
	return 0;
150
	return 0;
146
}
151
}
147
152
148
static int read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_data, u_int32_t *key_size, void **data_data, u_int32_t *data_size)
153
static enum type read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_data, u_int32_t *key_size, void **data_data, u_int32_t *data_size)
149
{
154
{
150
	struct cache_entry_header *h;
155
	struct cache_entry_header *h;
151
156
 Lines 159-165   static int read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_da Link Here 
159
164
160
	h = (struct cache_entry_header*)((char*)data+*pos);
165
	h = (struct cache_entry_header*)((char*)data+*pos);
161
166
162
	if ((h->type != 1 && h->type != 2) || h->key_size == 0) {
167
	if ((h->type != TYPE_ATTRIBUTE && h->type != TYPE_MODULES) || h->key_size == 0) {
163
		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);
168
		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);
164
		*key_size = 0;
169
		*key_size = 0;
165
		*key_data = NULL;
170
		*key_data = NULL;
 Lines 196-202   static int read_header(void *data, u_int32_t size, u_int32_t *pos, void **key_da Link Here 
196
int parse_entry(void *data, u_int32_t size, CacheEntry *entry)
201
int parse_entry(void *data, u_int32_t size, CacheEntry *entry)
197
{
202
{
198
	FILE *file;
203
	FILE *file;
199
	u_int16_t type;
204
	enum type type;
200
	void *key_data, *data_data;
205
	void *key_data, *data_data;
201
	u_int32_t key_size, data_size;
206
	u_int32_t key_size, data_size;
202
	u_int32_t pos=0;
207
	u_int32_t pos=0;
 Lines 208-214   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
208
	entry->module_count=0;
213
	entry->module_count=0;
209
214
210
	while ((type = read_header(data, size, &pos, &key_data, &key_size, &data_data, &data_size)) > 0) {
215
	while ((type = read_header(data, size, &pos, &key_data, &key_size, &data_data, &data_size)) > 0) {
211
		if (type == 1) {
216
		if (type == TYPE_ATTRIBUTE) {
212
			CacheEntryAttribute **attribute;
217
			CacheEntryAttribute **attribute;
213
			bool found = false;
218
			bool found = false;
214
219
 Lines 268-274   int parse_entry(void *data, u_int32_t size, CacheEntry *entry) Link Here 
268
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", (*attribute)->values[(*attribute)->value_count]);
273
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ALL, "value is \"%s\"", (*attribute)->values[(*attribute)->value_count]);
269
			(*attribute)->values[(*attribute)->value_count+1] = NULL;
274
			(*attribute)->values[(*attribute)->value_count+1] = NULL;
270
			(*attribute)->value_count++;
275
			(*attribute)->value_count++;
271
		} else if (type == 2) {
276
		} else if (type == TYPE_MODULES) {
272
			entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
277
			entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
273
			entry->modules[entry->module_count] = strndup((char*)key_data, key_size);
278
			entry->modules[entry->module_count] = strndup((char*)key_data, key_size);
274
			if (entry->modules[entry->module_count] == NULL) {
279
			if (entry->modules[entry->module_count] == NULL) {
275
   Bug #30227: listener: skip strdup(dn)
280
   Bug #30227: listener: skip strdup(dn)
276
   
281
   
277
   No need to duplicate the dn for printing the cache entries.
282
   No need to duplicate the dn for printing the cache entries.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache.c (-2 / +1 lines)
 Lines 590-596   int cache_print_entries(char *dn) Link Here 
590
	DBC *cur;
590
	DBC *cur;
591
	memset(&key, 0, sizeof(DBT));
591
	memset(&key, 0, sizeof(DBT));
592
	memset(&data, 0, sizeof(DBT));
592
	memset(&data, 0, sizeof(DBT));
593
	key.data = strdup(dn);
593
	key.data = dn;
594
	key.size = strlen(dn)+1;
594
	key.size = strlen(dn)+1;
595
	key.flags = DB_DBT_REALLOC;
595
	key.flags = DB_DBT_REALLOC;
596
	data.flags = DB_DBT_REALLOC;
596
	data.flags = DB_DBT_REALLOC;
 Lines 603-609   int cache_print_entries(char *dn) Link Here 
603
603
604
	cur->c_close(cur);
604
	cur->c_close(cur);
605
	free(key.data);
605
	free(key.data);
606
	free(data.data);
607
	return 0;
606
	return 0;
608
}
607
}
609
608
610
   Bug #30227: listener: rewrite copy_cache
609
   Bug #30227: listener: rewrite copy_cache
611
   
610
   
612
   Fix all out-of-memory cases.
611
   Fix all out-of-memory cases.
613
   
612
   
614
   Allocate structures once instead of incrementally increasing the arrays
613
   Allocate structures once instead of incrementally increasing the arrays
615
   again and again, since the size is known from the source entry before
614
   again and again, since the size is known from the source entry before
616
   hand.
615
   hand.
617
   
616
   
618
   Always copy bv_len + 1 bytes and terminate with '\0'.
617
   Always copy bv_len + 1 bytes and terminate with '\0'.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-65 / +70 lines)
 Lines 195-200   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
195
	int i;
195
	int i;
196
	char *ucrval;
196
	char *ucrval;
197
	enum { DUPLICATES, UNIQUE_UID, UNIQUE_MEMBER } check;
197
	enum { DUPLICATES, UNIQUE_UID, UNIQUE_MEMBER } check;
198
	size_t len;
198
199
199
	/* convert LDAP entry to cache entry */
200
	/* convert LDAP entry to cache entry */
200
	memset(cache_entry, 0, sizeof(CacheEntry));
201
	memset(cache_entry, 0, sizeof(CacheEntry));
 Lines 220-225   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
220
			goto result;
221
			goto result;
221
		}
222
		}
222
		c_attr->name = strdup(attr);
223
		c_attr->name = strdup(attr);
224
		if (!c_attr->name) {
225
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for CacheEntryAttribute.name failed");
226
			goto result;
227
		}
223
		c_attr->values = NULL;
228
		c_attr->values = NULL;
224
		c_attr->length = NULL;
229
		c_attr->length = NULL;
225
		c_attr->value_count = 0;
230
		c_attr->value_count = 0;
 Lines 270-299   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
270
				if (i < c_attr->value_count)
275
				if (i < c_attr->value_count)
271
					continue;
276
					continue;
272
			}
277
			}
273
			if ((c_attr->values = realloc(c_attr->values, (c_attr->value_count + 2) * sizeof(char*))) == NULL) {
278
			len = (*v)->bv_len;
274
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
279
			if (!(c_attr->length = realloc(c_attr->length, (c_attr->value_count + 2) * sizeof(int)))) {
280
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed");
275
				goto result;
281
				goto result;
276
			}
282
			}
277
			if ((c_attr->length = realloc(c_attr->length, (c_attr->value_count + 2) * sizeof(int))) == NULL) {
283
			if (!(c_attr->values = realloc(c_attr->values, (c_attr->value_count + 2) * sizeof(char*)))) {
278
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed");
284
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
279
				goto result;
285
				goto result;
280
			}
286
			}
281
			if ((*v)->bv_len == strlen((*v)->bv_val)) {
287
			if (!(c_attr->values[c_attr->value_count] = malloc(len + 1))) {
282
				if ((c_attr->values[c_attr->value_count] = strdup((*v)->bv_val)) == NULL) {
288
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed");
283
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: strdup of value failed");
289
				goto result;
284
					goto result;
285
				}
286
				c_attr->length[c_attr->value_count] = strlen(c_attr->values[c_attr->value_count]) + 1;
287
			} else {	// in this case something is strange about the string in bv_val, maybe contains a '\0'
288
				// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe
289
				if ((c_attr->values[c_attr->value_count] = malloc(((*v)->bv_len + 1) * sizeof(char))) == NULL) {
290
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed");
291
					goto result;
292
				}
293
				memcpy(c_attr->values[c_attr->value_count], (*v)->bv_val, (*v)->bv_len);
294
				c_attr->values[c_attr->value_count][(*v)->bv_len] = '\0'; // terminate the string to be safe
295
				c_attr->length[c_attr->value_count] = (*v)->bv_len + 1;
296
			}
290
			}
291
			c_attr->length[c_attr->value_count] = len + 1;
292
			memcpy(c_attr->values[c_attr->value_count], (*v)->bv_val, len);
293
			c_attr->values[c_attr->value_count][len] = '\0';
297
			c_attr->values[++c_attr->value_count] = NULL;
294
			c_attr->values[++c_attr->value_count] = NULL;
298
		}
295
		}
299
296
 Lines 353-415   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
353
	return changes;
350
	return changes;
354
}
351
}
355
352
356
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
353
int copy_cache_entry(CacheEntry *src, CacheEntry *dst)
357
	CacheEntryAttribute **curs, **curb;
354
{
358
	int i;
359
	int rv = 1;
355
	int rv = 1;
360
356
361
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
357
	memset(dst, 0, sizeof(CacheEntry));
362
	for (curs = cache_entry->attributes; curs != NULL && *curs != NULL; curs++) {
358
363
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute*))) == NULL) {
359
	int a, a_count = src->attribute_count;
364
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
360
	if (!(dst->attributes = calloc(a_count + 1, sizeof(CacheEntryAttribute*)))) {
361
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc of attributes array failed");
362
		goto result;
363
	}
364
	for (a = 0; a < a_count; a++) {
365
		CacheEntryAttribute *a_dst, *a_src = src->attributes[a];
366
		int v, v_count = a_src->value_count;
367
368
		if ((a_dst = malloc(sizeof(CacheEntryAttribute))) == NULL) {
369
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
365
			goto result;
370
			goto result;
366
		}
371
		}
367
		if ((backup_cache_entry->attributes[backup_cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
372
		memset(a_dst, 0, sizeof(CacheEntryAttribute));
368
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
373
		dst->attributes[a] = a_dst;
374
375
		if (!(a_dst->name = strdup(a_src->name))) {
376
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup for CacheEntryAttribute.name failed");
369
			goto result;
377
			goto result;
370
		}
378
		}
371
		curb = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
379
372
		(*curb)->name = strdup((*curs)->name);
380
		a_dst->value_count = v_count;
373
		(*curb)->values = NULL;
381
		if (!(a_dst->values = calloc(a_dst->value_count + 1, sizeof(char*)))) {
374
		(*curb)->length = NULL;
382
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
375
		(*curb)->value_count = 0;
383
			goto result;
376
		backup_cache_entry->attributes[backup_cache_entry->attribute_count + 1] = NULL;
384
		}
377
385
		if (!(a_dst->length = calloc(a_dst->value_count + 1, sizeof(int)))) {
378
		for (i = 0; i < (*curs)->value_count; i++) {
386
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
379
			if (((*curb)->values = realloc((*curb)->values, ((*curb)->value_count + 2) * sizeof(char*))) == NULL) {
387
			goto result;
380
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
388
		}
381
				goto result;
389
		for (v = 0; v < v_count; v++) {
382
			}
390
			char *v_dst, *v_src = a_src->values[v];
383
			if (((*curb)->length = realloc((*curb)->length, ((*curb)->value_count + 2) * sizeof(int))) == NULL) {
391
			int len = a_src->length[v];
384
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
392
393
			if (!(v_dst = malloc(len))) {
394
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc of value failed");
385
				goto result;
395
				goto result;
386
			}
396
			}
387
			if ((*curs)->length[i] == strlen((*curs)->values[i]) + 1) {
397
			memcpy(v_dst, v_src, len);
388
				if (((*curb)->values[(*curb)->value_count] = strdup((*curs)->values[i])) == NULL) {
398
			a_dst->values[v] = v_dst;
389
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
399
			a_dst->length[v] = len;
390
					goto result;
391
				}
392
				(*curb)->length[(*curb)->value_count] = strlen((*curb)->values[(*curb)->value_count]) + 1;
393
			} else {
394
				if (((*curb)->values[(*curb)->value_count] = malloc(((*curs)->length[i]) * sizeof(char))) == NULL) {
395
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
396
					goto result;
397
				}
398
				memcpy((*curb)->values[(*curb)->value_count], (*curs)->values[i], (*curs)->length[i]);
399
				(*curb)->length[(*curb)->value_count] = (*curs)->length[i];
400
			}
401
			(*curb)->values[(*curb)->value_count+1] = NULL;
402
			(*curb)->value_count++;
403
		}
400
		}
404
		backup_cache_entry->attribute_count++;
401
		a_dst->values[v] = NULL;
402
	}
403
	dst->attributes[a] = NULL;
404
405
	int m, m_count = src->module_count;
406
	if (!(dst->modules = calloc(m_count + 1, sizeof(char*)))) {
407
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc of module array failed");
408
		goto result;
405
	}
409
	}
406
	char **module_ptr;
410
	for (m = 0; m < m_count; m++) {
407
	for (module_ptr = cache_entry->modules; module_ptr != NULL && *module_ptr != NULL; module_ptr++) {
411
		if (!(dst->modules[m] = strdup(src->modules[m]))) {
408
		backup_cache_entry->modules = realloc(backup_cache_entry->modules, (backup_cache_entry->module_count + 2) * sizeof(char*));
412
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of module failed");
409
		backup_cache_entry->modules[backup_cache_entry->module_count] = strdup(*module_ptr);
413
			goto result;
410
		backup_cache_entry->modules[backup_cache_entry->module_count +1] = NULL;
414
		}
411
		backup_cache_entry->module_count++;
412
	}
415
	}
416
	dst->modules[m] = NULL;
417
413
	rv = 0;
418
	rv = 0;
414
result:
419
result:
415
	return rv;
420
	return rv;
416
   Bug #30227: listener: Rename cursors
421
   Bug #30227: listener: Rename cursors
417
   
422
   
418
   Use more expressive variable names than cur[12].
423
   Use more expressive variable names than cur[12].
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-43 / +43 lines)
 Lines 318-352   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
318
{
318
{
319
	char **changes = NULL;
319
	char **changes = NULL;
320
	int changes_count = 0;
320
	int changes_count = 0;
321
	CacheEntryAttribute **cur1, **cur2;
321
	CacheEntryAttribute **curn, **curo;
322
322
323
	for (cur1 = new->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
323
	for (curn = new->attributes; curn != NULL && *curn != NULL; curn++) {
324
		for (cur2 = old->attributes; cur2 != NULL && *cur2 != NULL; cur2++)
324
		for (curo = old->attributes; curo != NULL && *curo != NULL; curo++)
325
			if (strcmp((*cur1)->name, (*cur2)->name) == 0)
325
			if (strcmp((*curn)->name, (*curo)->name) == 0)
326
				break;
326
				break;
327
		if (cur2 != NULL && *cur2 != NULL && (*cur1)->value_count == (*cur2)->value_count) {
327
		if (curo != NULL && *curo != NULL && (*curn)->value_count == (*curo)->value_count) {
328
			int i;
328
			int i;
329
			for (i = 0; i < (*cur1)->value_count; i++)
329
			for (i = 0; i < (*curn)->value_count; i++)
330
				if (memcmp((*cur1)->values[i], (*cur2)->values[i], (*cur1)->length[i]) != 0)
330
				if (memcmp((*curn)->values[i], (*curo)->values[i], (*curn)->length[i]) != 0)
331
					break;
331
					break;
332
			if (i == (*cur1)->value_count)
332
			if (i == (*curn)->value_count)
333
				continue;
333
				continue;
334
		}
334
		}
335
335
336
		changes = realloc(changes, (changes_count + 2) * sizeof(char*));
336
		changes = realloc(changes, (changes_count + 2) * sizeof(char*));
337
		changes[changes_count++] = (*cur1)->name;
337
		changes[changes_count++] = (*curn)->name;
338
		changes[changes_count] = NULL;
338
		changes[changes_count] = NULL;
339
	}
339
	}
340
340
341
	for (cur2 = old->attributes; cur2 != NULL && *cur2 != NULL; cur2++) {
341
	for (curo = old->attributes; curo != NULL && *curo != NULL; curo++) {
342
		for (cur1 = new->attributes; cur1 != NULL && *cur1 != NULL; cur1++)
342
		for (curn = new->attributes; curn != NULL && *curn != NULL; curn++)
343
			if (strcmp((*cur1)->name, (*cur2)->name) == 0)
343
			if (strcmp((*curn)->name, (*curo)->name) == 0)
344
				break;
344
				break;
345
		if (cur1 != NULL && *cur1 != NULL)
345
		if (curn != NULL && *curn != NULL)
346
			continue;
346
			continue;
347
347
348
		changes = realloc(changes, (changes_count + 2) * sizeof(char*));
348
		changes = realloc(changes, (changes_count + 2) * sizeof(char*));
349
		changes[changes_count++] = (*cur2)->name;
349
		changes[changes_count++] = (*curo)->name;
350
		changes[changes_count] = NULL;
350
		changes[changes_count] = NULL;
351
	}
351
	}
352
352
 Lines 354-365   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
354
}
354
}
355
355
356
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
356
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
357
	CacheEntryAttribute **cur1, **cur2;
357
	CacheEntryAttribute **curs, **curb;
358
	int i;
358
	int i;
359
	int rv = 1;
359
	int rv = 1;
360
360
361
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
361
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
362
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
362
	for (curs = cache_entry->attributes; curs != NULL && *curs != NULL; curs++) {
363
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute*))) == NULL) {
363
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute*))) == NULL) {
364
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
364
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
365
			goto result;
365
			goto result;
 Lines 368-405   int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) { Link Here 
368
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
368
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
369
			goto result;
369
			goto result;
370
		}
370
		}
371
		cur2 = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
371
		curb = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
372
		(*cur2)->name = strdup((*cur1)->name);
372
		(*curb)->name = strdup((*curs)->name);
373
		(*cur2)->values = NULL;
373
		(*curb)->values = NULL;
374
		(*cur2)->length = NULL;
374
		(*curb)->length = NULL;
375
		(*cur2)->value_count = 0;
375
		(*curb)->value_count = 0;
376
		backup_cache_entry->attributes[backup_cache_entry->attribute_count + 1] = NULL;
376
		backup_cache_entry->attributes[backup_cache_entry->attribute_count + 1] = NULL;
377
377
378
		for (i = 0; i < (*cur1)->value_count; i++) {
378
		for (i = 0; i < (*curs)->value_count; i++) {
379
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count + 2) * sizeof(char*))) == NULL) {
379
			if (((*curb)->values = realloc((*curb)->values, ((*curb)->value_count + 2) * sizeof(char*))) == NULL) {
380
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
380
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
381
				goto result;
381
				goto result;
382
			}
382
			}
383
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count + 2) * sizeof(int))) == NULL) {
383
			if (((*curb)->length = realloc((*curb)->length, ((*curb)->value_count + 2) * sizeof(int))) == NULL) {
384
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
384
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
385
				goto result;
385
				goto result;
386
			}
386
			}
387
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
387
			if ((*curs)->length[i] == strlen((*curs)->values[i]) + 1) {
388
				if (((*cur2)->values[(*cur2)->value_count] = strdup((*cur1)->values[i])) == NULL) {
388
				if (((*curb)->values[(*curb)->value_count] = strdup((*curs)->values[i])) == NULL) {
389
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
389
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
390
					goto result;
390
					goto result;
391
				}
391
				}
392
				(*cur2)->length[(*cur2)->value_count] = strlen((*cur2)->values[(*cur2)->value_count]) + 1;
392
				(*curb)->length[(*curb)->value_count] = strlen((*curb)->values[(*curb)->value_count]) + 1;
393
			} else {
393
			} else {
394
				if (((*cur2)->values[(*cur2)->value_count] = malloc(((*cur1)->length[i]) * sizeof(char))) == NULL) {
394
				if (((*curb)->values[(*curb)->value_count] = malloc(((*curs)->length[i]) * sizeof(char))) == NULL) {
395
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
395
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
396
					goto result;
396
					goto result;
397
				}
397
				}
398
				memcpy((*cur2)->values[(*cur2)->value_count], (*cur1)->values[i], (*cur1)->length[i]);
398
				memcpy((*curb)->values[(*curb)->value_count], (*curs)->values[i], (*curs)->length[i]);
399
				(*cur2)->length[(*cur2)->value_count] = (*cur1)->length[i];
399
				(*curb)->length[(*curb)->value_count] = (*curs)->length[i];
400
			}
400
			}
401
			(*cur2)->values[(*cur2)->value_count+1] = NULL;
401
			(*curb)->values[(*curb)->value_count+1] = NULL;
402
			(*cur2)->value_count++;
402
			(*curb)->value_count++;
403
		}
403
		}
404
		backup_cache_entry->attribute_count++;
404
		backup_cache_entry->attribute_count++;
405
	}
405
	}
 Lines 462-483   void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry) Link Here 
462
	}
462
	}
463
	free(changes);
463
	free(changes);
464
464
465
	char **cur1, **cur2;
465
	char **curl, **curr;
466
466
467
	for (cur1 = lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++) {
467
	for (curl = lentry->modules; curl != NULL && *curl != NULL; curl++) {
468
		for (cur2 = rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++)
468
		for (curr = rentry->modules; curr != NULL && *curr != NULL; curr++)
469
			if (strcmp(*cur1, *cur2) == 0)
469
			if (strcmp(*curl, *curr) == 0)
470
				break;
470
				break;
471
		if (cur2 != NULL && *cur2 != NULL)
471
		if (curr != NULL && *curr != NULL)
472
			continue;
472
			continue;
473
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on lentry missing on rentry\n", *cur1);
473
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on lentry missing on rentry\n", *curl);
474
	}
474
	}
475
	for (cur2 = rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++) {
475
	for (curr = rentry->modules; curr != NULL && *curr != NULL; curr++) {
476
		for (cur1 = lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++)
476
		for (curl = lentry->modules; curl != NULL && *curl != NULL; curl++)
477
			if (strcmp(*cur1, *cur2) == 0)
477
			if (strcmp(*curl, *curr) == 0)
478
				break;
478
				break;
479
		if (cur1 != NULL && *cur1 != NULL)
479
		if (curl != NULL && *curl != NULL)
480
			continue;
480
			continue;
481
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on rentry missing on lentry\n", *cur2);
481
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on rentry missing on lentry\n", *curr);
482
	}
482
	}
483
}
483
}
484
   Bug #30227: listener: declare functions extern
484
   Bug #30227: listener: declare functions extern
485
   
485
   
486
   Mark all functions as extern, because the compiler will otherwise expect
486
   Mark all functions as extern, because the compiler will otherwise expect
487
   the real declaration after the declaration.
487
   the real declaration after the declaration.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/base64.h (-2 / +2 lines)
 Lines 39-49    Link Here 
39
#define BASE64_ENCODE_LEN(n)      (((n)+2)/3 * 4)
39
#define BASE64_ENCODE_LEN(n)      (((n)+2)/3 * 4)
40
#define BASE64_DECODE_LEN(n)      (((n)+3)/4 * 3)
40
#define BASE64_DECODE_LEN(n)      (((n)+3)/4 * 3)
41
41
42
int base64_encode(u_char const *src,
42
extern int base64_encode(u_char const *src,
43
	size_t srclength,
43
	size_t srclength,
44
	char *target,
44
	char *target,
45
	size_t targsize);
45
	size_t targsize);
46
int base64_decode(char const *src,
46
extern int base64_decode(char const *src,
47
	u_char *target,
47
	u_char *target,
48
	size_t targsize);
48
	size_t targsize);
49
49
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache.h (-17 / +17 lines)
 Lines 48-98   struct _CacheMasterEntry { Link Here 
48
} CacheMasterEntry;
48
} CacheMasterEntry;
49
#endif
49
#endif
50
50
51
int cache_init(void);
51
extern int cache_init(void);
52
#ifdef WITH_DB42
52
#ifdef WITH_DB42
53
int cache_get_master_entry(CacheMasterEntry *master_entry);
53
extern int cache_get_master_entry(CacheMasterEntry *master_entry);
54
int cache_update_master_entry(CacheMasterEntry *master_entry,
54
extern int cache_update_master_entry(CacheMasterEntry *master_entry,
55
		DB_TXN *dptxnp);
55
		DB_TXN *dptxnp);
56
#endif
56
#endif
57
int cache_update_entry(NotifierID id,
57
extern int cache_update_entry(NotifierID id,
58
		char *dn,
58
		char *dn,
59
		CacheEntry *entry);
59
		CacheEntry *entry);
60
inline int cache_update_entry_lower(NotifierID id,
60
inline int cache_update_entry_lower(NotifierID id,
61
		char *dn,
61
		char *dn,
62
		CacheEntry *entry);
62
		CacheEntry *entry);
63
int cache_delete_entry(NotifierID id,
63
extern int cache_delete_entry(NotifierID id,
64
		char *dn);
64
		char *dn);
65
int cache_delete_entry_lower_upper(NotifierID id,
65
extern int cache_delete_entry_lower_upper(NotifierID id,
66
		char *dn);
66
		char *dn);
67
int cache_update_or_deleteifunused_entry(NotifierID id,
67
extern int cache_update_or_deleteifunused_entry(NotifierID id,
68
		char *dn,
68
		char *dn,
69
		CacheEntry *entry);
69
		CacheEntry *entry);
70
int cache_get_entry(NotifierID id,
70
extern int cache_get_entry(NotifierID id,
71
		char *dn,
71
		char *dn,
72
		CacheEntry *entry);
72
		CacheEntry *entry);
73
int cache_get_entry_lower_upper(NotifierID id,
73
extern int cache_get_entry_lower_upper(NotifierID id,
74
		char *dn,
74
		char *dn,
75
		CacheEntry *entry);
75
		CacheEntry *entry);
76
int cache_first_entry(DBC **cur,
76
extern int cache_first_entry(DBC **cur,
77
		char **dn,
77
		char **dn,
78
		CacheEntry *entry);
78
		CacheEntry *entry);
79
int cache_next_entry(DBC **cur,
79
extern int cache_next_entry(DBC **cur,
80
		char **dn,
80
		char **dn,
81
		CacheEntry *entry);
81
		CacheEntry *entry);
82
int cache_free_cursor(DBC *cur);
82
extern int cache_free_cursor(DBC *cur);
83
int cache_close(void);
83
extern int cache_close(void);
84
84
85
/* deprecated with DB42*/
85
/* deprecated with DB42*/
86
int cache_set_int(const char *key,
86
extern int cache_set_int(const char *key,
87
		const NotifierID value);
87
		const NotifierID value);
88
int cache_get_int(const char *key,
88
extern int cache_get_int(const char *key,
89
		NotifierID *value,
89
		NotifierID *value,
90
		const long def);
90
		const long def);
91
91
92
int cache_get_schema_id(const char *key,
92
extern int cache_get_schema_id(const char *key,
93
		NotifierID *value,
93
		NotifierID *value,
94
		const long def);
94
		const long def);
95
int cache_set_schema_id(const char *key,
95
extern int cache_set_schema_id(const char *key,
96
		const NotifierID value);
96
		const NotifierID value);
97
97
98
#endif /* _CACHE_H_ */
98
#endif /* _CACHE_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.h (-9 / +9 lines)
 Lines 53-80   struct _CacheEntry { Link Here 
53
/* Initialize interal setting once. */
53
/* Initialize interal setting once. */
54
extern void cache_entry_init(void);
54
extern void cache_entry_init(void);
55
55
56
int cache_free_entry(char **dn,
56
extern int cache_free_entry(char **dn,
57
		CacheEntry *entry);
57
		CacheEntry *entry);
58
int cache_dump_entry(char *dn,
58
extern int cache_dump_entry(char *dn,
59
		CacheEntry *entry,
59
		CacheEntry *entry,
60
		FILE *fp);
60
		FILE *fp);
61
int cache_new_entry_from_ldap(char **dn,
61
extern int cache_new_entry_from_ldap(char **dn,
62
		CacheEntry *cache_entry,
62
		CacheEntry *cache_entry,
63
		LDAP *ld,
63
		LDAP *ld,
64
		LDAPMessage *ldap_entry);
64
		LDAPMessage *ldap_entry);
65
int cache_entry_module_add(CacheEntry *entry,
65
extern int cache_entry_module_add(CacheEntry *entry,
66
		char *module);
66
		char *module);
67
int cache_entry_module_remove(CacheEntry *entry,
67
extern int cache_entry_module_remove(CacheEntry *entry,
68
		char *module);
68
		char *module);
69
int cache_entry_module_present(CacheEntry *entry,
69
extern int cache_entry_module_present(CacheEntry *entry,
70
		char *module);
70
		char *module);
71
char** cache_entry_changed_attributes(CacheEntry *new,
71
extern char** cache_entry_changed_attributes(CacheEntry *new,
72
		CacheEntry *old);
72
		CacheEntry *old);
73
73
74
int copy_cache_entry(CacheEntry *cache_entry,
74
extern int copy_cache_entry(CacheEntry *cache_entry,
75
		CacheEntry *backup_cache_entry);
75
		CacheEntry *backup_cache_entry);
76
76
77
void compare_cache_entries(CacheEntry *lentry,
77
extern void compare_cache_entries(CacheEntry *lentry,
78
		CacheEntry *rentry);
78
		CacheEntry *rentry);
79
79
80
#endif /* _CACHE_ENTRY_H_ */
80
#endif /* _CACHE_ENTRY_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.h (-3 / +3 lines)
 Lines 35-47    Link Here 
35
35
36
#include "cache.h"
36
#include "cache.h"
37
37
38
int unparse_entry(void **data,
38
extern int unparse_entry(void **data,
39
		u_int32_t *size,
39
		u_int32_t *size,
40
		CacheEntry *entry);
40
		CacheEntry *entry);
41
int parse_entry(void *data,
41
extern int parse_entry(void *data,
42
		u_int32_t size,
42
		u_int32_t size,
43
		CacheEntry *entry);
43
		CacheEntry *entry);
44
void hex_dump(int level,
44
extern void hex_dump(int level,
45
		void *data,
45
		void *data,
46
		u_int32_t start,
46
		u_int32_t start,
47
		u_int32_t size);
47
		u_int32_t size);
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/change.h (-5 / +5 lines)
 Lines 38-53    Link Here 
38
38
39
#include "network.h"
39
#include "network.h"
40
40
41
int change_new_modules(univention_ldap_parameters_t *lp);
41
extern int change_new_modules(univention_ldap_parameters_t *lp);
42
int change_update_schema(univention_ldap_parameters_t *lp);
42
extern int change_update_schema(univention_ldap_parameters_t *lp);
43
int change_update_entry(univention_ldap_parameters_t *lp,
43
extern int change_update_entry(univention_ldap_parameters_t *lp,
44
		NotifierID id,
44
		NotifierID id,
45
		LDAPMessage *ldap_entry,
45
		LDAPMessage *ldap_entry,
46
		char command);
46
		char command);
47
int change_delete_dn(NotifierID id,
47
extern int change_delete_dn(NotifierID id,
48
		char *dn,
48
		char *dn,
49
		char command);
49
		char command);
50
int change_update_dn(univention_ldap_parameters_t *lp,
50
extern int change_update_dn(univention_ldap_parameters_t *lp,
51
		NotifierID id,
51
		NotifierID id,
52
		char *dn,
52
		char *dn,
53
		char command,
53
		char command,
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/common.h (-1 / +1 lines)
 Lines 33-39    Link Here 
33
#ifndef _COMMON_H_
33
#ifndef _COMMON_H_
34
#define _COMMON_H_
34
#define _COMMON_H_
35
35
36
void drop_privileges(void);
36
extern void drop_privileges(void);
37
37
38
#ifdef DMALLOC
38
#ifdef DMALLOC
39
#include <dmalloc.h>
39
#include <dmalloc.h>
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/filter.h (-1 / +1 lines)
 Lines 36-42    Link Here 
36
#include "cache.h"
36
#include "cache.h"
37
#include "handlers.h"
37
#include "handlers.h"
38
38
39
int cache_entry_ldap_filter_match(struct filter **filter,
39
extern int cache_entry_ldap_filter_match(struct filter **filter,
40
	char *dn,
40
	char *dn,
41
	CacheEntry *entry);
41
	CacheEntry *entry);
42
42
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/handlers.h (-15 / +15 lines)
 Lines 79-110   struct _Handler { Link Here 
79
	int prepared : 1;
79
	int prepared : 1;
80
} typedef Handler;
80
} typedef Handler;
81
81
82
int handlers_init(void);
82
extern int handlers_init(void);
83
int handlers_free_all(void);
83
extern int handlers_free_all(void);
84
int handlers_load_path(char *filename);
84
extern int handlers_load_path(char *filename);
85
int handlers_reload_all_paths(void);
85
extern int handlers_reload_all_paths(void);
86
int handlers_dump(void);
86
extern int handlers_dump(void);
87
int handlers_update(char *dn,
87
extern 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);
91
	CacheEntry *scratch);
92
int handler_update(char *dn,
92
extern int handler_update(char *dn,
93
	CacheEntry *new,
93
	CacheEntry *new,
94
	CacheEntry *old,
94
	CacheEntry *old,
95
	Handler *handler,
95
	Handler *handler,
96
	char command,
96
	char command,
97
	CacheEntry *scratch);
97
	CacheEntry *scratch);
98
int handlers_delete(char *dn,
98
extern int handlers_delete(char *dn,
99
	CacheEntry *old,
99
	CacheEntry *old,
100
	char command);
100
	char command);
101
int handler_clean(Handler *handler);
101
extern int handler_clean(Handler *handler);
102
int handlers_clean_all(void);
102
extern int handlers_clean_all(void);
103
int handler_initialize(Handler *handler);
103
extern int handler_initialize(Handler *handler);
104
int handlers_initialize_all(void);
104
extern int handlers_initialize_all(void);
105
int handlers_postrun_all(void);
105
extern int handlers_postrun_all(void);
106
int handlers_set_data_all(char *key,
106
extern int handlers_set_data_all(char *key,
107
	char *value);
107
	char *value);
108
char *handlers_filter(void);
108
extern char *handlers_filter(void);
109
109
110
#endif /* _HANDLERS_H_ */
110
#endif /* _HANDLERS_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/network.h (-12 / +12 lines)
 Lines 61-91   struct _NotifierClient { Link Here 
61
	char *buf;
61
	char *buf;
62
} typedef NotifierClient;
62
} typedef NotifierClient;
63
63
64
void notifier_entry_free(NotifierEntry *entry);
64
extern void notifier_entry_free(NotifierEntry *entry);
65
int notifier_client_new(NotifierClient *client,
65
extern int notifier_client_new(NotifierClient *client,
66
	const char *server,
66
	const char *server,
67
	int starttls);
67
	int starttls);
68
void notifier_client_destroy(NotifierClient *client);
68
extern void notifier_client_destroy(NotifierClient *client);
69
int notifier_wait(NotifierClient *client,
69
extern int notifier_wait(NotifierClient *client,
70
	time_t timeout);
70
	time_t timeout);
71
71
72
int notifier_recv_result(NotifierClient *client,
72
extern int notifier_recv_result(NotifierClient *client,
73
	time_t timeout);
73
	time_t timeout);
74
NotifierMessage*  notifier_get_msg(NotifierClient *client,
74
extern NotifierMessage*  notifier_get_msg(NotifierClient *client,
75
	int msgid);
75
	int msgid);
76
76
77
int notifier_get_dn(NotifierClient *client,
77
extern int notifier_get_dn(NotifierClient *client,
78
	NotifierID id);
78
	NotifierID id);
79
int notifier_resend_get_dn(NotifierClient *client,
79
extern int notifier_resend_get_dn(NotifierClient *client,
80
	int msgid,
80
	int msgid,
81
	NotifierID id);
81
	NotifierID id);
82
int notifier_get_dn_result(NotifierClient *client,
82
extern int notifier_get_dn_result(NotifierClient *client,
83
	int msgid,
83
	int msgid,
84
	NotifierEntry *entry);
84
	NotifierEntry *entry);
85
int notifier_alive_s(NotifierClient *client);
85
extern int notifier_alive_s(NotifierClient *client);
86
int notifier_get_id_s(NotifierClient *client,
86
extern int notifier_get_id_s(NotifierClient *client,
87
	NotifierID *id);
87
	NotifierID *id);
88
int notifier_get_schema_id_s(NotifierClient *client,
88
extern int notifier_get_schema_id_s(NotifierClient *client,
89
	NotifierID *id);
89
	NotifierID *id);
90
90
91
#endif /* _NETWORK_H_ */
91
#endif /* _NETWORK_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/notifier.h (-1 / +1 lines)
 Lines 40-46    Link Here 
40
typedef void univention_krb5_parameters_t;
40
typedef void univention_krb5_parameters_t;
41
#endif
41
#endif
42
42
43
int notifier_listen(univention_ldap_parameters_t *lp,
43
extern int notifier_listen(univention_ldap_parameters_t *lp,
44
	univention_krb5_parameters_t *kp,
44
	univention_krb5_parameters_t *kp,
45
	int write_transaction_file,
45
	int write_transaction_file,
46
	univention_ldap_parameters_t *lp_local);
46
	univention_ldap_parameters_t *lp_local);
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/select_server.h (-2 / +2 lines)
 Lines 40-46   struct server_list { Link Here 
40
	int conn_attemp;
40
	int conn_attemp;
41
};
41
};
42
42
43
void select_server(univention_ldap_parameters_t *lp);
43
extern void select_server(univention_ldap_parameters_t *lp);
44
int suspend_connect(void);
44
extern int suspend_connect(void);
45
45
46
#endif
46
#endif
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/signals.h (-3 / +3 lines)
 Lines 33-41    Link Here 
33
#ifndef _SIGNALS_H_
33
#ifndef _SIGNALS_H_
34
#define _SIGNALS_H_
34
#define _SIGNALS_H_
35
35
36
void signals_block(void);
36
extern void signals_block(void);
37
void signals_unblock(void);
37
extern void signals_unblock(void);
38
void signals_init(void);
38
extern void signals_init(void);
39
39
40
extern void exit_handler(int sig) __attribute__((noreturn));
40
extern void exit_handler(int sig) __attribute__((noreturn));
41
41
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/transfile.h (-1 / +1 lines)
 Lines 36-41    Link Here 
36
#include "network.h"
36
#include "network.h"
37
37
38
extern char *transaction_file;
38
extern char *transaction_file;
39
int notifier_write_transaction_file(NotifierEntry entry);
39
extern int notifier_write_transaction_file(NotifierEntry entry);
40
40
41
#endif /* _TRANSFILE_H_ */
41
#endif /* _TRANSFILE_H_ */
42
   Bug #30227: listener: white space cleanup
42
   Bug #30227: listener: white space cleanup
43
   
43
   
44
   Remove traling blanks.
44
   Remove traling blanks.
45
   Break long lines.
45
   Break long lines.
46
   Insert blanks before assignment, comparison, after keyword.
46
   Insert blanks before assignment, comparison, after keyword.
47
   Reformat header files.
47
   Reformat header files.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/base64.h (-7 / +7 lines)
 Lines 39-50    Link Here 
39
#define BASE64_ENCODE_LEN(n)      (((n)+2)/3 * 4)
39
#define BASE64_ENCODE_LEN(n)      (((n)+2)/3 * 4)
40
#define BASE64_DECODE_LEN(n)      (((n)+3)/4 * 3)
40
#define BASE64_DECODE_LEN(n)      (((n)+3)/4 * 3)
41
41
42
int	base64_encode	(u_char const	*src,
42
int base64_encode(u_char const *src,
43
			 size_t		 srclength,
43
	size_t srclength,
44
			 char		*target,
44
	char *target,
45
			 size_t		 targsize);
45
	size_t targsize);
46
int	base64_decode	(char const	*src,
46
int base64_decode(char const *src,
47
			 u_char		*target,
47
	u_char *target,
48
			 size_t		 targsize);
48
	size_t targsize);
49
49
50
#endif /* _BASE64_H_ */
50
#endif /* _BASE64_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache.h (-38 / +41 lines)
 Lines 48-95   struct _CacheMasterEntry { Link Here 
48
} CacheMasterEntry;
48
} CacheMasterEntry;
49
#endif
49
#endif
50
50
51
int	cache_init				(void);
51
int cache_init(void);
52
#ifdef WITH_DB42
52
#ifdef WITH_DB42
53
int	cache_get_master_entry			(CacheMasterEntry	 *master_entry);
53
int cache_get_master_entry(CacheMasterEntry *master_entry);
54
int	cache_update_master_entry		(CacheMasterEntry	 *master_entry,
54
int cache_update_master_entry(CacheMasterEntry *master_entry,
55
						 DB_TXN			 *dptxnp);
55
		DB_TXN *dptxnp);
56
#endif
56
#endif
57
int	cache_update_entry			(NotifierID		  id,
57
int cache_update_entry(NotifierID id,
58
						 char			 *dn,
58
		char *dn,
59
						 CacheEntry		 *entry);
59
		CacheEntry *entry);
60
inline int	cache_update_entry_lower			(NotifierID		  id,
60
inline int cache_update_entry_lower(NotifierID id,
61
						 char			 *dn,
61
		char *dn,
62
						 CacheEntry		 *entry);
62
		CacheEntry *entry);
63
int	cache_delete_entry			(NotifierID		  id,
63
int cache_delete_entry(NotifierID id,
64
						 char			 *dn);
64
		char *dn);
65
int	cache_delete_entry_lower_upper			(NotifierID		  id,
65
int cache_delete_entry_lower_upper(NotifierID id,
66
						 char			 *dn);
66
		char *dn);
67
int	cache_update_or_deleteifunused_entry	(NotifierID		  id,
67
int cache_update_or_deleteifunused_entry(NotifierID id,
68
						 char			 *dn,
68
		char *dn,
69
						 CacheEntry		 *entry);
69
		CacheEntry *entry);
70
int	cache_get_entry				(NotifierID		  id,
70
int cache_get_entry(NotifierID id,
71
						 char			 *dn,
71
		char *dn,
72
						 CacheEntry		 *entry);
72
		CacheEntry *entry);
73
int	cache_get_entry_lower_upper				(NotifierID		  id,
73
int cache_get_entry_lower_upper(NotifierID id,
74
						 char			 *dn,
74
		char *dn,
75
						 CacheEntry		 *entry);
75
		CacheEntry *entry);
76
int	cache_first_entry			(DBC			**cur,
76
int cache_first_entry(DBC **cur,
77
						 char			**dn,
77
		char **dn,
78
						 CacheEntry		 *entry);
78
		CacheEntry *entry);
79
int	cache_next_entry			(DBC			**cur,
79
int cache_next_entry(DBC **cur,
80
						 char			**dn,
80
		char **dn,
81
						 CacheEntry		 *entry);
81
		CacheEntry *entry);
82
int	cache_free_cursor			(DBC			 *cur);
82
int cache_free_cursor(DBC *cur);
83
int	cache_close				(void);
83
int cache_close(void);
84
84
85
/* deprecated with DB42*/
85
/* deprecated with DB42*/
86
int	cache_set_int				(const char		 *key,
86
int cache_set_int(const char *key,
87
						 const NotifierID		  value);
87
		const NotifierID value);
88
int	cache_get_int				(const char		 *key,
88
int cache_get_int(const char *key,
89
						 NotifierID			 *value,
89
		NotifierID *value,
90
						 const long		  def);
90
		const long def);
91
91
92
int cache_get_schema_id(const char *key, NotifierID *value, const long def);
92
int cache_get_schema_id(const char *key,
93
int cache_set_schema_id(const char *key, const NotifierID value);
93
		NotifierID *value,
94
		const long def);
95
int cache_set_schema_id(const char *key,
96
		const NotifierID value);
94
97
95
#endif /* _CACHE_H_ */
98
#endif /* _CACHE_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-49 / +52 lines)
 Lines 114-120   int cache_dump_entry(char *dn, CacheEntry *entry, FILE *fp) Link Here 
114
			if (len >= 0) {
114
			if (len >= 0) {
115
				char *base64_value;
115
				char *base64_value;
116
				size_t srclen = attribute->length[j] - 1;
116
				size_t srclen = attribute->length[j] - 1;
117
				base64_value = malloc(BASE64_ENCODE_LEN(srclen)+1);
117
				base64_value = malloc(BASE64_ENCODE_LEN(srclen) + 1);
118
				if (!base64_value)
118
				if (!base64_value)
119
					return 1;
119
					return 1;
120
				base64_encode((u_char *)value, srclen, base64_value, BASE64_ENCODE_LEN(srclen) + 1);
120
				base64_encode((u_char *)value, srclen, base64_value, BASE64_ENCODE_LEN(srclen) + 1);
 Lines 125-131   int cache_dump_entry(char *dn, CacheEntry *entry, FILE *fp) Link Here 
125
			}
125
			}
126
		}
126
		}
127
	}
127
	}
128
	for (module=entry->modules; module != NULL && *module != NULL; module++) {
128
	for (module = entry->modules; module != NULL && *module != NULL; module++) {
129
		fprintf(fp, "listenerModule: %s\n", *module);
129
		fprintf(fp, "listenerModule: %s\n", *module);
130
	}
130
	}
131
131
 Lines 136-147   int cache_entry_module_add(CacheEntry *entry, char *module) Link Here 
136
{
136
{
137
	char **cur;
137
	char **cur;
138
138
139
	for (cur=entry->modules; cur != NULL && *cur != NULL; cur++) {
139
	for (cur = entry->modules; cur != NULL && *cur != NULL; cur++) {
140
		if (strcmp(*cur, module) == 0)
140
		if (strcmp(*cur, module) == 0)
141
			return 0;
141
			return 0;
142
	}
142
	}
143
143
144
	entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
144
	entry->modules = realloc(entry->modules, (entry->module_count + 2) * sizeof(char*));
145
	if (!entry->modules)
145
	if (!entry->modules)
146
		return 1;
146
		return 1;
147
	entry->modules[entry->module_count++] = strdup(module);
147
	entry->modules[entry->module_count++] = strdup(module);
 Lines 154-160   int cache_entry_module_remove(CacheEntry *entry, char *module) Link Here 
154
{
154
{
155
	char **cur;
155
	char **cur;
156
156
157
	for (cur=entry->modules; cur != NULL && *cur != NULL; cur++) {
157
	for (cur = entry->modules; cur != NULL && *cur != NULL; cur++) {
158
		if (strcmp(*cur, module) == 0)
158
		if (strcmp(*cur, module) == 0)
159
			break;
159
			break;
160
	}
160
	}
 Lines 164-173   int cache_entry_module_remove(CacheEntry *entry, char *module) Link Here 
164
164
165
	/* replace entry that is to be removed with last entry */
165
	/* replace entry that is to be removed with last entry */
166
	free(*cur);
166
	free(*cur);
167
	entry->modules[cur-entry->modules] = entry->modules[entry->module_count-1];
167
	entry->modules[cur-entry->modules] = entry->modules[entry->module_count - 1];
168
	entry->modules[--entry->module_count] = NULL;
168
	entry->modules[--entry->module_count] = NULL;
169
169
170
	entry->modules = realloc(entry->modules, (entry->module_count+1)*sizeof(char*));
170
	entry->modules = realloc(entry->modules, (entry->module_count + 1) * sizeof(char*));
171
171
172
	return 0;
172
	return 0;
173
}
173
}
 Lines 178-184   int cache_entry_module_present(CacheEntry *entry, char *module) Link Here 
178
178
179
	if (entry == NULL)
179
	if (entry == NULL)
180
		return 0;
180
		return 0;
181
	for (cur=entry->modules; cur != NULL && *cur != NULL; cur++) {
181
	for (cur = entry->modules; cur != NULL && *cur != NULL; cur++) {
182
		if (strcmp(*cur, module) == 0)
182
		if (strcmp(*cur, module) == 0)
183
			return 1;
183
			return 1;
184
	}
184
	}
 Lines 200-215   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
200
	memset(cache_entry, 0, sizeof(CacheEntry));
200
	memset(cache_entry, 0, sizeof(CacheEntry));
201
	if (dn != NULL) {
201
	if (dn != NULL) {
202
		char *_dn = ldap_get_dn(ld, ldap_entry);
202
		char *_dn = ldap_get_dn(ld, ldap_entry);
203
		if(*dn)
203
		if (*dn)
204
				free(*dn);
204
			free(*dn);
205
		*dn = strdup(_dn);
205
		*dn = strdup(_dn);
206
		ldap_memfree(_dn);
206
		ldap_memfree(_dn);
207
	}
207
	}
208
208
209
	for (attr=ldap_first_attribute(ld, ldap_entry, &ber); attr != NULL; attr=ldap_next_attribute(ld, ldap_entry, ber)) {
209
	for (attr = ldap_first_attribute(ld, ldap_entry, &ber);
210
			attr != NULL;
211
			attr = ldap_next_attribute(ld, ldap_entry, ber)) {
210
		struct berval **val, **v;
212
		struct berval **val, **v;
211
213
212
		if ((cache_entry->attributes = realloc(cache_entry->attributes, (cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) {
214
		if ((cache_entry->attributes = realloc(cache_entry->attributes, (cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute*))) == NULL) {
213
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of attributes array failed");
215
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of attributes array failed");
214
			goto result;
216
			goto result;
215
		}
217
		}
 Lines 230-241   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
230
			check = UNIQUE_MEMBER;
232
			check = UNIQUE_MEMBER;
231
		else
233
		else
232
			check = DUPLICATES;
234
			check = DUPLICATES;
233
		if ((val=ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
235
		if ((val = ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
234
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ldap_get_values failed");
236
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ldap_get_values failed");
235
			goto result;
237
			goto result;
236
		}
238
		}
237
		for (v = val; *v != NULL; v++) {
239
		for (v = val; *v != NULL; v++) {
238
			if ( (*v)->bv_val == NULL ) {
240
			if ((*v)->bv_val == NULL) {
239
				// check here, strlen behavior might be undefined in this case
241
				// check here, strlen behavior might be undefined in this case
240
				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, c_attr->name, *dn);
242
				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, c_attr->name, *dn);
241
				goto result;
243
				goto result;
 Lines 243-249   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
243
			if (memberUidMode && check == UNIQUE_UID) {
245
			if (memberUidMode && check == UNIQUE_UID) {
244
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
246
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
245
				for (i = 0; i < c_attr->value_count; i++) {
247
				for (i = 0; i < c_attr->value_count; i++) {
246
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
248
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len + 1) ) {
247
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate memberUid entry:");
249
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate memberUid entry:");
248
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
250
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
249
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "memberUid: %s", c_attr->values[i]);
251
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "memberUid: %s", c_attr->values[i]);
 Lines 257-263   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
257
			if (uniqueMemberMode && check == UNIQUE_MEMBER) {
259
			if (uniqueMemberMode && check == UNIQUE_MEMBER) {
258
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
260
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
259
				for (i = 0; i < c_attr->value_count; i++) {
261
				for (i = 0; i < c_attr->value_count; i++) {
260
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1)) {
262
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len + 1)) {
261
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate uniqueMember entry:");
263
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate uniqueMember entry:");
262
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
264
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
263
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "uniqueMember: %s", c_attr->values[i]);
265
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "uniqueMember: %s", c_attr->values[i]);
 Lines 331-337   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
331
				continue;
333
				continue;
332
		}
334
		}
333
335
334
		changes = realloc(changes, (changes_count+2)*sizeof(char*));
336
		changes = realloc(changes, (changes_count + 2) * sizeof(char*));
335
		changes[changes_count++] = (*cur1)->name;
337
		changes[changes_count++] = (*cur1)->name;
336
		changes[changes_count] = NULL;
338
		changes[changes_count] = NULL;
337
	}
339
	}
 Lines 343-349   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
343
		if (cur1 != NULL && *cur1 != NULL)
345
		if (cur1 != NULL && *cur1 != NULL)
344
			continue;
346
			continue;
345
347
346
		changes = realloc(changes, (changes_count+2)*sizeof(char*));
348
		changes = realloc(changes, (changes_count + 2) * sizeof(char*));
347
		changes[changes_count++] = (*cur2)->name;
349
		changes[changes_count++] = (*cur2)->name;
348
		changes[changes_count] = NULL;
350
		changes[changes_count] = NULL;
349
	}
351
	}
 Lines 353-363   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
353
355
354
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
356
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
355
	CacheEntryAttribute **cur1, **cur2;
357
	CacheEntryAttribute **cur1, **cur2;
356
	int i=0;
358
	int i;
357
	int rv=1;
359
	int rv = 1;
360
358
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
361
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
359
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
362
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
360
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) {
363
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count + 2) * sizeof(CacheEntryAttribute*))) == NULL) {
361
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
364
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
362
			goto result;
365
			goto result;
363
		}
366
		}
 Lines 366-410   int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) { Link Here 
366
			goto result;
369
			goto result;
367
		}
370
		}
368
		cur2 = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
371
		cur2 = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
369
		(*cur2)->name=strdup((*cur1)->name);
372
		(*cur2)->name = strdup((*cur1)->name);
370
		(*cur2)->values=NULL;
373
		(*cur2)->values = NULL;
371
		(*cur2)->length=NULL;
374
		(*cur2)->length = NULL;
372
		(*cur2)->value_count=0;
375
		(*cur2)->value_count = 0;
373
		backup_cache_entry->attributes[backup_cache_entry->attribute_count+1]=NULL;
376
		backup_cache_entry->attributes[backup_cache_entry->attribute_count + 1] = NULL;
374
377
375
		for (i = 0; i < (*cur1)->value_count; i++) {
378
		for (i = 0; i < (*cur1)->value_count; i++) {
376
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count+2)*sizeof(char*))) == NULL) {
379
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count + 2) * sizeof(char*))) == NULL) {
377
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
380
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
378
				goto result;
381
				goto result;
379
			}
382
			}
380
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count+2)*sizeof(int))) == NULL) {
383
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count + 2) * sizeof(int))) == NULL) {
381
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
384
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
382
				goto result;
385
				goto result;
383
			}
386
			}
384
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
387
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
385
				if (((*cur2)->values[(*cur2)->value_count]=strdup((*cur1)->values[i])) == NULL) {
388
				if (((*cur2)->values[(*cur2)->value_count] = strdup((*cur1)->values[i])) == NULL) {
386
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
389
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
387
					goto result;
390
					goto result;
388
				}
391
				}
389
				(*cur2)->length[(*cur2)->value_count]=strlen((*cur2)->values[(*cur2)->value_count])+1;
392
				(*cur2)->length[(*cur2)->value_count] = strlen((*cur2)->values[(*cur2)->value_count]) + 1;
390
			} else {
393
			} else {
391
				if (((*cur2)->values[(*cur2)->value_count]=malloc(((*cur1)->length[i])*sizeof(char))) == NULL) {
394
				if (((*cur2)->values[(*cur2)->value_count] = malloc(((*cur1)->length[i]) * sizeof(char))) == NULL) {
392
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
395
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
393
					goto result;
396
					goto result;
394
				}
397
				}
395
				memcpy((*cur2)->values[(*cur2)->value_count],(*cur1)->values[i],(*cur1)->length[i]);
398
				memcpy((*cur2)->values[(*cur2)->value_count], (*cur1)->values[i], (*cur1)->length[i]);
396
				(*cur2)->length[(*cur2)->value_count]=(*cur1)->length[i];
399
				(*cur2)->length[(*cur2)->value_count] = (*cur1)->length[i];
397
			}
400
			}
398
			(*cur2)->values[(*cur2)->value_count+1]=NULL;
401
			(*cur2)->values[(*cur2)->value_count+1] = NULL;
399
			(*cur2)->value_count++;
402
			(*cur2)->value_count++;
400
		}
403
		}
401
		backup_cache_entry->attribute_count++;
404
		backup_cache_entry->attribute_count++;
402
	}
405
	}
403
	char **module_ptr;
406
	char **module_ptr;
404
	for (module_ptr=cache_entry->modules; module_ptr != NULL && *module_ptr != NULL; module_ptr++) {
407
	for (module_ptr = cache_entry->modules; module_ptr != NULL && *module_ptr != NULL; module_ptr++) {
405
		backup_cache_entry->modules = realloc(backup_cache_entry->modules, (backup_cache_entry->module_count+2)*sizeof(char*));
408
		backup_cache_entry->modules = realloc(backup_cache_entry->modules, (backup_cache_entry->module_count + 2) * sizeof(char*));
406
		backup_cache_entry->modules[backup_cache_entry->module_count] = strdup(*module_ptr);
409
		backup_cache_entry->modules[backup_cache_entry->module_count] = strdup(*module_ptr);
407
		backup_cache_entry->modules[backup_cache_entry->module_count+1] = NULL;
410
		backup_cache_entry->modules[backup_cache_entry->module_count +1] = NULL;
408
		backup_cache_entry->module_count++;
411
		backup_cache_entry->module_count++;
409
	}
412
	}
410
	rv = 0;
413
	rv = 0;
 Lines 414-429   result: Link Here 
414
417
415
void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry)
418
void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry)
416
{
419
{
417
	char		**changes;
420
	char **changes;
418
	char		**cur;
421
	char **cur;
419
	int i=0;
422
	int i;
420
423
421
	changes = cache_entry_changed_attributes(lentry, rentry);
424
	changes = cache_entry_changed_attributes(lentry, rentry);
422
425
423
	for (cur = changes; cur != NULL && *cur != NULL; cur++) {
426
	for (cur = changes; cur != NULL && *cur != NULL; cur++) {
424
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     %s differs\n", *cur);
427
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     %s differs\n", *cur);
425
428
426
		for (i=0; lentry->attributes != NULL && lentry->attributes[i] != NULL; i++) {
429
		for (i = 0; lentry->attributes != NULL && lentry->attributes[i] != NULL; i++) {
427
			if (strcmp(lentry->attributes[i]->name, *cur) == 0)
430
			if (strcmp(lentry->attributes[i]->name, *cur) == 0)
428
				break;
431
				break;
429
		}
432
		}
 Lines 432-438   void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry) Link Here 
432
		} else {
435
		} else {
433
			int j;
436
			int j;
434
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         lentry = [");
437
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         lentry = [");
435
			for (j=0; lentry->attributes[i]->values &&
438
			for (j = 0; lentry->attributes[i]->values &&
436
					lentry->attributes[i]->values[j] != NULL;
439
					lentry->attributes[i]->values[j] != NULL;
437
					j++) {
440
					j++) {
438
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", lentry->attributes[i]->values[j]);
441
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", lentry->attributes[i]->values[j]);
 Lines 440-446   void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry) Link Here 
440
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "]\n");
443
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "]\n");
441
		}
444
		}
442
445
443
		for (i=0; rentry->attributes != NULL && rentry->attributes[i] != NULL; i++) {
446
		for (i = 0; rentry->attributes != NULL && rentry->attributes[i] != NULL; i++) {
444
			if (strcmp(rentry->attributes[i]->name, *cur) == 0)
447
			if (strcmp(rentry->attributes[i]->name, *cur) == 0)
445
				break;
448
				break;
446
		}
449
		}
 Lines 449-455   void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry) Link Here 
449
		} else {
452
		} else {
450
			int j;
453
			int j;
451
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         rentry = [");
454
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:         rentry = [");
452
			for (j=0; rentry->attributes[i]->values &&
455
			for (j = 0; rentry->attributes[i]->values &&
453
					rentry->attributes[i]->values[j] != NULL;
456
					rentry->attributes[i]->values[j] != NULL;
454
					j++) {
457
					j++) {
455
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", rentry->attributes[i]->values[j]);
458
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, j == 0 ? "%s" : ", %s", rentry->attributes[i]->values[j]);
 Lines 459-476   void compare_cache_entries(CacheEntry *lentry, CacheEntry *rentry) Link Here 
459
	}
462
	}
460
	free(changes);
463
	free(changes);
461
464
462
	char		**cur1, **cur2;
465
	char **cur1, **cur2;
463
466
464
	for (cur1=lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++) {
467
	for (cur1 = lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++) {
465
		for (cur2=rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++)
468
		for (cur2 = rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++)
466
			if (strcmp(*cur1, *cur2) == 0)
469
			if (strcmp(*cur1, *cur2) == 0)
467
				break;
470
				break;
468
		if (cur2 != NULL && *cur2 != NULL)
471
		if (cur2 != NULL && *cur2 != NULL)
469
			continue;
472
			continue;
470
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on lentry missing on rentry\n", *cur1);
473
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ALERT:     module %s on lentry missing on rentry\n", *cur1);
471
	}
474
	}
472
	for (cur2=rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++) {
475
	for (cur2 = rentry->modules; cur2 != NULL && *cur2 != NULL; cur2++) {
473
		for (cur1=lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++)
476
		for (cur1 = lentry->modules; cur1 != NULL && *cur1 != NULL; cur1++)
474
			if (strcmp(*cur1, *cur2) == 0)
477
			if (strcmp(*cur1, *cur2) == 0)
475
				break;
478
				break;
476
		if (cur1 != NULL && *cur1 != NULL)
479
		if (cur1 != NULL && *cur1 != NULL)
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.h (-29 / +29 lines)
 Lines 37-80    Link Here 
37
#include <ldap.h>
37
#include <ldap.h>
38
38
39
struct _CacheEntryAttribute {
39
struct _CacheEntryAttribute {
40
	char			 *name;
40
	char *name;
41
	char			**values;
41
	char **values;
42
	int			*length;
42
	int *length;
43
	int			  value_count;
43
	int value_count;
44
} typedef CacheEntryAttribute;
44
} typedef CacheEntryAttribute;
45
45
46
struct _CacheEntry {
46
struct _CacheEntry {
47
	CacheEntryAttribute	**attributes;
47
	CacheEntryAttribute **attributes;
48
	int			  attribute_count;
48
	int attribute_count;
49
	char			**modules;
49
	char **modules;
50
	int			  module_count;
50
	int module_count;
51
} typedef CacheEntry;
51
} typedef CacheEntry;
52
52
53
/* Initialize interal setting once. */
53
/* Initialize interal setting once. */
54
extern void cache_entry_init(void);
54
extern void cache_entry_init(void);
55
55
56
int	cache_free_entry		(char		**dn,
56
int cache_free_entry(char **dn,
57
					 CacheEntry	 *entry);
57
		CacheEntry *entry);
58
int	cache_dump_entry		(char		 *dn,
58
int cache_dump_entry(char *dn,
59
					 CacheEntry	 *entry,
59
		CacheEntry *entry,
60
					 FILE		 *fp);
60
		FILE *fp);
61
int	cache_new_entry_from_ldap	(char		**dn,
61
int cache_new_entry_from_ldap(char **dn,
62
					 CacheEntry	 *cache_entry,
62
		CacheEntry *cache_entry,
63
					 LDAP		 *ld,
63
		LDAP *ld,
64
					 LDAPMessage	 *ldap_entry);
64
		LDAPMessage *ldap_entry);
65
int	cache_entry_module_add		(CacheEntry	 *entry,
65
int cache_entry_module_add(CacheEntry *entry,
66
					 char		 *module);
66
		char *module);
67
int	cache_entry_module_remove	(CacheEntry	 *entry,
67
int cache_entry_module_remove(CacheEntry *entry,
68
					 char		 *module);
68
		char *module);
69
int	cache_entry_module_present	(CacheEntry	 *entry,
69
int cache_entry_module_present(CacheEntry *entry,
70
					 char		 *module);
70
		char *module);
71
char**	cache_entry_changed_attributes	(CacheEntry	 *new,
71
char** cache_entry_changed_attributes(CacheEntry *new,
72
					 CacheEntry	 *old);
72
		CacheEntry *old);
73
73
74
int	copy_cache_entry		(CacheEntry *cache_entry,
74
int copy_cache_entry(CacheEntry *cache_entry,
75
					 CacheEntry *backup_cache_entry);
75
		CacheEntry *backup_cache_entry);
76
76
77
void	compare_cache_entries		(CacheEntry *lentry,
77
void compare_cache_entries(CacheEntry *lentry,
78
					 CacheEntry *rentry);
78
		CacheEntry *rentry);
79
79
80
#endif /* _CACHE_ENTRY_H_ */
80
#endif /* _CACHE_ENTRY_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_lowlevel.h (-7 / +10 lines)
 Lines 35-46    Link Here 
35
35
36
#include "cache.h"
36
#include "cache.h"
37
37
38
int	unparse_entry	(void		**data,
38
int unparse_entry(void **data,
39
			 u_int32_t	 *size,
39
		u_int32_t *size,
40
			 CacheEntry	 *entry);
40
		CacheEntry *entry);
41
int	parse_entry	(void		 *data,
41
int parse_entry(void *data,
42
			 u_int32_t	  size,
42
		u_int32_t size,
43
			 CacheEntry	 *entry);
43
		CacheEntry *entry);
44
void hex_dump(int level, void *data, u_int32_t start, u_int32_t size);
44
void hex_dump(int level,
45
		void *data,
46
		u_int32_t start,
47
		u_int32_t size);
45
48
46
#endif /* _CACHE_LOWLEVEL_ */
49
#endif /* _CACHE_LOWLEVEL_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/change.h (-15 / +14 lines)
 Lines 38-57    Link Here 
38
38
39
#include "network.h"
39
#include "network.h"
40
40
41
41
int change_new_modules(univention_ldap_parameters_t *lp);
42
int	change_new_modules	(univention_ldap_parameters_t	*lp);
42
int change_update_schema(univention_ldap_parameters_t *lp);
43
int 	change_update_schema	(univention_ldap_parameters_t	*lp);
43
int change_update_entry(univention_ldap_parameters_t *lp,
44
int	change_update_entry	(univention_ldap_parameters_t	*lp,
44
		NotifierID id,
45
				 NotifierID			 id,
45
		LDAPMessage *ldap_entry,
46
				 LDAPMessage			*ldap_entry,
46
		char command);
47
				 char 				command);
47
int change_delete_dn(NotifierID id,
48
int 	change_delete_dn	(NotifierID			 id,
48
		char *dn,
49
				 char				*dn,
49
		char command);
50
				 char 				command);
50
int change_update_dn(univention_ldap_parameters_t *lp,
51
int 	change_update_dn	(univention_ldap_parameters_t	*lp,
51
		NotifierID id,
52
				 NotifierID			 id,
52
		char *dn,
53
				 char				*dn,
53
		char command,
54
				 char				command,
54
		univention_ldap_parameters_t *lp_local);
55
				 univention_ldap_parameters_t   *lp_local);
56
55
57
#endif /* _CHANGE_H_ */
56
#endif /* _CHANGE_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/filter.h (-3 / +3 lines)
 Lines 36-43    Link Here 
36
#include "cache.h"
36
#include "cache.h"
37
#include "handlers.h"
37
#include "handlers.h"
38
38
39
int	cache_entry_ldap_filter_match	(struct filter	**filter,
39
int cache_entry_ldap_filter_match(struct filter **filter,
40
					 char		 *dn,
40
	char *dn,
41
					 CacheEntry	 *entry);
41
	CacheEntry *entry);
42
42
43
#endif /* _FILTER_H_ */
43
#endif /* _FILTER_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/handlers.h (-44 / +45 lines)
 Lines 55-109    Link Here 
55
#define HANDLER_UNSET_FLAG(handler, flag)	handler->state &= ~flag
55
#define HANDLER_UNSET_FLAG(handler, flag)	handler->state &= ~flag
56
56
57
struct filter {
57
struct filter {
58
	char	*base;
58
	char *base;
59
	int	 scope;
59
	int scope;
60
	char	*filter;
60
	char *filter;
61
};
61
};
62
62
63
struct _Handler {
63
struct _Handler {
64
	PyObject	 *module;
64
	PyObject *module;
65
	char		 *name;
65
	char *name;
66
	char		 *description;
66
	char *description;
67
	struct filter	**filters;
67
	struct filter **filters;
68
	char		**attributes;
68
	char **attributes;
69
	char		*modrdn;
69
	char *modrdn;
70
	PyObject	 *handler;
70
	PyObject *handler;
71
	PyObject	 *initialize;
71
	PyObject *initialize;
72
	PyObject	 *clean;
72
	PyObject *clean;
73
	PyObject	 *postrun;
73
	PyObject *postrun;
74
	PyObject	 *prerun;
74
	PyObject *prerun;
75
	PyObject	 *setdata;
75
	PyObject *setdata;
76
	struct _Handler	 *next;
76
	struct _Handler *next;
77
77
78
	int		  state;
78
	int state;
79
	int		  prepared : 1;
79
	int prepared : 1;
80
} typedef Handler;
80
} typedef Handler;
81
81
82
int	handlers_init			(void);
82
int handlers_init(void);
83
int	handlers_free_all		(void);
83
int handlers_free_all(void);
84
int	handlers_load_path		(char		*filename);
84
int handlers_load_path(char *filename);
85
int	handlers_reload_all_paths	(void);
85
int handlers_reload_all_paths(void);
86
int	handlers_dump			(void);
86
int handlers_dump(void);
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);
91
	CacheEntry *scratch);
92
int	handler_update			(char		*dn,
92
int handler_update(char *dn,
93
					 CacheEntry	*new,
93
	CacheEntry *new,
94
					 CacheEntry	*old,
94
	CacheEntry *old,
95
					 Handler	*handler,
95
	Handler *handler,
96
					 char		command,
96
	char command,
97
					 CacheEntry *scratch);
97
	CacheEntry *scratch);
98
int	handlers_delete			(char		*dn,
98
int handlers_delete(char *dn,
99
					 CacheEntry	*old,
99
	CacheEntry *old,
100
					 char command);
100
	char command);
101
int	handler_clean			(Handler	*handler);
101
int handler_clean(Handler *handler);
102
int	handlers_clean_all		(void);
102
int handlers_clean_all(void);
103
int	handler_initialize		(Handler	*handler);
103
int handler_initialize(Handler *handler);
104
int	handlers_initialize_all		(void);
104
int handlers_initialize_all(void);
105
int	handlers_postrun_all		(void);
105
int handlers_postrun_all(void);
106
int handlers_set_data_all		(char *key, char *value);
106
int handlers_set_data_all(char *key,
107
char*	handlers_filter			(void);
107
	char *value);
108
char *handlers_filter(void);
108
109
109
#endif /* _HANDLERS_H_ */
110
#endif /* _HANDLERS_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/network.h (-37 / +37 lines)
 Lines 40-91    Link Here 
40
typedef unsigned long NotifierID;
40
typedef unsigned long NotifierID;
41
41
42
struct _NotifierEntry {
42
struct _NotifierEntry {
43
	NotifierID	 id;
43
	NotifierID id;
44
	char		*dn;
44
	char *dn;
45
	char		 command; /* 'd'elete, 'm'odify, 'a'dd */
45
	char command; /* 'd'elete, 'm'odify, 'a'dd */
46
} typedef NotifierEntry;
46
} typedef NotifierEntry;
47
47
48
struct _NotifierMessage {
48
struct _NotifierMessage {
49
	int			 id;
49
	int id;
50
	char			*result;
50
	char *result;
51
	struct _NotifierMessage	*next;
51
	struct _NotifierMessage *next;
52
} typedef NotifierMessage;
52
} typedef NotifierMessage;
53
53
54
struct _NotifierClient {
54
struct _NotifierClient {
55
	char		*server;
55
	char *server;
56
	int		 protocol;
56
	int protocol;
57
	int		 starttls;
57
	int starttls;
58
	int		 fd;
58
	int fd;
59
	NotifierMessage	*messages;
59
	NotifierMessage *messages;
60
	int		 last_msgid;
60
	int last_msgid;
61
	char		*buf;
61
	char *buf;
62
} typedef NotifierClient;
62
} typedef NotifierClient;
63
63
64
void		  notifier_entry_free	    (NotifierEntry	*entry);
64
void notifier_entry_free(NotifierEntry *entry);
65
int		  notifier_client_new	    (NotifierClient	*client,
65
int notifier_client_new(NotifierClient *client,
66
					     const char		*server,
66
	const char *server,
67
					     int		 starttls);
67
	int starttls);
68
void		  notifier_client_destroy   (NotifierClient	*client);
68
void notifier_client_destroy(NotifierClient *client);
69
int		  notifier_wait		    (NotifierClient	*client,
69
int notifier_wait(NotifierClient *client,
70
					     time_t		 timeout);
70
	time_t timeout);
71
71
72
int		  notifier_recv_result	    (NotifierClient	*client,
72
int notifier_recv_result(NotifierClient *client,
73
					     time_t		 timeout);
73
	time_t timeout);
74
NotifierMessage*  notifier_get_msg	    (NotifierClient	*client,
74
NotifierMessage*  notifier_get_msg(NotifierClient *client,
75
					     int		 msgid);
75
	int msgid);
76
76
77
int		  notifier_get_dn	    (NotifierClient	*client,
77
int notifier_get_dn(NotifierClient *client,
78
					     NotifierID		 id);
78
	NotifierID id);
79
int		  notifier_resend_get_dn    (NotifierClient	*client,
79
int notifier_resend_get_dn(NotifierClient *client,
80
					     int		 msgid,
80
	int msgid,
81
					     NotifierID		 id);
81
	NotifierID id);
82
int		  notifier_get_dn_result    (NotifierClient	*client,
82
int notifier_get_dn_result(NotifierClient *client,
83
					     int		msgid,
83
	int msgid,
84
					     NotifierEntry	*entry);
84
	NotifierEntry *entry);
85
int		  notifier_alive_s	    (NotifierClient	*client);
85
int notifier_alive_s(NotifierClient *client);
86
int		  notifier_get_id_s	    (NotifierClient	*client,
86
int notifier_get_id_s(NotifierClient *client,
87
					     NotifierID		*id);
87
	NotifierID *id);
88
int		  notifier_get_schema_id_s  (NotifierClient	*client,
88
int notifier_get_schema_id_s(NotifierClient *client,
89
					     NotifierID		*id);
89
	NotifierID *id);
90
90
91
#endif /* _NETWORK_H_ */
91
#endif /* _NETWORK_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/notifier.h (-4 / +4 lines)
 Lines 40-48    Link Here 
40
typedef void univention_krb5_parameters_t;
40
typedef void univention_krb5_parameters_t;
41
#endif
41
#endif
42
42
43
int	notifier_listen	(univention_ldap_parameters_t	*lp,
43
int notifier_listen(univention_ldap_parameters_t *lp,
44
			 univention_krb5_parameters_t	*kp,
44
	univention_krb5_parameters_t *kp,
45
			 int				 write_transaction_file,
45
	int write_transaction_file,
46
			 univention_ldap_parameters_t *lp_local);
46
	univention_ldap_parameters_t *lp_local);
47
47
48
#endif /* _NOTIFIER_H_ */
48
#endif /* _NOTIFIER_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/signals.h (-4 / +4 lines)
 Lines 33-42    Link Here 
33
#ifndef _SIGNALS_H_
33
#ifndef _SIGNALS_H_
34
#define _SIGNALS_H_
34
#define _SIGNALS_H_
35
35
36
void	signals_block	(void);
36
void signals_block(void);
37
void	signals_unblock	(void);
37
void signals_unblock(void);
38
void	signals_init	(void);
38
void signals_init(void);
39
39
40
extern void	exit_handler	(int sig) __attribute__((noreturn));
40
extern void exit_handler(int sig) __attribute__((noreturn));
41
41
42
#endif /* _SIGNALS_H_ */
42
#endif /* _SIGNALS_H_ */
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/transfile.h (-1 / +1 lines)
 Lines 36-41    Link Here 
36
#include "network.h"
36
#include "network.h"
37
37
38
extern char *transaction_file;
38
extern char *transaction_file;
39
int	notifier_write_transaction_file	(NotifierEntry entry);
39
int notifier_write_transaction_file(NotifierEntry entry);
40
40
41
#endif /* _TRANSFILE_H_ */
41
#endif /* _TRANSFILE_H_ */
42
   Bug #30227: listener: fix ucr memory leak
42
   Bug #30227: listener: fix ucr memory leak
43
   
43
   
44
   For every entry * for every attribute two UCR variable for the duplicate
44
   For every entry * for every attribute two UCR variable for the duplicate
45
   check were allocated, but never freed.
45
   check were allocated, but never freed.
46
   
46
   
47
   Also initialize unique handling once instead of parsing base.conf twice
47
   Also initialize unique handling once instead of parsing base.conf twice
48
   for each entry.
48
   for each entry.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-24 / +28 lines)
 Lines 42-47    Link Here 
42
#include "cache_entry.h"
42
#include "cache_entry.h"
43
#include "base64.h"
43
#include "base64.h"
44
44
45
static bool memberUidMode;
46
static bool uniqueMemberMode;
47
48
/* Initialize interal setting once. */
49
void cache_entry_init(void)
50
{
51
	ucrval = univention_config_get_string("listener/memberuid/skip");
52
	if (ucrval) {
53
		memberUidMode |= !strcmp(ucrval, "yes") || !strcmp(ucrval, "true");
54
		free(ucrval);
55
	}
56
	ucrval = univention_config_get_string("listener/uniquemember/skip");
57
	if (ucrval) {
58
		uniqueMemberMode |= !strcmp(ucrval, "yes") || !strcmp(ucrval, "true");
59
		free(ucrval);
60
	}
61
}
62
45
int cache_free_entry(char **dn, CacheEntry *entry)
63
int cache_free_entry(char **dn, CacheEntry *entry)
46
{
64
{
47
	int i, j;
65
	int i, j;
 Lines 174-182   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
174
	char *attr;
192
	char *attr;
175
	int rv = 1;
193
	int rv = 1;
176
194
177
	bool memberUidMode = false;
178
	bool uniqueMemberMode = false;
179
	int i;
195
	int i;
196
	char *ucrval;
197
	enum { DUPLICATES, UNIQUE_UID, UNIQUE_MEMBER } check;
180
198
181
	/* convert LDAP entry to cache entry */
199
	/* convert LDAP entry to cache entry */
182
	memset(cache_entry, 0, sizeof(CacheEntry));
200
	memset(cache_entry, 0, sizeof(CacheEntry));
 Lines 206-231   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
206
		cache_entry->attributes[cache_entry->attribute_count++] = c_attr;
224
		cache_entry->attributes[cache_entry->attribute_count++] = c_attr;
207
		cache_entry->attributes[cache_entry->attribute_count] = NULL;
225
		cache_entry->attributes[cache_entry->attribute_count] = NULL;
208
226
209
		memberUidMode = false;
227
		if (!strcmp(c_attr->name, "memberUid"))
210
		if (!strncmp(c_attr->name, "memberUid", strlen("memberUid"))) {
228
			check = UNIQUE_UID;
211
			char *ucrval;
229
		else if (!strcmp(c_attr->name, "uniqueMember"))
212
			ucrval = univention_config_get_string("listener/memberuid/skip");
230
			check = UNIQUE_MEMBER;
213
231
		else
214
			if (ucrval) {
232
			check = DUPLICATES;
215
				memberUidMode = !strcmp(ucrval, "yes") || !strcmp(ucrval, "true");
216
				free(ucrval);
217
			}
218
		}
219
		uniqueMemberMode = false;
220
		if (!strncmp(c_attr->name, "uniqueMember", strlen("uniqueMember"))) {
221
			char *ucrval;
222
			ucrval = univention_config_get_string("listener/uniquemember/skip");
223
224
			if (ucrval) {
225
				uniqueMemberMode = !strcmp(ucrval, "yes") || !strcmp(ucrval, "true");
226
				free(ucrval);
227
			}
228
		}
229
		if ((val=ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
233
		if ((val=ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
230
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ldap_get_values failed");
234
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ldap_get_values failed");
231
			goto result;
235
			goto result;
 Lines 236-242   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
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, c_attr->name, *dn);
240
				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, c_attr->name, *dn);
237
				goto result;
241
				goto result;
238
			}
242
			}
239
			if (memberUidMode) {
243
			if (memberUidMode && check == UNIQUE_UID) {
240
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
244
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
241
				for (i = 0; i < c_attr->value_count; i++) {
245
				for (i = 0; i < c_attr->value_count; i++) {
242
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
246
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
 Lines 250-256   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
250
				if (i < c_attr->value_count)
254
				if (i < c_attr->value_count)
251
					continue;
255
					continue;
252
			}
256
			}
253
			if (uniqueMemberMode) {
257
			if (uniqueMemberMode && check == UNIQUE_MEMBER) {
254
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
258
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
255
				for (i = 0; i < c_attr->value_count; i++) {
259
				for (i = 0; i < c_attr->value_count; i++) {
256
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1)) {
260
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1)) {
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.h (+3 lines)
 Lines 50-55   struct _CacheEntry { Link Here 
50
	int			  module_count;
50
	int			  module_count;
51
} typedef CacheEntry;
51
} typedef CacheEntry;
52
52
53
/* Initialize interal setting once. */
54
extern void cache_entry_init(void);
55
53
int	cache_free_entry		(char		**dn,
56
int	cache_free_entry		(char		**dn,
54
					 CacheEntry	 *entry);
57
					 CacheEntry	 *entry);
55
int	cache_dump_entry		(char		 *dn,
58
int	cache_dump_entry		(char		 *dn,
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/main.c (+1 lines)
 Lines 556-561   int main(int argc, char* argv[]) Link Here 
556
556
557
	/* XXX: we shouldn't block all signals for so long */
557
	/* XXX: we shouldn't block all signals for so long */
558
	signals_block();
558
	signals_block();
559
	cache_entry_init();
559
	cache_init();
560
	cache_init();
560
	handlers_init();
561
	handlers_init();
561
562
562
   Bug #30227: listener: Handle allocation failure
563
   Bug #30227: listener: Handle allocation failure
563
   
564
   
564
   Check for failed allocation and abort with error.
565
   Check for failed allocation and abort with error.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (+4 lines)
 Lines 97-102   int cache_dump_entry(char *dn, CacheEntry *entry, FILE *fp) Link Here 
97
				char *base64_value;
97
				char *base64_value;
98
				size_t srclen = attribute->length[j] - 1;
98
				size_t srclen = attribute->length[j] - 1;
99
				base64_value = malloc(BASE64_ENCODE_LEN(srclen)+1);
99
				base64_value = malloc(BASE64_ENCODE_LEN(srclen)+1);
100
				if (!base64_value)
101
					return 1;
100
				base64_encode((u_char *)value, srclen, base64_value, BASE64_ENCODE_LEN(srclen) + 1);
102
				base64_encode((u_char *)value, srclen, base64_value, BASE64_ENCODE_LEN(srclen) + 1);
101
				fprintf(fp, "%s:: %s\n", attribute->name, base64_value);
103
				fprintf(fp, "%s:: %s\n", attribute->name, base64_value);
102
				free(base64_value);
104
				free(base64_value);
 Lines 122-127   int cache_entry_module_add(CacheEntry *entry, char *module) Link Here 
122
	}
124
	}
123
125
124
	entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
126
	entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
127
	if (!entry->modules)
128
		return 1;
125
	entry->modules[entry->module_count++] = strdup(module);
129
	entry->modules[entry->module_count++] = strdup(module);
126
	entry->modules[entry->module_count] = NULL;
130
	entry->modules[entry->module_count] = NULL;
127
131
128
   Bug #30227: listener: list entry
132
   Bug #30227: listener: list entry
129
   
133
   
130
   Use post-increment when storing new entries to make sure, that on error
134
   Use post-increment when storing new entries to make sure, that on error
131
   paths al elements are freed.
135
   paths al elements are freed.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-11 / +7 lines)
 Lines 122-130   int cache_entry_module_add(CacheEntry *entry, char *module) Link Here 
122
	}
122
	}
123
123
124
	entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
124
	entry->modules = realloc(entry->modules, (entry->module_count+2)*sizeof(char*));
125
	entry->modules[entry->module_count] = strdup(module);
125
	entry->modules[entry->module_count++] = strdup(module);
126
	entry->modules[entry->module_count+1] = NULL;
126
	entry->modules[entry->module_count] = NULL;
127
	entry->module_count++;
128
127
129
	return 0;
128
	return 0;
130
}
129
}
 Lines 144-151   int cache_entry_module_remove(CacheEntry *entry, char *module) Link Here 
144
	/* replace entry that is to be removed with last entry */
143
	/* replace entry that is to be removed with last entry */
145
	free(*cur);
144
	free(*cur);
146
	entry->modules[cur-entry->modules] = entry->modules[entry->module_count-1];
145
	entry->modules[cur-entry->modules] = entry->modules[entry->module_count-1];
147
	entry->modules[entry->module_count-1] = NULL;
146
	entry->modules[--entry->module_count] = NULL;
148
	entry->module_count--;
149
147
150
	entry->modules = realloc(entry->modules, (entry->module_count+1)*sizeof(char*));
148
	entry->modules = realloc(entry->modules, (entry->module_count+1)*sizeof(char*));
151
149
 Lines 326-334   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
326
		}
324
		}
327
325
328
		changes = realloc(changes, (changes_count+2)*sizeof(char*));
326
		changes = realloc(changes, (changes_count+2)*sizeof(char*));
329
		changes[changes_count] = (*cur1)->name;
327
		changes[changes_count++] = (*cur1)->name;
330
		changes[changes_count+1] = NULL;
328
		changes[changes_count] = NULL;
331
		changes_count++;
332
	}
329
	}
333
330
334
	for (cur2 = old->attributes; cur2 != NULL && *cur2 != NULL; cur2++) {
331
	for (cur2 = old->attributes; cur2 != NULL && *cur2 != NULL; cur2++) {
 Lines 339-347   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
339
			continue;
336
			continue;
340
337
341
		changes = realloc(changes, (changes_count+2)*sizeof(char*));
338
		changes = realloc(changes, (changes_count+2)*sizeof(char*));
342
		changes[changes_count] = (*cur2)->name;
339
		changes[changes_count++] = (*cur2)->name;
343
		changes[changes_count+1] = NULL;
340
		changes[changes_count] = NULL;
344
		changes_count++;
345
	}
341
	}
346
342
347
	return changes;
343
	return changes;
348
   Bug #30227: listener: simplify repeated dereference
344
   Bug #30227: listener: simplify repeated dereference
349
   
345
   
350
   Replace lookup to current element with local variable.
346
   Replace lookup to current element with local variable.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-26 / +26 lines)
 Lines 168-173   int cache_entry_module_present(CacheEntry *entry, char *module) Link Here 
168
int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAPMessage *ldap_entry)
168
int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAPMessage *ldap_entry)
169
{
169
{
170
	BerElement *ber;
170
	BerElement *ber;
171
	CacheEntryAttribute *c_attr;
171
	char *attr;
172
	char *attr;
172
	int rv = 1;
173
	int rv = 1;
173
174
 Lines 192-209   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
192
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of attributes array failed");
193
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of attributes array failed");
193
			goto result;
194
			goto result;
194
		}
195
		}
195
		if ((cache_entry->attributes[cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
196
		if ((c_attr = malloc(sizeof(CacheEntryAttribute))) == NULL) {
196
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for CacheEntryAttribute failed");
197
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for CacheEntryAttribute failed");
197
			goto result;
198
			goto result;
198
		}
199
		}
199
		cache_entry->attributes[cache_entry->attribute_count]->name=strdup(attr);
200
		c_attr->name = strdup(attr);
200
		cache_entry->attributes[cache_entry->attribute_count]->values=NULL;
201
		c_attr->values = NULL;
201
		cache_entry->attributes[cache_entry->attribute_count]->length=NULL;
202
		c_attr->length = NULL;
202
		cache_entry->attributes[cache_entry->attribute_count]->value_count=0;
203
		c_attr->value_count = 0;
203
		cache_entry->attributes[cache_entry->attribute_count+1]=NULL;
204
		cache_entry->attributes[cache_entry->attribute_count++] = c_attr;
205
		cache_entry->attributes[cache_entry->attribute_count] = NULL;
204
206
205
		memberUidMode = false;
207
		memberUidMode = false;
206
		if ( !strncmp(cache_entry->attributes[cache_entry->attribute_count]->name, "memberUid", strlen("memberUid")) ) {
208
		if (!strncmp(c_attr->name, "memberUid", strlen("memberUid"))) {
207
			char *ucrval;
209
			char *ucrval;
208
			ucrval = univention_config_get_string("listener/memberuid/skip");
210
			ucrval = univention_config_get_string("listener/memberuid/skip");
209
211
 Lines 213-219   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
213
			}
215
			}
214
		}
216
		}
215
		uniqueMemberMode = false;
217
		uniqueMemberMode = false;
216
		if ( !strncmp(cache_entry->attributes[cache_entry->attribute_count]->name, "uniqueMember", strlen("uniqueMember")) ) {
218
		if (!strncmp(c_attr->name, "uniqueMember", strlen("uniqueMember"))) {
217
			char *ucrval;
219
			char *ucrval;
218
			ucrval = univention_config_get_string("listener/uniquemember/skip");
220
			ucrval = univention_config_get_string("listener/uniquemember/skip");
219
221
 Lines 229-244   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
229
		for (v = val; *v != NULL; v++) {
231
		for (v = val; *v != NULL; v++) {
230
			if ( (*v)->bv_val == NULL ) {
232
			if ( (*v)->bv_val == NULL ) {
231
				// check here, strlen behavior might be undefined in this case
233
				// check here, strlen behavior might be undefined in this case
232
				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, cache_entry->attributes[cache_entry->attribute_count]->name, *dn);
234
				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, c_attr->name, *dn);
233
				goto result;
235
				goto result;
234
			}
236
			}
235
			if (memberUidMode) {
237
			if (memberUidMode) {
236
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
238
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
237
				for (i=0; i<cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
239
				for (i = 0; i < c_attr->value_count; i++) {
238
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
240
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
239
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate memberUid entry:");
241
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate memberUid entry:");
240
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
242
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
241
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "memberUid: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
243
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "memberUid: %s", c_attr->values[i]);
242
						break;
244
						break;
243
					}
245
					}
244
				}
246
				}
 Lines 248-258   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
248
			}
250
			}
249
			if (uniqueMemberMode) {
251
			if (uniqueMemberMode) {
250
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
252
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
251
				for (i=0; i<cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
253
				for (i = 0; i < c_attr->value_count; i++) {
252
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
254
					if (!memcmp(c_attr->values[i], (*v)->bv_val, (*v)->bv_len+1)) {
253
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate uniqueMember entry:");
255
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate uniqueMember entry:");
254
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
256
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
255
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "uniqueMember: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
257
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "uniqueMember: %s", c_attr->values[i]);
256
						break;
258
						break;
257
					}
259
					}
258
				}
260
				}
 Lines 260-293   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
260
				if (i < c_attr->value_count)
262
				if (i < c_attr->value_count)
261
					continue;
263
					continue;
262
			}
264
			}
263
			if ((cache_entry->attributes[cache_entry->attribute_count]->values = realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(char*))) == NULL) {
265
			if ((c_attr->values = realloc(c_attr->values, (c_attr->value_count + 2) * sizeof(char*))) == NULL) {
264
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
266
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
265
				goto result;
267
				goto result;
266
			}
268
			}
267
			if ((cache_entry->attributes[cache_entry->attribute_count]->length = realloc(cache_entry->attributes[cache_entry->attribute_count]->length, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(int))) == NULL) {
269
			if ((c_attr->length = realloc(c_attr->length, (c_attr->value_count + 2) * sizeof(int))) == NULL) {
268
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed");
270
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed");
269
				goto result;
271
				goto result;
270
			}
272
			}
271
			if ((*v)->bv_len == strlen((*v)->bv_val)) {
273
			if ((*v)->bv_len == strlen((*v)->bv_val)) {
272
				if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strdup((*v)->bv_val)) == NULL) {
274
				if ((c_attr->values[c_attr->value_count] = strdup((*v)->bv_val)) == NULL) {
273
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: strdup of value failed");
275
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: strdup of value failed");
274
					goto result;
276
					goto result;
275
				}
277
				}
276
				cache_entry->attributes[cache_entry->attribute_count]->length[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strlen(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count])+1;
278
				c_attr->length[c_attr->value_count] = strlen(c_attr->values[c_attr->value_count]) + 1;
277
			} else {	// in this case something is strange about the string in bv_val, maybe contains a '\0'
279
			} else {	// in this case something is strange about the string in bv_val, maybe contains a '\0'
278
				// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe
280
				// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe
279
				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))) == NULL) {
281
				if ((c_attr->values[c_attr->value_count] = malloc(((*v)->bv_len + 1) * sizeof(char))) == NULL) {
280
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed");
282
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed");
281
					goto result;
283
					goto result;
282
				}
284
				}
283
				memcpy(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count],(*v)->bv_val,(*v)->bv_len);
285
				memcpy(c_attr->values[c_attr->value_count], (*v)->bv_val, (*v)->bv_len);
284
				cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count][(*v)->bv_len]='\0'; // terminate the string to be safe
286
				c_attr->values[c_attr->value_count][(*v)->bv_len] = '\0'; // terminate the string to be safe
285
				cache_entry->attributes[cache_entry->attribute_count]->length[cache_entry->attributes[cache_entry->attribute_count]->value_count]=(*v)->bv_len+1;
287
				c_attr->length[c_attr->value_count] = (*v)->bv_len + 1;
286
			}
288
			}
287
			cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count+1]=NULL;
289
			c_attr->values[++c_attr->value_count] = NULL;
288
			cache_entry->attributes[cache_entry->attribute_count]->value_count++;
289
		}
290
		}
290
		cache_entry->attribute_count++;
291
291
292
		ldap_value_free_len(val);
292
		ldap_value_free_len(val);
293
		ldap_memfree(attr);
293
		ldap_memfree(attr);
294
   Bug #30227: listener: simplify next value loop
294
   Bug #30227: listener: simplify next value loop
295
   
295
   
296
   Remove variable and directly continue with next variable when duplicate
296
   Remove variable and directly continue with next variable when duplicate
297
   value is detected.
297
   value is detected.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-12 / +4 lines)
 Lines 173-180   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
173
173
174
	bool memberUidMode = false;
174
	bool memberUidMode = false;
175
	bool uniqueMemberMode = false;
175
	bool uniqueMemberMode = false;
176
	bool duplicateMemberUid = false;
177
	bool duplicateUniqueMember = false;
178
	int i;
176
	int i;
179
177
180
	/* convert LDAP entry to cache entry */
178
	/* convert LDAP entry to cache entry */
 Lines 236-272   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
236
			}
234
			}
237
			if (memberUidMode) {
235
			if (memberUidMode) {
238
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
236
				/* avoid duplicate memberUid entries https://forge.univention.org/bugzilla/show_bug.cgi?id=17998 */
239
				duplicateMemberUid = 0;
240
				for (i=0; i<cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
237
				for (i=0; i<cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
241
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
238
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
242
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate memberUid entry:");
239
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate memberUid entry:");
243
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
240
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
244
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "memberUid: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
241
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "memberUid: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
245
						duplicateMemberUid = true;
246
						break;
242
						break;
247
					}
243
					}
248
				}
244
				}
249
				if (duplicateMemberUid) {
245
				/* skip this memberUid entry if listener/memberuid/skip is set to yes */
250
					/* skip this memberUid entry if listener/memberuid/skip is set to yes */
246
				if (i < c_attr->value_count)
251
					continue;
247
					continue;
252
				}
253
			}
248
			}
254
			if (uniqueMemberMode) {
249
			if (uniqueMemberMode) {
255
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
250
				/* avoid duplicate uniqueMember entries https://forge.univention.org/bugzilla/show_bug.cgi?id=18692 */
256
				duplicateUniqueMember = false;
257
				for (i=0; i<cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
251
				for (i=0; i<cache_entry->attributes[cache_entry->attribute_count]->value_count; i++) {
258
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
252
					if (!memcmp(cache_entry->attributes[cache_entry->attribute_count]->values[i], (*v)->bv_val, (*v)->bv_len+1) ) {
259
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate uniqueMember entry:");
253
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "Found a duplicate uniqueMember entry:");
260
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
254
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "DN: %s",  *dn);
261
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "uniqueMember: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
255
						univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "uniqueMember: %s", cache_entry->attributes[cache_entry->attribute_count]->values[i]);
262
						duplicateUniqueMember = true;
263
						break;
256
						break;
264
					}
257
					}
265
				}
258
				}
266
				if (duplicateUniqueMember) {
259
				/* skip this uniqueMember entry if listener/uniquemember/skip is set to yes */
267
					/* skip this uniqueMember entry if listener/uniquemember/skip is set to yes */
260
				if (i < c_attr->value_count)
268
					continue;
261
					continue;
269
				}
270
			}
262
			}
271
			if ((cache_entry->attributes[cache_entry->attribute_count]->values = realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(char*))) == NULL) {
263
			if ((cache_entry->attributes[cache_entry->attribute_count]->values = realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(char*))) == NULL) {
272
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
264
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
273
   Bug #30227: listener: simplify indirect pointers
265
   Bug #30227: listener: simplify indirect pointers
274
   
266
   
275
   Replace pointer to pointer by pointer itself.
267
   Replace pointer to pointer by pointer itself.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-14 / +12 lines)
 Lines 80-109   int cache_free_entry(char **dn, CacheEntry *entry) Link Here 
80
80
81
int cache_dump_entry(char *dn, CacheEntry *entry, FILE *fp)
81
int cache_dump_entry(char *dn, CacheEntry *entry, FILE *fp)
82
{
82
{
83
	CacheEntryAttribute **attribute;
83
	int i, j;
84
	char **module;
84
	char **module;
85
	char **value;
86
85
87
	fprintf(fp, "dn: %s\n", dn);
86
	fprintf(fp, "dn: %s\n", dn);
88
	int i, j;
87
	for (i = 0; i < entry->attribute_count; i++) {
89
	for(i=0; i<entry->attribute_count; i++) {
88
		CacheEntryAttribute *attribute = entry->attributes[i];
90
		attribute = &entry->attributes[i];
89
		for (j = 0; j < entry->attributes[i]->value_count; j++) {
91
		for (j=0; j<entry->attributes[i]->value_count; j++) {
90
			int len = attribute->length[j] - 1;
92
			value = &entry->attributes[i]->values[j];
91
			char *c, *value = attribute->values[j];
93
			char *c;
92
			for (c = value; len >= 0; c++, len--) {
94
			for (c=*value; *c != '\0'; c++) {
95
				if (!isgraph(*c))
93
				if (!isgraph(*c))
96
					break;
94
					break;
97
			}
95
			}
98
			if (*c != '\0') {
96
			if (len >= 0) {
99
				char *base64_value;
97
				char *base64_value;
100
				size_t srclen = entry->attributes[i]->length[j]-1;
98
				size_t srclen = attribute->length[j] - 1;
101
				base64_value = malloc(BASE64_ENCODE_LEN(srclen)+1);
99
				base64_value = malloc(BASE64_ENCODE_LEN(srclen)+1);
102
				base64_encode((u_char *)*value, srclen, base64_value, BASE64_ENCODE_LEN(srclen)+1);
100
				base64_encode((u_char *)value, srclen, base64_value, BASE64_ENCODE_LEN(srclen) + 1);
103
				fprintf(fp, "%s:: %s\n", (*attribute)->name, base64_value);
101
				fprintf(fp, "%s:: %s\n", attribute->name, base64_value);
104
				free(base64_value);
102
				free(base64_value);
105
			} else {
103
			} else {
106
				fprintf(fp, "%s: %s\n", (*attribute)->name, *value);
104
				fprintf(fp, "%s: %s\n", attribute->name, value);
107
			}
105
			}
108
		}
106
		}
109
	}
107
	}
110
   Bug #30227: listener: Fix NULL check
108
   Bug #30227: listener: Fix NULL check
111
   
109
   
112
   Check pointer for NULL before freeing sub structures.
110
   Check pointer for NULL before freeing sub structures.
113
   Calling free(NULL) is okay.
111
   Calling free(NULL) is okay.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-28 / +15 lines)
 Lines 51-93   int cache_free_entry(char **dn, CacheEntry *entry) Link Here 
51
		*dn = NULL;
51
		*dn = NULL;
52
	}
52
	}
53
53
54
	for(i=0; i<entry->attribute_count; i++) {
54
	if (entry->attributes) {
55
		if(entry->attributes[i]->name) {
55
		for(i = 0; i < entry->attribute_count; i++) {
56
			free(entry->attributes[i]->name);
56
			if (entry->attributes[i]) {
57
		}
57
				free(entry->attributes[i]->name);
58
		for(j=0; j<entry->attributes[i]->value_count; j++) {
58
				for (j = 0; j < entry->attributes[i]->value_count; j++)
59
			if(entry->attributes[i]->values[j]) {
59
					free(entry->attributes[i]->values[j]);
60
				free(entry->attributes[i]->values[j]);
60
				free(entry->attributes[i]->values);
61
				free(entry->attributes[i]->length);
62
				free(entry->attributes[i]);
61
			}
63
			}
62
		}
64
		}
63
		if(entry->attributes[i]->values) {
64
			free(entry->attributes[i]->values);
65
		}
66
		if(entry->attributes[i]->length) {
67
			free(entry->attributes[i]->length);
68
		}
69
		if(entry->attributes[i]) {
70
			free(entry->attributes[i]);
71
		}
72
	}
73
74
	if (entry->attributes) {
75
		free(entry->attributes);
65
		free(entry->attributes);
66
		entry->attributes = NULL;
67
		entry->attribute_count = 0;
76
	}
68
	}
77
69
78
	for(i=0; i<entry->module_count; i++) {
70
	if (entry->modules) {
79
		if (entry->modules[i]) {
71
		for (i = 0; i < entry->module_count; i++)
80
			free(entry->modules[i]);
72
			free(entry->modules[i]);
81
		}
82
	}
83
84
	if(entry->modules) {
85
		free(entry->modules);
73
		free(entry->modules);
74
		entry->modules = NULL;
75
		entry->module_count = 0;
86
	}
76
	}
87
77
88
	entry->modules = NULL;
89
	entry->module_count = 0;
90
91
	return 0;
78
	return 0;
92
}
79
}
93
80
94
   Bug #30227: listener: error by default
81
   Bug #30227: listener: error by default
95
   
82
   
96
   Switch return value to return error by default and 0 only on success.
83
   Switch return value to return error by default and 0 only on success.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-16 / +4 lines)
 Lines 184-190   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
184
{
184
{
185
	BerElement *ber;
185
	BerElement *ber;
186
	char *attr;
186
	char *attr;
187
	int rv = 0;
187
	int rv = 1;
188
188
189
	bool memberUidMode = false;
189
	bool memberUidMode = false;
190
	bool uniqueMemberMode = false;
190
	bool uniqueMemberMode = false;
 Lines 207-218   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
207
207
208
		if ((cache_entry->attributes = realloc(cache_entry->attributes, (cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) {
208
		if ((cache_entry->attributes = realloc(cache_entry->attributes, (cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) {
209
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of attributes array failed");
209
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of attributes array failed");
210
			rv = 1;
211
			goto result;
210
			goto result;
212
		}
211
		}
213
		if ((cache_entry->attributes[cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
212
		if ((cache_entry->attributes[cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
214
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for CacheEntryAttribute failed");
213
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for CacheEntryAttribute failed");
215
			rv = 1;
216
			goto result;
214
			goto result;
217
		}
215
		}
218
		cache_entry->attributes[cache_entry->attribute_count]->name=strdup(attr);
216
		cache_entry->attributes[cache_entry->attribute_count]->name=strdup(attr);
 Lines 243-256   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
243
		}
241
		}
244
		if ((val=ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
242
		if ((val=ldap_get_values_len(ld, ldap_entry, attr)) == NULL) {
245
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ldap_get_values failed");
243
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "ldap_get_values failed");
246
			rv = 1;
247
			goto result;
244
			goto result;
248
		}
245
		}
249
		for (v = val; *v != NULL; v++) {
246
		for (v = val; *v != NULL; v++) {
250
			if ( (*v)->bv_val == NULL ) {
247
			if ( (*v)->bv_val == NULL ) {
251
				// check here, strlen behavior might be undefined in this case
248
				// check here, strlen behavior might be undefined in this case
252
				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, cache_entry->attributes[cache_entry->attribute_count]->name, *dn);
249
				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, cache_entry->attributes[cache_entry->attribute_count]->name, *dn);
253
				rv = 1;
254
				goto result;
250
				goto result;
255
			}
251
			}
256
			if (memberUidMode) {
252
			if (memberUidMode) {
 Lines 289-306   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
289
			}
285
			}
290
			if ((cache_entry->attributes[cache_entry->attribute_count]->values = realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(char*))) == NULL) {
286
			if ((cache_entry->attributes[cache_entry->attribute_count]->values = realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(char*))) == NULL) {
291
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
287
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed");
292
				rv = 1;
293
				goto result;
288
				goto result;
294
			}
289
			}
295
			if ((cache_entry->attributes[cache_entry->attribute_count]->length = realloc(cache_entry->attributes[cache_entry->attribute_count]->length, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(int))) == NULL) {
290
			if ((cache_entry->attributes[cache_entry->attribute_count]->length = realloc(cache_entry->attributes[cache_entry->attribute_count]->length, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(int))) == NULL) {
296
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed");
291
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed");
297
				rv = 1;
298
				goto result;
292
				goto result;
299
			}
293
			}
300
			if ((*v)->bv_len == strlen((*v)->bv_val)) {
294
			if ((*v)->bv_len == strlen((*v)->bv_val)) {
301
				if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strdup((*v)->bv_val)) == NULL) {
295
				if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strdup((*v)->bv_val)) == NULL) {
302
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: strdup of value failed");
296
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: strdup of value failed");
303
					rv = 1;
304
					goto result;
297
					goto result;
305
				}
298
				}
306
				cache_entry->attributes[cache_entry->attribute_count]->length[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strlen(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count])+1;
299
				cache_entry->attributes[cache_entry->attribute_count]->length[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strlen(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count])+1;
 Lines 308-314   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
308
				// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe
301
				// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe
309
				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))) == NULL) {
302
				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))) == NULL) {
310
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed");
303
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed");
311
					rv = 1;
312
					goto result;
304
					goto result;
313
				}
305
				}
314
				memcpy(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count],(*v)->bv_val,(*v)->bv_len);
306
				memcpy(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count],(*v)->bv_val,(*v)->bv_len);
 Lines 325-330   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
325
	}
317
	}
326
318
327
	ber_free(ber, 0);
319
	ber_free(ber, 0);
320
	rv = 0;
328
321
329
result:
322
result:
330
	if (rv != 0)
323
	if (rv != 0)
 Lines 380-396   char** cache_entry_changed_attributes(CacheEntry *new, CacheEntry *old) Link Here 
380
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
373
int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) {
381
	CacheEntryAttribute **cur1, **cur2;
374
	CacheEntryAttribute **cur1, **cur2;
382
	int i=0;
375
	int i=0;
383
	int rv=0;
376
	int rv=1;
384
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
377
	memset(backup_cache_entry, 0, sizeof(CacheEntry));
385
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
378
	for (cur1 = cache_entry->attributes; cur1 != NULL && *cur1 != NULL; cur1++) {
386
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) {
379
		if ((backup_cache_entry->attributes = realloc(backup_cache_entry->attributes, (backup_cache_entry->attribute_count+2)*sizeof(CacheEntryAttribute*))) == NULL) {
387
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
380
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of attributes array failed");
388
			rv = 1;
389
			goto result;
381
			goto result;
390
		}
382
		}
391
		if ((backup_cache_entry->attributes[backup_cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
383
		if ((backup_cache_entry->attributes[backup_cache_entry->attribute_count] = malloc(sizeof(CacheEntryAttribute))) == NULL) {
392
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
384
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for CacheEntryAttribute failed");
393
			rv = 1;
394
			goto result;
385
			goto result;
395
		}
386
		}
396
		cur2 = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
387
		cur2 = &backup_cache_entry->attributes[backup_cache_entry->attribute_count];
 Lines 403-427   int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) { Link Here 
403
		for (i = 0; i < (*cur1)->value_count; i++) {
394
		for (i = 0; i < (*cur1)->value_count; i++) {
404
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count+2)*sizeof(char*))) == NULL) {
395
			if (((*cur2)->values = realloc((*cur2)->values, ((*cur2)->value_count+2)*sizeof(char*))) == NULL) {
405
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
396
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of values array failed");
406
				rv = 1;
407
				goto result;
397
				goto result;
408
			}
398
			}
409
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count+2)*sizeof(int))) == NULL) {
399
			if (((*cur2)->length = realloc((*cur2)->length, ((*cur2)->value_count+2)*sizeof(int))) == NULL) {
410
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
400
				univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: realloc of length array failed");
411
				rv = 1;
412
				goto result;
401
				goto result;
413
			}
402
			}
414
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
403
			if ((*cur1)->length[i] == strlen((*cur1)->values[i]) + 1) {
415
				if (((*cur2)->values[(*cur2)->value_count]=strdup((*cur1)->values[i])) == NULL) {
404
				if (((*cur2)->values[(*cur2)->value_count]=strdup((*cur1)->values[i])) == NULL) {
416
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
405
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: strdup of value failed");
417
					rv = 1;
418
					goto result;
406
					goto result;
419
				}
407
				}
420
				(*cur2)->length[(*cur2)->value_count]=strlen((*cur2)->values[(*cur2)->value_count])+1;
408
				(*cur2)->length[(*cur2)->value_count]=strlen((*cur2)->values[(*cur2)->value_count])+1;
421
			} else {
409
			} else {
422
				if (((*cur2)->values[(*cur2)->value_count]=malloc(((*cur1)->length[i])*sizeof(char))) == NULL) {
410
				if (((*cur2)->values[(*cur2)->value_count]=malloc(((*cur1)->length[i])*sizeof(char))) == NULL) {
423
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
411
					univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "copy_cache_entry: malloc for value failed");
424
					rv = 1;
425
					goto result;
412
					goto result;
426
				}
413
				}
427
				memcpy((*cur2)->values[(*cur2)->value_count],(*cur1)->values[i],(*cur1)->length[i]);
414
				memcpy((*cur2)->values[(*cur2)->value_count],(*cur1)->values[i],(*cur1)->length[i]);
 Lines 439-444   int copy_cache_entry(CacheEntry *cache_entry, CacheEntry *backup_cache_entry) { Link Here 
439
		backup_cache_entry->modules[backup_cache_entry->module_count+1] = NULL;
426
		backup_cache_entry->modules[backup_cache_entry->module_count+1] = NULL;
440
		backup_cache_entry->module_count++;
427
		backup_cache_entry->module_count++;
441
	}
428
	}
429
	rv = 0;
442
result:
430
result:
443
	return rv;
431
	return rv;
444
}
432
}
445
   Bug #30227: listener: dn memory leak
433
   Bug #30227: listener: dn memory leak
446
   
434
   
447
   Free dn on errors.
435
   Free dn on errors.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-1 / +1 lines)
 Lines 328-334   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
328
328
329
result:
329
result:
330
	if (rv != 0)
330
	if (rv != 0)
331
		cache_free_entry(NULL, cache_entry);
331
		cache_free_entry(dn, cache_entry);
332
332
333
	return rv;
333
	return rv;
334
}
334
}
335
   Bug #30227: listener: use local dn variable
335
   Bug #30227: listener: use local dn variable
336
   
336
   
337
   Declare variable only in-scope.
337
   Declare variable only in-scope.
(-)a/branches/ucs-3.1/ucs/management/univention-directory-listener/src/cache_entry.c (-2 / +1 lines)
 Lines 184-190   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
184
{
184
{
185
	BerElement *ber;
185
	BerElement *ber;
186
	char *attr;
186
	char *attr;
187
	char *_dn;
188
	int rv = 0;
187
	int rv = 0;
189
188
190
	bool memberUidMode = false;
189
	bool memberUidMode = false;
 Lines 196-202   int cache_new_entry_from_ldap(char **dn, CacheEntry *cache_entry, LDAP *ld, LDAP Link Here 
196
	/* convert LDAP entry to cache entry */
195
	/* convert LDAP entry to cache entry */
197
	memset(cache_entry, 0, sizeof(CacheEntry));
196
	memset(cache_entry, 0, sizeof(CacheEntry));
198
	if (dn != NULL) {
197
	if (dn != NULL) {
199
		_dn = ldap_get_dn(ld, ldap_entry);
198
		char *_dn = ldap_get_dn(ld, ldap_entry);
200
		if(*dn)
199
		if(*dn)
201
				free(*dn);
200
				free(*dn);
202
		*dn = strdup(_dn);
201
		*dn = strdup(_dn);

Return to bug 30263