summaryrefslogtreecommitdiffstats
path: root/daemons/ipa-slapi-plugins/ipa-pwd-extop
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2011-01-03 16:16:57 +0100
committerSimo Sorce <ssorce@redhat.com>2011-01-07 05:00:44 -0500
commit8a9fdbfb039bf1894cf3b301c8a0f84261ec8c1c (patch)
treef08d850fd5b68f8bb06a5e92cbbea5fb49b277c0 /daemons/ipa-slapi-plugins/ipa-pwd-extop
parent21bf175e0c10b087deb10b8e328a6a6bd549c0f9 (diff)
downloadfreeipa-8a9fdbfb039bf1894cf3b301c8a0f84261ec8c1c.tar.gz
freeipa-8a9fdbfb039bf1894cf3b301c8a0f84261ec8c1c.tar.xz
freeipa-8a9fdbfb039bf1894cf3b301c8a0f84261ec8c1c.zip
Do not use LDAP_DEPRECATED in plugins
Remove the LDAP_DEPRECATED constant and do not use functions that are marked as deprecated in recent OpenLDAP releases. Also always define WITH_{MOZLDAP,OPENLDAP} since there are conditional header includes that depend on that constant. https://fedorahosted.org/freeipa/ticket/576
Diffstat (limited to 'daemons/ipa-slapi-plugins/ipa-pwd-extop')
-rw-r--r--daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd.h2
-rw-r--r--daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd_common.c50
2 files changed, 39 insertions, 13 deletions
diff --git a/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd.h b/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd.h
index 4f8764f4c..aaaeeb717 100644
--- a/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd.h
+++ b/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd.h
@@ -49,8 +49,6 @@
#include <unistd.h>
#include <stdbool.h>
-#define LDAP_DEPRECATED 1
-
#include <prio.h>
#include <ssl.h>
#include <dirsrv/slapi-plugin.h>
diff --git a/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd_common.c b/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd_common.c
index cf6b3fc9b..2bc36c09e 100644
--- a/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd_common.c
+++ b/daemons/ipa-slapi-plugins/ipa-pwd-extop/ipapwd_common.c
@@ -373,6 +373,40 @@ static void pwd_values_free(Slapi_ValueSet** results,
slapi_vattr_values_free(results, actual_type_name, buffer_flags);
}
+static int ipapwd_rdn_count(const char *dn)
+{
+ int rdnc = 0;
+
+#ifdef WITH_MOZLDAP
+ char **edn;
+
+ edn = ldap_explode_dn(dn, 0);
+ if (!edn) {
+ LOG_TRACE("ldap_explode_dn(dn) failed ?!");
+ return -1;
+ }
+
+ for (rdnc = 0; edn != NULL && edn[rdnc]; rdnc++) /* count */ ;
+ ldap_value_free(edn);
+#else
+ /* both ldap_explode_dn and ldap_value_free are deprecated
+ * in OpenLDAP */
+ LDAPDN ldn;
+ int ret;
+
+ ret = ldap_str2dn(dn, &ldn, LDAP_DN_FORMAT_LDAPV3);
+ if (ret != LDAP_SUCCESS) {
+ LOG_TRACE("ldap_str2dn(dn) failed ?!");
+ return -1;
+ }
+
+ for (rdnc = 0; ldn != NULL && ldn[rdnc]; rdnc++) /* count */ ;
+ ldap_dnfree(ldn);
+#endif
+
+ return rdnc;
+}
+
static int ipapwd_getPolicy(const char *dn,
Slapi_Entry *target, Slapi_Entry **e)
{
@@ -386,7 +420,6 @@ static int ipapwd_getPolicy(const char *dn,
"krbPwdHistoryLength", NULL};
Slapi_Entry **es = NULL;
Slapi_Entry *pe = NULL;
- char **edn;
int ret, res, dist, rdnc, scope, i;
Slapi_DN *sdn = NULL;
int buffer_flags=0;
@@ -465,14 +498,12 @@ static int ipapwd_getPolicy(const char *dn,
}
/* count number of RDNs in DN */
- edn = ldap_explode_dn(dn, 0);
- if (!edn) {
- LOG_TRACE("ldap_explode_dn(dn) failed ?!");
+ rdnc = ipapwd_rdn_count(dn);
+ if (rdnc == -1) {
+ LOG_TRACE("ipapwd_rdn_count(dn) failed");
ret = -1;
goto done;
}
- for (rdnc = 0; edn[rdnc]; rdnc++) /* count */ ;
- ldap_value_free(edn);
pe = NULL;
dist = -1;
@@ -490,15 +521,12 @@ static int ipapwd_getPolicy(const char *dn,
}
if (slapi_sdn_issuffix(sdn, esdn)) {
const char *dn1;
- char **e1;
int c1;
dn1 = slapi_sdn_get_dn(esdn);
if (!dn1) continue;
- e1 = ldap_explode_dn(dn1, 0);
- if (!e1) continue;
- for (c1 = 0; e1[c1]; c1++) /* count */ ;
- ldap_value_free(e1);
+ c1 = ipapwd_rdn_count(dn1);
+ if (c1 == -1) continue;
if ((dist == -1) ||
((rdnc - c1) < dist)) {
dist = rdnc - c1;