diff options
| author | Jelmer Vernooij <jelmer@samba.org> | 2006-03-24 16:53:29 +0100 | 
|---|---|---|
| committer | Jelmer Vernooij <jelmer@samba.org> | 2006-03-24 16:53:29 +0100 | 
| commit | f32d5578d7039f1e61e99b2e1f7bfd0a47828c8c (patch) | |
| tree | 3ed18a062e9ddb4ca307d13db6f55a462441457c | |
| parent | 728a981e422539df38d27d87e33829082d376ac6 (diff) | |
Switch from LDB to LDAP (LDB's authentication subsystem is not mature enough yet)
| -rw-r--r-- | Makefile | 2 | ||||
| -rwxr-xr-x | configure | 30 | ||||
| -rw-r--r-- | storage_ldap.c | 162 | ||||
| -rw-r--r-- | storage_ldb.c | 63 | 
4 files changed, 178 insertions, 79 deletions
| @@ -13,7 +13,7 @@ objects = account.o bitlbee.o conf.o crypting.o help.o ini.o ipc.o irc.o irc_com  headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ini.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h url.h user.h protocols/http_client.h protocols/md5.h protocols/nogaim.h protocols/proxy.h protocols/sha.h protocols/ssl_client.h  subdirs = protocols -objects += $(LDB_OBJ) +objects += $(LDAP_OBJ)  # Expansion of variables  subdirobjs = $(foreach dir,$(subdirs),$(dir)/$(dir).o) @@ -27,7 +27,7 @@ yahoo=1  debug=0  strip=1  ipv6=1 -ldb=auto +ldap=auto  ssl=auto  arch=`uname -s` @@ -64,7 +64,7 @@ Option		Description				Default  --ipv6=0/1	IPv6 socket support			$ipv6 ---ldb=0/1/auto	LDB support				$ldb +--ldap=0/1/auto	LDAP support				$ldap  --ssl=...	SSL library to use (gnutls, nss, openssl, bogus, auto)  							$ssl @@ -223,14 +223,14 @@ EOF  	fi;  } -detect_ldb() +detect_ldap()  {  	if $PKG_CONFIG --version > /dev/null 2>/dev/null && $PKG_CONFIG ldb; then  		cat<<EOF>>Makefile.settings  EFLAGS+=`$PKG_CONFIG --libs ldb`  CFLAGS+=`$PKG_CONFIG --cflags ldb`  EOF -		ldb=1 +		ldap=1  		ret=1  	else  		ret=0 @@ -297,16 +297,16 @@ if [ "$msn" = 1 -o "$jabber" = 1 ]; then  	echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings  fi -if [ "$ldb" = "auto" ]; then -	detect_ldb +if [ "$ldap" = "auto" ]; then +	detect_ldap  fi -if [ "$ldb" = 0 ]; then -	echo "LDB_OBJ=\# no ldb" >> Makefile.settings -	echo "#undef LDB" >> config.h -elif [ "$ldb" = 1 ]; then -	echo "#define LDB 1" >> config.h -	echo "LDB_OBJ=storage_ldb.o" >> Makefile.settings +if [ "$ldap" = 0 ]; then +	echo "LDAP_OBJ=\# no ldap" >> Makefile.settings +	echo "#undef LDAP" >> config.h +elif [ "$ldap" = 1 ]; then +	echo "#define LDAP 1" >> config.h +	echo "LDAP_OBJ=storage_ldap.o" >> Makefile.settings  fi  if [ "$strip" = 0 ]; then @@ -460,8 +460,8 @@ else  	echo '  Building without IM-protocol support. We wish you a lot of fun...';  fi -if [ "$ldb" = "0" ]; then -	echo "  LDB storage backend disabled." +if [ "$ldap" = "0" ]; then +	echo "  LDAP storage backend disabled."  else -	echo "  LDB storage backend enabled." +	echo "  LDAP storage backend enabled."  fi diff --git a/storage_ldap.c b/storage_ldap.c new file mode 100644 index 00000000..f6119168 --- /dev/null +++ b/storage_ldap.c @@ -0,0 +1,162 @@ +  /********************************************************************\ +  * BitlBee -- An IRC to other IM-networks gateway                     * +  *                                                                    * +  * Copyright 2002-2004 Wilmer van der Gaast and others                * +  \********************************************************************/ + +/* Storage backend that uses a LDAP database */ + +/* Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org> */ + +/* +  This program 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 with +  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; +  if not, write to the Free Software Foundation, Inc., 59 Temple Place, +  Suite 330, Boston, MA  02111-1307  USA +*/ + +#define BITLBEE_CORE +#include "bitlbee.h" +#include <ldap.h> + +#define BB_LDAP_HOST "localhost" +#define BB_LDAP_BASE "" + +static char *nick_dn(const char *nick) +{ +	return g_strdup_printf("bitlBeeNick=%s%s%s", nick, BB_LDAP_BASE?",":"", BB_LDAP_BASE?BB_LDAP_BASE:""); +} + +static storage_status_t nick_connect(const char *nick, const char *password, LDAP **ld) +{ +	char *mydn; +	int ret; +	storage_status_t status; +	*ld = ldap_init(BB_LDAP_HOST, LDAP_PORT); + +	if (!ld) { +		/* FIXME: report error */ +		return STORAGE_OTHER_ERROR; +	} + +	mydn = nick_dn(nick); + +	ret = ldap_simple_bind_s(*ld, mydn, password); + +	switch (ret) { +	 case LDAP_SUCCESS: status = STORAGE_OK; break; +	 case LDAP_INVALID_CREDENTIALS: status = STORAGE_INVALID_PASSWORD; break; +	 default:  +		/* FIXME: Log */ +		status = STORAGE_OTHER_ERROR; +		break; +	} + +	g_free(mydn); + +	return status; +} + +static void sldap_init (void) +{ +} + +static storage_status_t sldap_load ( const char *my_nick, const char* password, irc_t *irc ) +{ +	LDAPMessage *res; +	LDAP *ld; +	int ret; +	storage_status_t status; +	char *mydn;  + +	status = nick_connect(my_nick, password, &ld); +	if (status != STORAGE_OK) +		return status; + +	mydn = nick_dn(my_nick); + +	ret = ldap_search_s(ld, mydn, LDAP_SCOPE_ONELEVEL, "(objectClass=*)", NULL, 0, &res); + +	g_free(mydn); + +	/* FIXME: Check ret */ + +	/* FIXME: Store in irc_t */ +	 +	return STORAGE_OK; +} + +static storage_status_t sldap_save( irc_t *irc, int overwrite ) +{ +	LDAP *ld; +	char *mydn; +	storage_status_t status; + +	status = nick_connect(irc->nick, irc->password, &ld); +	if (status != STORAGE_OK) +		return status; + +	mydn = nick_dn(irc->nick); + +	/* FIXME */ +	 +	g_free(mydn); +	 +	return STORAGE_OK; +} + +static storage_status_t sldap_check_pass( const char *nick, const char *password ) +{ +	LDAP *ld; +	storage_status_t status; + +	status = nick_connect(nick, password, &ld); + +	ldap_unbind_s(ld); + +	return status; +} + +static storage_status_t sldap_remove( const char *nick, const char *password ) +{ +	storage_status_t status; +	LDAP *ld; +	char *mydn; +	int ret; +	 +	status = nick_connect(nick, password, &ld); + +	if (status != STORAGE_OK) +		return status; + +	mydn = nick_dn(nick); +	 +	ret = ldap_delete(ld, mydn); + +	if (ret != LDAP_SUCCESS) { +		/* FIXME: report */ +		return STORAGE_OTHER_ERROR; +	} + +	g_free(mydn); +	return STORAGE_OK; +} + +storage_t storage_ldap = { +	.name = "ldap", +	.init = sldap_init, +	.check_pass = sldap_check_pass, +	.remove = sldap_remove, +	.load = sldap_load, +	.save = sldap_save +}; diff --git a/storage_ldb.c b/storage_ldb.c deleted file mode 100644 index 09d1452b..00000000 --- a/storage_ldb.c +++ /dev/null @@ -1,63 +0,0 @@ -  /********************************************************************\ -  * BitlBee -- An IRC to other IM-networks gateway                     * -  *                                                                    * -  * Copyright 2002-2004 Wilmer van der Gaast and others                * -  \********************************************************************/ - -/* Storage backend that uses the LDB embedded LDAP-like database */ - -/* Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org> */ - -/* -  This program 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 with -  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; -  if not, write to the Free Software Foundation, Inc., 59 Temple Place, -  Suite 330, Boston, MA  02111-1307  USA -*/ - -#define BITLBEE_CORE -#include "bitlbee.h" -#include <ldb.h> - -static void sldb_init (void) -{ -} - -static storage_status_t sldb_load ( const char *my_nick, const char* password, irc_t *irc ) -{ -	return STORAGE_OK; -} - -static storage_status_t sldb_save( irc_t *irc, int overwrite ) -{ -	return STORAGE_OK; -} - -static storage_status_t sldb_check_pass( const char *nick, const char *password ) -{ -	return STORAGE_OK; -} - -static storage_status_t sldb_remove( const char *nick, const char *password ) -{ -	return STORAGE_OK; -} - -storage_t storage_ldb = { -	.name = "ldb", -	.init = sldb_init, -	.check_pass = sldb_check_pass, -	.remove = sldb_remove, -	.load = sldb_load, -	.save = sldb_save -}; | 
