From 0ab357e3c9dc9cbadc808367db99908591942780 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Tue, 13 Oct 2009 12:11:07 +0200 Subject: add a replacement if ldap_control_create is missing --- server/Makefile.am | 4 ++- server/external/ldap.m4 | 9 +++++ server/providers/ldap/sdap.c | 1 - server/providers/ldap/sdap.h | 2 +- server/providers/ldap/sdap_async.c | 12 +++---- server/util/sss_ldap.c | 70 ++++++++++++++++++++++++++++++++++++++ server/util/sss_ldap.h | 30 ++++++++++++++++ 7 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 server/util/sss_ldap.c create mode 100644 server/util/sss_ldap.h diff --git a/server/Makefile.am b/server/Makefile.am index a700eea5a..19b9095c4 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -238,6 +238,7 @@ dist_noinst_HEADERS = \ util/sssd-i18n.h \ util/util.h \ util/strtonum.h \ + util/sss_ldap.h \ config.h \ monitor/monitor.h \ monitor/monitor_interfaces.h \ @@ -427,7 +428,8 @@ libsss_ldap_la_SOURCES = \ providers/ldap/ldap_id.c \ providers/ldap/ldap_auth.c \ providers/ldap/sdap_async.c \ - providers/ldap/sdap.c + providers/ldap/sdap.c \ + util/sss_ldap.c libsss_ldap_la_CFLAGS = \ $(AM_CFLAGS) \ $(LDAP_CFLAGS) \ diff --git a/server/external/ldap.m4 b/server/external/ldap.m4 index 5e817b824..a17ed7e9c 100644 --- a/server/external/ldap.m4 +++ b/server/external/ldap.m4 @@ -38,3 +38,12 @@ else fi AC_SUBST(OPENLDAP_LIBS) + +SAVE_CFLAGS=$CFLAGS +SAVE_LIBS=$LIBS +CFLAGS="$CFLAGS $OPENLDAP_CFLAGS" +LIBS="$LIBS $OPENLDAP_LIBS" +AC_CHECK_FUNCS([ldap_control_create]) +CFLAGS=$SAVE_CFLAGS +LIBS=$SAVE_LIBS + diff --git a/server/providers/ldap/sdap.c b/server/providers/ldap/sdap.c index 47f76f9cd..ba234ed09 100644 --- a/server/providers/ldap/sdap.c +++ b/server/providers/ldap/sdap.c @@ -20,7 +20,6 @@ */ #define LDAP_DEPRECATED 1 -#include #include "util/util.h" #include "confdb/confdb.h" #include "providers/ldap/sdap.h" diff --git a/server/providers/ldap/sdap.h b/server/providers/ldap/sdap.h index 3aa29a377..650ce5f1e 100644 --- a/server/providers/ldap/sdap.h +++ b/server/providers/ldap/sdap.h @@ -21,7 +21,7 @@ #include "confdb/confdb.h" #include "db/sysdb.h" -#include +#include "util/sss_ldap.h" struct sdap_msg { struct sdap_msg *next; diff --git a/server/providers/ldap/sdap_async.c b/server/providers/ldap/sdap_async.c index 80b7e046c..4f9294c51 100644 --- a/server/providers/ldap/sdap_async.c +++ b/server/providers/ldap/sdap_async.c @@ -676,10 +676,10 @@ static struct tevent_req *simple_bind_send(TALLOC_CTX *memctx, state->user_dn = user_dn; state->pw = pw; - ret = ldap_control_create(LDAP_CONTROL_PASSWORDPOLICYREQUEST, 0, NULL, 0, - &request_controls[0]); + ret = sss_ldap_control_create(LDAP_CONTROL_PASSWORDPOLICYREQUEST, + 0, NULL, 0, &request_controls[0]); if (ret != LDAP_SUCCESS) { - DEBUG(1, ("ldap_control_create failed.\n")); + DEBUG(1, ("sss_ldap_control_create failed.\n")); goto fail; } request_controls[1] = NULL; @@ -2699,10 +2699,10 @@ struct tevent_req *sdap_exop_modify_passwd_send(TALLOC_CTX *memctx, return NULL; } - ret = ldap_control_create(LDAP_CONTROL_PASSWORDPOLICYREQUEST, 0, NULL, 0, - &request_controls[0]); + ret = sss_ldap_control_create(LDAP_CONTROL_PASSWORDPOLICYREQUEST, + 0, NULL, 0, &request_controls[0]); if (ret != LDAP_SUCCESS) { - DEBUG(1, ("ldap_control_create failed.\n")); + DEBUG(1, ("sss_ldap_control_create failed.\n")); goto fail; } request_controls[1] = NULL; diff --git a/server/util/sss_ldap.c b/server/util/sss_ldap.c new file mode 100644 index 000000000..f098e7d6d --- /dev/null +++ b/server/util/sss_ldap.c @@ -0,0 +1,70 @@ +/* + Authors: + Sumit Bose + + Copyright (C) 2009 Red Hat + + 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 3 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 this program. If not, see . +*/ +#include + +#include "config.h" + +#include "util/sss_ldap.h" + + +int sss_ldap_control_create(const char *oid, int iscritical, + struct berval *value, int dupval, + LDAPControl **ctrlp) +{ +#ifdef HAVE_LDAP_CONTROL_CREATE + return ldap_control_create(oid, iscritical, value, dupval, ctrlp); +#else + LDAPControl *lc = NULL; + + if (oid == NULL || ctrlp == NULL) { + return LDAP_PARAM_ERROR; + } + + lc = calloc(sizeof(LDAPControl), 1); + if (lc == NULL) { + return LDAP_NO_MEMORY; + } + + lc->ldctl_oid = strdup(oid); + if (lc->ldctl_oid == NULL) { + free(lc); + return LDAP_NO_MEMORY; + } + + if (value != NULL && value->bv_val != NULL) { + if (dupval == 0) { + lc->ldctl_value = *value; + } else { + ber_dupbv(&lc->ldctl_value, value); + if (lc->ldctl_value.bv_val == NULL) { + free(lc->ldctl_oid); + free(lc); + return LDAP_NO_MEMORY; + } + } + } + + lc->ldctl_iscritical = iscritical; + + *ctrlp = lc; + + return LDAP_SUCCESS; +#endif +} diff --git a/server/util/sss_ldap.h b/server/util/sss_ldap.h new file mode 100644 index 000000000..14747dffc --- /dev/null +++ b/server/util/sss_ldap.h @@ -0,0 +1,30 @@ +/* + Authors: + Sumit Bose + + Copyright (C) 2009 Red Hat + + 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 3 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 this program. If not, see . +*/ + +#ifndef __SSS_LDAP_H__ +#define __SSS_LDAP_H__ + +#include + +int sss_ldap_control_create(const char *oid, int iscritical, + struct berval *value, int dupval, + LDAPControl **ctrlp); + +#endif /* __SSS_LDAP_H__ */ -- cgit