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

(-)lib/license_ldap.c (-1 / +55 lines)
 Lines 8-14    Link Here 
8
8
9
univention_ldap_parameters_t* lp = NULL;
9
univention_ldap_parameters_t* lp = NULL;
10
10
11
#define _UNIVENTION_LDAP_MACHINE_SECRET_LEN_MAX 60
12
int univention_ldap_set_machine_connection( univention_ldap_parameters_t *lp )
13
{
14
	FILE *secret;
15
	size_t len;
11
16
17
	asprintf(&lp->binddn, univention_config_get_string("ldap/hostdn"));
18
	if (!lp->binddn) {
19
		goto err;
20
	}
21
22
	secret = fopen("/etc/machine.secret", "r" );
23
	if (!secret)
24
		goto err1;
25
26
	lp->bindpw = calloc(_UNIVENTION_LDAP_MACHINE_SECRET_LEN_MAX, sizeof(char));
27
	if (!lp->bindpw) {
28
		fclose(secret);
29
		goto err1;
30
	}
31
32
	len = fread(lp->bindpw, _UNIVENTION_LDAP_MACHINE_SECRET_LEN_MAX, sizeof(char), secret);
33
	if (ferror(secret))
34
		len = -1;
35
	fclose(secret);
36
37
	for (; len >= 0; len--) {
38
		switch (lp->bindpw[len]) {
39
			case '\r':
40
			case '\n':
41
				lp->bindpw[len] = '\0';
42
			case '\0':
43
				continue;
44
			default:
45
				return 0;
46
		}
47
	}
48
49
	/* password already cleared memory. */
50
	if (lp->bindpw != NULL) {
51
		free(lp->bindpw);
52
		lp->bindpw = NULL;
53
	}
54
err1:
55
	if (lp->binddn != NULL) {
56
		free(lp->binddn);
57
		lp->binddn = NULL;
58
	}
59
err:
60
	return 1;
61
}	
62
12
/******************************************************************************/
63
/******************************************************************************/
13
/*!
64
/*!
14
	@brief initialitze the ldap part of the lib, automatic called if need
65
	@brief initialitze the ldap part of the lib, automatic called if need
 Lines 20-26    Link Here 
20
int univention_license_ldap_init(void)
71
int univention_license_ldap_init(void)
21
{
72
{
22
	lp = univention_ldap_new();
73
	lp = univention_ldap_new();
23
	univention_ldap_set_admin_connection(lp);
74
	if (univention_ldap_set_admin_connection(lp)) {
75
		univention_debug(UV_DEBUG_LDAP, UV_DEBUG_INFO, "univention_ldap_set_admin_connection() failed, trying univention_ldap_set_machine_connection().");
76
		univention_ldap_set_machine_connection(lp);
77
	}
24
	univention_ldap_open(lp);
78
	univention_ldap_open(lp);
25
79
26
	return 1;
80
	return 1;

Return to bug 35157