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

(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/cache.c (-4 / +6 lines)
Lines 248-261 int cache_get_schema_id(NotifierID *value, const long def) Link Here
248
{
248
{
249
	FILE *fp;
249
	FILE *fp;
250
	char file[PATH_MAX];
250
	char file[PATH_MAX];
251
	int rv;
251
252
252
	*value = def;
253
	*value = def;
253
254
254
	snprintf(file, PATH_MAX, "%s/schema/id/id", ldap_dir);
255
	snprintf(file, PATH_MAX, "%s/schema/id/id", ldap_dir);
255
	if ((fp = fopen(file, "r")) == NULL)
256
	if ((fp = fopen(file, "r")) == NULL)
256
		return 1;
257
		return 1;
257
	fscanf(fp, "%ld", value);
258
	rv = fscanf(fp, "%ld", value);
258
	return fclose(fp);
259
	return fclose(fp) || (rv != 1);
259
}
260
}
260
261
261
int cache_set_int(char *key, const NotifierID value)
262
int cache_set_int(char *key, const NotifierID value)
Lines 285-298 int cache_get_int(char *key, NotifierID *value, const long def) Link Here
285
{
286
{
286
	FILE *fp;
287
	FILE *fp;
287
	char file[PATH_MAX];
288
	char file[PATH_MAX];
289
	int rv;
288
290
289
	*value = def;
291
	*value = def;
290
292
291
	snprintf(file, PATH_MAX, "%s/%s", cache_dir, key);
293
	snprintf(file, PATH_MAX, "%s/%s", cache_dir, key);
292
	if ((fp = fopen(file, "r")) == NULL)
294
	if ((fp = fopen(file, "r")) == NULL)
293
		return 1;
295
		return 1;
294
	fscanf(fp, "%ld", value);
296
	rv = fscanf(fp, "%ld", value);
295
	return fclose(fp);
297
	return fclose(fp) || (rv != 1);
296
}
298
}
297
299
298
int cache_get_master_entry(CacheMasterEntry *master_entry)
300
int cache_get_master_entry(CacheMasterEntry *master_entry)
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.h (-10 / +6 lines)
Lines 45-58 Link Here
45
   initializing, HANDLER_READY will be set; however, if the
45
   initializing, HANDLER_READY will be set; however, if the
46
   initialization fails, it will be removed again. If it's successful,
46
   initialization fails, it will be removed again. If it's successful,
47
   both, HANDLER_INITIALIZED and HANDLER_READY will be set */
47
   both, HANDLER_INITIALIZED and HANDLER_READY will be set */
48
#define HANDLER_INITIALIZED	000000001
48
enum state {
49
#define HANDLER_READY		000000002
49
	HANDLER_INITIALIZED = 1 << 0,
50
50
	HANDLER_READY = 1 << 1,
51
#define HANDLER_PREPARED        000000004
51
	HANDLER_PREPARED = 1 << 2,
52
 
52
};
53
#define HANDLER_HAS_FLAG(handler, flag)		((handler->state & flag) == flag)
54
#define HANDLER_SET_FLAG(handler, flag)		handler->state |= flag
55
#define HANDLER_UNSET_FLAG(handler, flag)	handler->state &= ~flag
56
struct filter {
53
struct filter {
57
	char	*base;
54
	char	*base;
Lines 71-77 struct _Handler { Link Here
71
	PyObject	 *setdata;
72
	PyObject	 *setdata;
72
	struct _Handler	 *next;
73
	struct _Handler	 *next;
73
74
74
	int		  state;
75
	enum state	  state;
75
	int		  prepared : 1;
76
	int		  prepared : 1;
76
} typedef Handler;
77
} typedef Handler;
77
78
Lines 83-89 int handlers_init (void); Link Here
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);
87
int	handlers_update			(const char		*dn,
86
int	handlers_update			(const char		*dn,
88
					 CacheEntry	*new,
87
					 CacheEntry	*new,
89
					 CacheEntry	*old,
88
					 CacheEntry	*old,
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.c (-35 / +5 lines)
Lines 262-268 static int handler_import(char* filename) Link Here
262
	if (state_fp == NULL) {
262
	if (state_fp == NULL) {
263
		handler->state = 0;
263
		handler->state = 0;
264
	} else {
264
	} else {
265
		fscanf(state_fp, "%d", &handler->state);
265
		rv = fscanf(state_fp, "%u", &handler->state);
266
		if (rv != 1) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed reading %s: %s", state_filename, strerror(errno));
266
		fclose(state_fp);
267
		fclose(state_fp);
267
	}
268
	}
268
269
Lines 466-504 int handlers_initialize_all(void) Link Here
466
}
466
}
467
467
468
468
469
/* dump internal state of one handler. */
470
static void handler_dump(Handler *handler)
471
{
472
	struct filter **filter;
473
474
	printf("name: %s\n", handler->name);
475
	printf("description: %s\n", handler->description);
476
477
	for (filter = handler->filters; filter != NULL; filter++) {
478
		printf("filter: %s %d %s\n", (*filter)->base, (*filter)->scope, (*filter)->filter);
479
	}
480
481
	printf("clean handler: %d\n", handler->clean != NULL);
482
	printf("initialize handler: %d\n", handler->initialize != NULL);
483
	printf("prerun handler: %d\n", handler->prerun != NULL);
484
	printf("postrun handler: %d\n", handler->postrun != NULL);
485
	printf("setdata handler: %d\n", handler->setdata != NULL);
486
}
487
488
489
/* dump internal state of all handlers. UNUSED */
490
int handlers_dump(void)
491
{
492
	Handler *handler;
493
	for (handler=handlers; handler != NULL; handler=handler->next)
494
		handler_dump(handler);
495
496
	return 0;
497
}
498
499
500
/* Load all handlers from one directory. */
469
/* Load all handlers from one directory. */
501
int handlers_load_path(char *path)
470
static int handlers_load_path(char *path)
502
{
471
{
503
	char **module_dir;
472
	char **module_dir;
504
473
Lines 733-739 static PyObject* handlers_argtuple_command(const char *dn, CacheEntry *new, Cach Link Here
733
733
734
734
735
/* return boolean indicating whether attribute has changed */
735
/* return boolean indicating whether attribute has changed */
736
int attribute_has_changed(char** changes, char* attribute)
736
static int attribute_has_changed(char** changes, char* attribute)
737
{
737
{
738
	char **cur;
738
	char **cur;
739
739
Lines 885-891 char *handlers_filter(void) Link Here
885
885
886
886
887
/* Pass configuration data from listener to one module. */
887
/* Pass configuration data from listener to one module. */
888
int handler_set_data(Handler *handler, PyObject *argtuple)
888
static int handler_set_data(Handler *handler, PyObject *argtuple)
889
{
889
{
890
	PyObject *result;
890
	PyObject *result;
891
	int rv;
891
	int rv;
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/main.c (-8 / +13 lines)
Lines 103-109 static void daemonize(int lock_fd) Link Here
103
	if (rv < 0 || rv >= PATH_MAX)
103
	if (rv < 0 || rv >= PATH_MAX)
104
		abort();
104
		abort();
105
105
106
	fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL);
106
	fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL, 0644);
107
	if (fd < 0) {
107
	if (fd < 0) {
108
		if (errno == EEXIST)
108
		if (errno == EEXIST)
109
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "pidfile %s exists, aborting...%d %s", pidfile, errno, strerror(errno));
109
			univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "pidfile %s exists, aborting...%d %s", pidfile, errno, strerror(errno));
Lines 149-177 static void daemonize(int lock_fd) Link Here
149
		rv = snprintf(buf, sizeof buf, "%d", pid);
149
		rv = snprintf(buf, sizeof buf, "%d", pid);
150
		if (rv < 0 || rv >= sizeof buf)
150
		if (rv < 0 || rv >= sizeof buf)
151
			abort();
151
			abort();
152
		write(fd, buf, rv);
152
		rv = write(fd, buf, rv);
153
		if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to write %s: %s", pidfile, strerror(errno));
153
	}
154
	}
154
	close(fd);
155
	rv = close(fd);
156
	if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close %s: %s", pidfile, strerror(errno));
155
157
156
	// Set new file permissions
158
	// Set new file permissions
157
	umask(0);
159
	umask(0);
158
160
159
	// Change the working directory to the root directory
161
	// Change the working directory to the root directory
160
	chdir("/");
162
	rv = chdir("/");
163
	if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to change directory: %s", strerror(errno));
161
164
162
	if ((null = open("/dev/null", O_RDWR)) == -1) {
165
	if ((null = open("/dev/null", O_RDWR)) == -1) {
163
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not open /dev/null");
166
		univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not open /dev/null: %s", strerror(errno));
164
		exit(EXIT_FAILURE);
167
		exit(EXIT_FAILURE);
165
	}
168
	}
166
	dup2(null, STDIN_FILENO);
169
	dup2(null, STDIN_FILENO);
167
	dup2(null, STDOUT_FILENO);
170
	dup2(null, STDOUT_FILENO);
168
	if ((log = open("/var/log/univention/listener.log", O_WRONLY | O_CREAT | O_APPEND)) >= 0) {
171
	if ((log = open("/var/log/univention/listener.log", O_WRONLY | O_CREAT | O_APPEND, 0640)) >= 0) {
169
		dup2(log, STDERR_FILENO);
172
		dup2(log, STDERR_FILENO);
170
		close(log);
173
		rv = close(log);
174
		if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close /var/log/univention/listener.log: %s", strerror(errno));
171
	} else {
175
	} else {
172
		dup2(null, STDERR_FILENO);
176
		dup2(null, STDERR_FILENO);
173
	}
177
	}
174
	close(null);
178
	rv = close(null);
179
	if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close /dev/null: %s", strerror(errno));
175
180
176
	// Close all open file descriptors
181
	// Close all open file descriptors
177
	for (fd = sysconf(_SC_OPEN_MAX); fd > STDERR_FILENO; fd--)
182
	for (fd = sysconf(_SC_OPEN_MAX); fd > STDERR_FILENO; fd--)
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/select_server.c (-1 / +1 lines)
Lines 109-115 void select_server(univention_ldap_parameters_t *lp) Link Here
109
		}
109
		}
110
110
111
		if (ldap_backups && !current_server_list) {
111
		if (ldap_backups && !current_server_list) {
112
			char *str, *saveptr;
112
			char *str, *saveptr = NULL;
113
			/* rebuild list and initialize */
113
			/* rebuild list and initialize */
114
			current_server_list = strdup(ldap_backups);
114
			current_server_list = strdup(ldap_backups);
115
			while (server_list_entries > 0)
115
			while (server_list_entries > 0)
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/transfile.c (-1 / +4 lines)
Lines 33-38 Link Here
33
#include <stdio.h>
33
#include <stdio.h>
34
#include <stdlib.h>
34
#include <stdlib.h>
35
#include <unistd.h>
35
#include <unistd.h>
36
#include <string.h>
37
#include <errno.h>
36
#include <limits.h>
38
#include <limits.h>
37
#include <assert.h>
39
#include <assert.h>
38
#include <sys/types.h>
40
#include <sys/types.h>
Lines 80-86 static FILE* fopen_lock(const char *name, const char *type, FILE **l_file) Link Here
80
	if ((file = fopen(name, type)) == NULL) {
82
	if ((file = fopen(name, type)) == NULL) {
81
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Could not open file [%s]", name);
83
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Could not open file [%s]", name);
82
84
83
		lockf(l_fd, F_ULOCK, 0);
85
		int rc = lockf(l_fd, F_ULOCK, 0);
86
		if (rc) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to unlock %s: %s", buf, strerror(errno));
84
		fclose(*l_file);
87
		fclose(*l_file);
85
		*l_file = NULL;
88
		*l_file = NULL;
86
	}
89
	}
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/debian/rules (-1 / +1 lines)
Lines 37-43 override_dh_auto_clean: Link Here
37
37
38
override_dh_auto_build:
38
override_dh_auto_build:
39
	$(MAKE) -C src clean
39
	$(MAKE) -C src clean
40
	$(MAKE) -C src DB_CFLAGS="-I/usr/include/db3 -DWITH_DB3" DB_LDADD="-ldb3"
40
	$(MAKE) -C src
41
	dh_auto_build
41
	dh_auto_build
42
42
43
override_dh_auto_install:
43
override_dh_auto_install:
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/Makefile (-18 / +20 lines)
Lines 29-42 Link Here
29
# /usr/share/common-licenses/AGPL-3; if not, see
29
# /usr/share/common-licenses/AGPL-3; if not, see
30
# <http://www.gnu.org/licenses/>.
30
# <http://www.gnu.org/licenses/>.
31
#
31
#
32
CC=gcc
33
DB_LDADD=-ldb3
34
DB_CFLAGS=-I/usr/include/db3 -DWITH_DB3
35
DB_OBJS=cache.o cache_entry.o cache_lowlevel.o base64.o filter.o
36
32
37
CFLAGS += -g -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS)
33
CC ?= gcc
38
LDADD += -g -luniventiondebug -licuuc
34
DB_LDLIBS := -ldb3
39
LISTENER_LDADD=$(LDADD) -luniventionpolicy -lldap -lpython2.7 $(DB_LDADD)
35
DB_CFLAGS := -I/usr/include/db3 -DWITH_DB3
40
LISTENER_OBJS=main.o notifier.o transfile.o handlers.o change.o network.o signals.o select_server.o utils.o $(DB_OBJS)
36
DB_OBJS := cache.o cache_entry.o cache_lowlevel.o base64.o filter.o
41
DUMP_LDADD=$(LDADD) -lldap -luniventionconfig $(DB_LDADD)
37
42
DUMP_OBJS=dump.o dump_signals.o utils.o $(DB_OBJS)
38
LDAP_LDLIBS := -lldap -llber
43
DEMO_LDADD=$(LDADD) -luniventionconfig
39
44
DEMO_OBJS=demo.o network.o utils.o
40
CFLAGS += -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS)
45
VERIFY_LDADD=$(LDADD) -lldap -luniventionconfig $(DB_LDADD)
41
LDLIBS := -luniventiondebug -luniventionconfig -licuuc
46
VERIFY_OBJS=verify.o dump_signals.o utils.o $(DB_OBJS)
42
LISTENER_LDLIBS := -luniventionpolicy $(LDAP_LDLIBS) -lpython2.7 $(DB_LDLIBS)
43
LISTENER_OBJS := main.o notifier.o transfile.o handlers.o change.o network.o signals.o select_server.o utils.o $(DB_OBJS)
44
DUMP_LDLIBS := $(LDAP_LDLIBS) $(DB_LDLIBS)
45
DUMP_OBJS := dump.o dump_signals.o utils.o $(DB_OBJS)
46
DEMO_OBJS := demo.o network.o utils.o
47
VERIFY_LDLIBS := $(LDAP_LDLIBS) $(DB_LDLIBS)
48
VERIFY_OBJS := verify.o dump_signals.o utils.o $(DB_OBJS)
47
49
48
.PHONY: all
50
.PHONY: all
49
all: listener dump verify
51
all: listener dump verify
50
52
51
listener: $(LISTENER_OBJS)
53
listener: $(LISTENER_OBJS)
52
	$(CC) -o $@ $^ $(LISTENER_LDADD)
54
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LISTENER_LDLIBS)
53
55
54
dump: $(DUMP_OBJS)
56
dump: $(DUMP_OBJS)
55
	$(CC) -o $@ $^ $(DUMP_LDADD)
57
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(DUMP_LDLIBS)
56
58
57
demo: $(DEMO_OBJS)
59
demo: $(DEMO_OBJS)
58
	$(CC) -o $@ $^ $(DEMO_LDADD)
60
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(DEMO_LDLIBS)
59
61
60
verify: $(VERIFY_OBJS)
62
verify: $(VERIFY_OBJS)
61
	$(CC) -o $@ $^ $(VERIFY_LDADD)
63
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(VERIFY_LDLIBS)
62
64
63
.PHONY: clean
65
.PHONY: clean
64
clean:
66
clean:
(-)a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/tests/Makefile (-2 / +2 lines)
Lines 42-49 test__utils__same_dn: ../src/utils.o Link Here
42
42
43
include ../src/Makefile
43
include ../src/Makefile
44
44
45
CFLAGS := -g -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS) -I../src
45
CFLAGS += -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS) -I../src
46
LDFLAGS := -Wl,--unresolved-symbols=ignore-all -Wl,--as-needed
46
LDFLAGS += -Wl,--unresolved-symbols=ignore-all -Wl,--as-needed
47
LDLIBS := -lldap -licuuc
47
LDLIBS := -lldap -licuuc
48
48
49
.PHONY: clean
49
.PHONY: clean

Return to bug 42701