+ ldap_time_disconnect=0;
+}
+
+
+
+
+
+int CtdlConnectToLdap(void) {
+ int i;
+ int ldap_version = 3;
+
+ if (ldap_time_disconnect && dirserver)
+ { // Already connected
+ ldap_time_disconnect=5; // reset the timer.
+ return 0;
+ }
+
+ lprintf(CTDL_INFO, "LDAP: Connecting to LDAP server %s:%d...\n",
+ config.c_ldap_host, config.c_ldap_port);
+
+ dirserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
+ if (dirserver == NULL) {
+ lprintf(CTDL_CRIT, "LDAP: Could not connect to %s:%d : %s\n",
+ config.c_ldap_host,
+ config.c_ldap_port,
+ strerror(errno));
+ aide_message(strerror(errno), "LDAP: Could not connect to server.");
+ return -1;
+ }
+
+ ldap_set_option(dirserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
+
+ lprintf(CTDL_INFO, "LDAP: Binding to %s\n", config.c_ldap_bind_dn);
+
+ i = ldap_simple_bind_s(dirserver,
+ config.c_ldap_bind_dn,
+ config.c_ldap_bind_pw
+ );
+ if (i != LDAP_SUCCESS) {
+ lprintf(CTDL_CRIT, "LDAP: Cannot bind: %s (%d)\n", ldap_err2string(i), i);
+ dirserver = NULL; /* FIXME disconnect from ldap */
+ aide_message(ldap_err2string(i), "LDAP: Cannot bind to server");
+ return -1;
+ }
+ ldap_time_disconnect=5;
+ return 0;