-/*
+/* x3ldap.c - LDAP functionality for x3, by Rubin
+ * Copyright 2002-2007 x3 Development Team
+ *
+ * This file is part of x3.
+ *
+ * x3 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
- * LDAP functionality for x3, by Rubin
*
* TODO:
* * get queries working in static existance, so i understand how it works
* * nickserv.c work to use said functions.
*/
+#include "config.h"
+#ifdef WITH_LDAP
+
#include <stdio.h>
#include <stdlib.h>
#include <ldap.h>
//#include <sys/select.h>
#include "conf.h"
-#include "config.h"
#include "global.h"
+#include "log.h"
#include "x3ldap.h"
#ifdef HAVE_FCNTL_H
#include <sys/socket.h>
#endif
-#ifdef WITH_LDAP
/* char dn[] = "uid=%s,ou=Users,dc=afternet,dc=org";
char password[] = "xxxxxxx";
extern struct nickserv_config nickserv_conf;
-/* TODO: change all these printfs to proper debug statements */
-
LDAP *ld = NULL;
int ldap_do_init()
{
+ if(!nickserv_conf.ldap_enable)
+ return false;
/* TODO: check here for all required config options and exit() out if not present */
ld = ldap_init(nickserv_conf.ldap_host, nickserv_conf.ldap_port);
if(ld == NULL) {
- printf("Failed!\n");
+ log_module(MAIN_LOG, LOG_ERROR, "LDAP initilization failed!\n");
exit(1);
}
ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &nickserv_conf.ldap_version);
- printf("Success! ldap_init() was successfull in connecting to %s port %d\n", nickserv_conf.ldap_host, nickserv_conf.ldap_port );
+ log_module(MAIN_LOG, LOG_INFO, "Success! ldap_init() was successfull in connecting to %s port %d\n", nickserv_conf.ldap_host, nickserv_conf.ldap_port );
return true;
}
char buff[MAXLEN];
int q;
+ if(!nickserv_conf.ldap_enable)
+ return false;
+
memset(buff, 0, MAXLEN);
snprintf(buff, sizeof(buff)-1, nickserv_conf.ldap_dn_fmt /*"uid=%s,ou=Users,dc=afternet,dc=org"*/, account);
int n = 0;
return false;
}
else {
- printf("Bind failed: %s/****** (%d)\n", buff, q);
+ log_module(MAIN_LOG, LOG_ERROR, "Bind failed: %s/****** (%d)\n", buff, q);
ldap_perror(ld, "ldap");
/* Re-init to re-connect to ldap server if thats the problem */
- sleep(10);
+ //sleep(10);
ldap_do_init(nickserv_conf);
}
- if(n++ > 6) {
- printf("Failing to reconnect to ldap server. Dieing.");
- exit(1);
+ if(n++ > 1) {
+ /* TODO: return to the user that this is a connection error and not a problem
+ * with their password
+ */
+ log_module(MAIN_LOG, LOG_ERROR, "Failing to reconnect to ldap server. Auth failing.");
+ return false;
}
}
- printf("bind() successfull! You are bound as %s\n", buff);
+ log_module(MAIN_LOG, LOG_DEBUG, "bind() successfull! You are bound as %s\n", buff);
return true;
}
timeout.tv_usec = 0;
timeout.tv_sec = 5;
if( ldap_search_st(ld, base, LDAP_SCOPE_ONELEVEL, filter, NULL, 0, &timeout, &res) != LDAP_SUCCESS) {
- printf("search failed: %s %s\n", base, filter);
+ log_module(MAIN_LOG, LOG_ERROR, "search failed: %s %s\n", base, filter);
exit(1);
}
- printf("Search successfull! %s %s\n", base, filter);
- printf("Got %d entries\n", ldap_count_entries(ld, res));
+ log_module(MAIN_LOG, LOG_DEBUG, "Search successfull! %s %s\n", base, filter);
+ log_module(MAIN_LOG, LOG_DEBUG, "Got %d entries\n", ldap_count_entries(ld, res));
{
LDAPMessage *entry;
char **value;
entry = ldap_first_entry(ld, res);
value = ldap_get_values(ld, entry, "cn");
- printf("cn: %s\n", value[0]);
+ log_module(MAIN_LOG, LOG_DEBUG, "cn: %s\n", value[0]);
value = ldap_get_values(ld, entry, "description");
- printf("Description: %s\n", value[0]);
+ log_module(MAIN_LOG, LOG_DEBUG, "Description: %s\n", value[0]);
value = ldap_get_values(ld, entry, "userPassword");
- printf("pass: %s\n", value ? value[0] : "error");
+ log_module(MAIN_LOG, LOG_DEBUG, "pass: %s\n", value ? value[0] : "error");
}
/*
ldap_result();