diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/cache.c b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/cache.c index d28f96f..f246248 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/cache.c +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/cache.c @@ -248,14 +248,15 @@ int cache_get_schema_id(NotifierID *value, const long def) { FILE *fp; char file[PATH_MAX]; + int rv; *value = def; snprintf(file, PATH_MAX, "%s/schema/id/id", ldap_dir); if ((fp = fopen(file, "r")) == NULL) return 1; - fscanf(fp, "%ld", value); - return fclose(fp); + rv = fscanf(fp, "%ld", value); + return fclose(fp) || (rv != 1); } int cache_set_int(char *key, const NotifierID value) @@ -285,14 +286,15 @@ int cache_get_int(char *key, NotifierID *value, const long def) { FILE *fp; char file[PATH_MAX]; + int rv; *value = def; snprintf(file, PATH_MAX, "%s/%s", cache_dir, key); if ((fp = fopen(file, "r")) == NULL) return 1; - fscanf(fp, "%ld", value); - return fclose(fp); + rv = fscanf(fp, "%ld", value); + return fclose(fp) || (rv != 1); } int cache_get_master_entry(CacheMasterEntry *master_entry) diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.h b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.h index 7f6baf0..f8246b1 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.h +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.h @@ -45,14 +45,11 @@ initializing, HANDLER_READY will be set; however, if the initialization fails, it will be removed again. If it's successful, both, HANDLER_INITIALIZED and HANDLER_READY will be set */ -#define HANDLER_INITIALIZED 000000001 -#define HANDLER_READY 000000002 - -#define HANDLER_PREPARED 000000004 - -#define HANDLER_HAS_FLAG(handler, flag) ((handler->state & flag) == flag) -#define HANDLER_SET_FLAG(handler, flag) handler->state |= flag -#define HANDLER_UNSET_FLAG(handler, flag) handler->state &= ~flag +enum state { + HANDLER_INITIALIZED = 1 << 0, + HANDLER_READY = 1 << 1, + HANDLER_PREPARED = 1 << 2, +}; struct filter { char *base; @@ -71,7 +72,7 @@ struct _Handler { PyObject *setdata; struct _Handler *next; - int state; + enum state state; int prepared : 1; } typedef Handler; @@ -83,7 +83,6 @@ int handlers_init (void); int handlers_free_all (void); int handlers_load_path (char *filename); int handlers_reload_all_paths (void); -int handlers_dump (void); int handlers_update (const char *dn, CacheEntry *new, CacheEntry *old, diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.c b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.c index 65ac580..4c4fef9 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.c +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/handlers.c @@ -262,7 +262,8 @@ static int handler_import(char* filename) if (state_fp == NULL) { handler->state = 0; } else { - fscanf(state_fp, "%d", &handler->state); + rv = fscanf(state_fp, "%u", &handler->state); + if (rv != 1) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed reading %s: %s", state_filename, strerror(errno)); fclose(state_fp); } @@ -466,39 +466,8 @@ int handlers_initialize_all(void) } -/* dump internal state of one handler. */ -static void handler_dump(Handler *handler) -{ - struct filter **filter; - - printf("name: %s\n", handler->name); - printf("description: %s\n", handler->description); - - for (filter = handler->filters; filter != NULL; filter++) { - printf("filter: %s %d %s\n", (*filter)->base, (*filter)->scope, (*filter)->filter); - } - - printf("clean handler: %d\n", handler->clean != NULL); - printf("initialize handler: %d\n", handler->initialize != NULL); - printf("prerun handler: %d\n", handler->prerun != NULL); - printf("postrun handler: %d\n", handler->postrun != NULL); - printf("setdata handler: %d\n", handler->setdata != NULL); -} - - -/* dump internal state of all handlers. UNUSED */ -int handlers_dump(void) -{ - Handler *handler; - for (handler=handlers; handler != NULL; handler=handler->next) - handler_dump(handler); - - return 0; -} - - /* Load all handlers from one directory. */ -int handlers_load_path(char *path) +static int handlers_load_path(char *path) { char **module_dir; @@ -733,7 +733,7 @@ static PyObject* handlers_argtuple_command(const char *dn, CacheEntry *new, Cach /* return boolean indicating whether attribute has changed */ -int attribute_has_changed(char** changes, char* attribute) +static int attribute_has_changed(char** changes, char* attribute) { char **cur; @@ -885,7 +885,7 @@ char *handlers_filter(void) /* Pass configuration data from listener to one module. */ -int handler_set_data(Handler *handler, PyObject *argtuple) +static int handler_set_data(Handler *handler, PyObject *argtuple) { PyObject *result; int rv; diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/main.c b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/main.c index 5b172c7..1e51c00 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/main.c +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/main.c @@ -103,7 +103,7 @@ static void daemonize(int lock_fd) if (rv < 0 || rv >= PATH_MAX) abort(); - fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL); + fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL, 0644); if (fd < 0) { if (errno == EEXIST) univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "pidfile %s exists, aborting...%d %s", pidfile, errno, strerror(errno)); @@ -149,29 +149,34 @@ static void daemonize(int lock_fd) rv = snprintf(buf, sizeof buf, "%d", pid); if (rv < 0 || rv >= sizeof buf) abort(); - write(fd, buf, rv); + rv = write(fd, buf, rv); + if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to write %s: %s", pidfile, strerror(errno)); } - close(fd); + rv = close(fd); + if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close %s: %s", pidfile, strerror(errno)); // Set new file permissions umask(0); // Change the working directory to the root directory - chdir("/"); + rv = chdir("/"); + if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to change directory: %s", strerror(errno)); if ((null = open("/dev/null", O_RDWR)) == -1) { - univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not open /dev/null"); + univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "could not open /dev/null: %s", strerror(errno)); exit(EXIT_FAILURE); } dup2(null, STDIN_FILENO); dup2(null, STDOUT_FILENO); - if ((log = open("/var/log/univention/listener.log", O_WRONLY | O_CREAT | O_APPEND)) >= 0) { + if ((log = open("/var/log/univention/listener.log", O_WRONLY | O_CREAT | O_APPEND, 0640)) >= 0) { dup2(log, STDERR_FILENO); - close(log); + rv = close(log); + if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close /var/log/univention/listener.log: %s", strerror(errno)); } else { dup2(null, STDERR_FILENO); } - close(null); + rv = close(null); + if (rv) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to close /dev/null: %s", strerror(errno)); // Close all open file descriptors for (fd = sysconf(_SC_OPEN_MAX); fd > STDERR_FILENO; fd--) diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/select_server.c b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/select_server.c index ebfdad2..a421e66 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/select_server.c +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/select_server.c @@ -109,7 +109,7 @@ void select_server(univention_ldap_parameters_t *lp) } if (ldap_backups && !current_server_list) { - char *str, *saveptr; + char *str, *saveptr = NULL; /* rebuild list and initialize */ current_server_list = strdup(ldap_backups); while (server_list_entries > 0) diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/transfile.c b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/transfile.c index 3abb31e..ec2cf9f 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/transfile.c +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/transfile.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include #include #include @@ -80,7 +82,8 @@ static FILE* fopen_lock(const char *name, const char *type, FILE **l_file) if ((file = fopen(name, type)) == NULL) { univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Could not open file [%s]", name); - lockf(l_fd, F_ULOCK, 0); + int rc = lockf(l_fd, F_ULOCK, 0); + if (rc) univention_debug(UV_DEBUG_LDAP, UV_DEBUG_WARN, "Failed to unlock %s: %s", buf, strerror(errno)); fclose(*l_file); *l_file = NULL; } diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/debian/rules b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/debian/rules index 571dbdd..04bb870 100755 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/debian/rules +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/debian/rules @@ -37,7 +37,7 @@ override_dh_auto_clean: override_dh_auto_build: $(MAKE) -C src clean - $(MAKE) -C src DB_CFLAGS="-I/usr/include/db3 -DWITH_DB3" DB_LDADD="-ldb3" + $(MAKE) -C src dh_auto_build override_dh_auto_install: diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/Makefile b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/Makefile index fcb4d29..bf2789c 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/Makefile +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/src/Makefile @@ -29,14 +29,14 @@ # /usr/share/common-licenses/AGPL-3; if not, see # . # -CC=gcc -DB_LDADD=-ldb3 -DB_CFLAGS=-I/usr/include/db3 -DWITH_DB3 -DB_OBJS=cache.o cache_entry.o cache_lowlevel.o base64.o filter.o -CFLAGS += -g -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS) -LDADD += -g -luniventiondebug -licuuc -LISTENER_LDADD=$(LDADD) -luniventionpolicy -lldap -lpython2.7 $(DB_LDADD) -LISTENER_OBJS=main.o notifier.o transfile.o handlers.o change.o network.o signals.o select_server.o utils.o $(DB_OBJS) -DUMP_LDADD=$(LDADD) -lldap -luniventionconfig $(DB_LDADD) -DUMP_OBJS=dump.o dump_signals.o utils.o $(DB_OBJS) -DEMO_LDADD=$(LDADD) -luniventionconfig -DEMO_OBJS=demo.o network.o utils.o -VERIFY_LDADD=$(LDADD) -lldap -luniventionconfig $(DB_LDADD) -VERIFY_OBJS=verify.o dump_signals.o utils.o $(DB_OBJS) +CC ?= gcc +DB_LDLIBS := -ldb3 +DB_CFLAGS := -I/usr/include/db3 -DWITH_DB3 +DB_OBJS := cache.o cache_entry.o cache_lowlevel.o base64.o filter.o + +LDAP_LDLIBS := -lldap -llber + +CFLAGS += -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS) +LDLIBS := -luniventiondebug -luniventionconfig -licuuc +LISTENER_LDLIBS := -luniventionpolicy $(LDAP_LDLIBS) -lpython2.7 $(DB_LDLIBS) +LISTENER_OBJS := main.o notifier.o transfile.o handlers.o change.o network.o signals.o select_server.o utils.o $(DB_OBJS) +DUMP_LDLIBS := $(LDAP_LDLIBS) $(DB_LDLIBS) +DUMP_OBJS := dump.o dump_signals.o utils.o $(DB_OBJS) +DEMO_OBJS := demo.o network.o utils.o +VERIFY_LDLIBS := $(LDAP_LDLIBS) $(DB_LDLIBS) +VERIFY_OBJS := verify.o dump_signals.o utils.o $(DB_OBJS) .PHONY: all all: listener dump verify listener: $(LISTENER_OBJS) - $(CC) -o $@ $^ $(LISTENER_LDADD) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LISTENER_LDLIBS) dump: $(DUMP_OBJS) - $(CC) -o $@ $^ $(DUMP_LDADD) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(DUMP_LDLIBS) demo: $(DEMO_OBJS) - $(CC) -o $@ $^ $(DEMO_LDADD) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(DEMO_LDLIBS) verify: $(VERIFY_OBJS) - $(CC) -o $@ $^ $(VERIFY_LDADD) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(VERIFY_LDLIBS) .PHONY: clean clean: diff --git a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/tests/Makefile b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/tests/Makefile index ade1c82..ca924af 100644 --- a/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/tests/Makefile +++ b/branches/ucs-4.1/ucs-4.1-3/management/univention-directory-listener/tests/Makefile @@ -42,8 +42,8 @@ test__utils__same_dn: ../src/utils.o include ../src/Makefile -CFLAGS := -g -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS) -I../src -LDFLAGS := -Wl,--unresolved-symbols=ignore-all -Wl,--as-needed +CFLAGS += -Wall -Werror -D_FILE_OFFSET_BITS=64 $(DB_CFLAGS) -I../src +LDFLAGS += -Wl,--unresolved-symbols=ignore-all -Wl,--as-needed LDLIBS := -lldap -licuuc .PHONY: clean