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

(-)a/branches/ucs-3.2/ucs-3.2-0/base/univention-config-registry/lib/config.c (-3 / +17 lines)
 Lines 48-54    Link Here 
48
#define BASECONFIG_MAX_LINE 1024
48
#define BASECONFIG_MAX_LINE 1024
49
49
50
50
51
const char *SCOPES[] = {
51
static const char *SCOPES[] = {
52
	"forced",
52
	"forced",
53
	"schedule",
53
	"schedule",
54
	"ldap",
54
	"ldap",
 Lines 56-62   const char *SCOPES[] = { Link Here 
56
	"custom",
56
	"custom",
57
	NULL};
57
	NULL};
58
58
59
const char *BASES[] = {
59
static const char *BASES[] = {
60
			"/etc/univention/base-forced.conf",
60
			"/etc/univention/base-forced.conf",
61
			"/etc/univention/base-schedule.conf",
61
			"/etc/univention/base-schedule.conf",
62
			"/etc/univention/base-ldap.conf",
62
			"/etc/univention/base-ldap.conf",
 Lines 87-93   char *univention_config_get_string(const char *key) Link Here 
87
		{
87
		{
88
			if (!strncmp(line, nvalue, len))
88
			if (!strncmp(line, nvalue, len))
89
			{
89
			{
90
				ret = strndup(line + len, strlen(line) - len - 1 ); /* no newline */
90
				char *value;
91
				size_t vlen;
92
93
				value = line + len; // skip key
94
				vlen = strlen(value);
95
				while (vlen > 0) {
96
					switch (value[vlen - 1]) {
97
					case '\n':
98
					case '\r':
99
						value[--vlen] = '\0';
100
						continue;
101
					}
102
					break;
103
				}
104
				ret = strndup(value, vlen);
91
				fclose(file);
105
				fclose(file);
92
				goto done;
106
				goto done;
93
			}
107
			}
(-)a/branches/ucs-3.2/ucs-3.2-0/base/univention-config-registry/tests/clib.c (-3 / +79 lines)
 Lines 3-33    Link Here 
3
#include <unistd.h>
3
#include <unistd.h>
4
#include <assert.h>
4
#include <assert.h>
5
#include <univention/config.h>
5
#include <univention/config.h>
6
#include <sys/types.h>
7
#include <sys/wait.h>
8
9
static char ucr_bin[] = "/usr/sbin/univention-config-registry";
10
static char ucr_name[] = "univention-config-registry";
11
static char key[] = "test/clib";
12
static char *LAYER[] = {
13
	"--ldap-policy",
14
	"--schedule",
15
	"--force",
16
	NULL,
17
};
18
19
int fork_exec(char **argv) {
20
	pid_t pid;
21
	int status;
22
23
	pid = fork();
24
	switch (pid) {
25
	case -1: // error
26
		abort();
27
28
	case 0: // child
29
		return execv(ucr_bin, argv);
30
31
	default: // parent
32
		pid = wait(&status);
33
		assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
34
		return 0;
35
	}
36
}
37
38
int test_layer(void) {
39
	char assign[64];
40
	int r, layer;
41
	pid_t pid;
42
43
	for (layer = 0; LAYER[layer]; layer++) {
44
		size_t size;
45
46
		size = snprintf(assign, sizeof assign, "%s=%s", key, LAYER[layer]);
47
		assert(0 < size && size < sizeof assign);
48
		char *argv[] = {
49
			ucr_name,
50
			"set",
51
			LAYER[layer],
52
			assign,
53
			NULL
54
		};
55
		fprintf(stderr, "set %s %s\n", LAYER[layer], assign);
56
		fork_exec(argv);
57
58
		char *c = univention_config_get_string(key);
59
		fprintf(stderr, "should=%s is=%s\n", LAYER[layer], c);
60
		r = strcmp(c, LAYER[layer]);
61
		assert(r == 0);
62
	}
63
64
	for (layer = 0; LAYER[layer]; layer++) {
65
		char *argv[] = {
66
			ucr_name,
67
			"unset",
68
			LAYER[layer],
69
			key,
70
			NULL
71
		};
72
		fprintf(stderr, "unset %s %s\n", LAYER[layer], key);
73
		fork_exec(argv);
74
	}
75
}
6
76
7
int main(void) {
77
int main(void) {
8
	char key[] = "test/clib";
9
	char value[] = "42";
78
	char value[] = "42";
10
	int r;
79
	int r;
11
80
12
	r = univention_config_set_string(key, value);
81
	r = univention_config_set_string(key, value);
82
	fprintf(stderr, "set %s=%s [%d]\n", key, value, r);
13
	assert(r == 0);
83
	assert(r == 0);
14
84
15
	char *c = univention_config_get_string(key);
85
	char *c = univention_config_get_string(key);
86
	fprintf(stderr, "get_str %s=%s\n", key, c);
16
	assert(c != NULL);
87
	assert(c != NULL);
17
	assert(strcmp(c, value) == 0);
88
	assert(strcmp(c, value) == 0);
18
	free(c);
89
	free(c);
19
90
20
	int i = univention_config_get_int(key);
91
	int i = univention_config_get_int(key);
92
	fprintf(stderr, "get_int %s=%d\n", key, i);
21
	assert(i == atoi(value));
93
	assert(i == atoi(value));
22
94
23
	long l = univention_config_get_long(key);
95
	long l = univention_config_get_long(key);
96
	fprintf(stderr, "get_long %s=%d\n", key, l);
24
	assert(l == atol(value));
97
	assert(l == atol(value));
25
98
99
	test_layer();
100
26
	char *argv[] = {
101
	char *argv[] = {
27
		"univention-config-registry",
102
		ucr_name,
28
		"unset",
103
		"unset",
29
		key,
104
		key,
30
		NULL
105
		NULL
31
	};
106
	};
32
	return execv("/usr/sbin/univention-config-registry", argv);
107
	fprintf(stderr, "unset %s\n", key);
108
	return execv(ucr_bin, argv);
33
}
109
}

Return to bug 29964