From 5a3eb1df560f29c4692e01594fc63d22bb4c50ee Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sat, 17 Oct 2009 10:17:33 +0000 Subject: provide replacement functions for ldap_initialize() and ldap_passwd_s() and centralise LDAP compatibility hacks into ldap_compat.h git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1007 ef36b2f9-881f-0410-afb5-c4e39611909c --- compat/ldap_initialize.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 compat/ldap_initialize.c (limited to 'compat/ldap_initialize.c') diff --git a/compat/ldap_initialize.c b/compat/ldap_initialize.c new file mode 100644 index 0000000..d397784 --- /dev/null +++ b/compat/ldap_initialize.c @@ -0,0 +1,64 @@ +/* + ldap_initialize.c - replacement function for ldap_initialize() + + Copyright (C) 2009 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#include "config.h" + +/* also include deprecated LDAP functions for now */ +#define LDAP_DEPRECATED 1 + +#include +#include +#include +#include +#include + +#include "compat/ldap_compat.h" +#include "nslcd/log.h" + + +/* provide a wrapper around ldap_init() if the system doesn't have + ldap_initialize() */ +int ldap_initialize(LDAP **ldp,const char *url) +{ + char host[80]; + /* check schema part */ + if (strncasecmp(url,"ldap://",7)==0) + { + strncpy(host,url+7,sizeof(host)); + host[sizeof(host)-1]='\0'; + } + else if (strncasecmp(url,"ldaps://",8)==0) + { + strncpy(host,url+8,sizeof(host)); + host[sizeof(host)-1]='\0'; + } + else + { + log_log(LOG_ERR,"ldap_initialize(): schema not supported: %s",url); + exit(EXIT_FAILURE); + } + /* strip trailing slash */ + if ((strlen(host)>0)&&(host[strlen(host)-1]=='/')) + host[strlen(host)-1]='\0'; + /* call ldap_init() */ + *ldp=ldap_init(host,LDAP_PORT); + return (*ldp==NULL)?LDAP_OPERATIONS_ERROR:LDAP_SUCCESS; +} -- cgit v1.2.3