From 99a7f83c3c123554ca7279ec97abddd717f5ee70 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 26 Oct 2010 11:29:53 -0400 Subject: ipa_uuid: Handle generation of the uuid when it is a RDN --- daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c | 60 ++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'daemons/ipa-slapi-plugins/ipa-uuid') diff --git a/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c b/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c index eb5b40d73..c0fde90fd 100644 --- a/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c +++ b/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c @@ -987,17 +987,13 @@ static int ipauuid_pre_op(Slapi_PBlock *pb, int modtype) bv = slapi_mod_get_first_value(smod); /* If we have a value, see if it's the magic value. */ if (bv) { - int len = strlen(cfgentry->generate); - if (len == bv->bv_len) { - if (!slapi_UTF8NCASECMP(bv->bv_val, - cfgentry->generate, - len)) { - generate = true; + if (!slapi_UTF8CASECMP(bv->bv_val, + cfgentry->generate)) { + generate = true; - /* also remove this mod, as we will add - * it again later */ - slapi_mod_remove_value(next_mod); - } + /* also remove this mod, as we will add + * it again later */ + slapi_mod_remove_value(next_mod); } } else { /* This is a replace with no new values, so we need @@ -1054,8 +1050,52 @@ static int ipauuid_pre_op(Slapi_PBlock *pb, int modtype) /* do the mod */ if (LDAP_CHANGETYPE_ADD == modtype) { + Slapi_DN *sdn; + Slapi_RDN *rdn; + char *attr; + char *nrdn; + /* add - set in entry */ slapi_entry_attr_set_charptr(e, cfgentry->attr, new_value); + + /* check to see if we need to change the RDN too */ + rdn = slapi_rdn_new(); + if (!rdn) { + LOG_OOM(); + ret = LDAP_OPERATIONS_ERROR; + goto done; + } + sdn = slapi_sdn_new_dn_byval(dn); + if (!sdn) { + LOG_OOM(); + ret = LDAP_OPERATIONS_ERROR; + slapi_rdn_free(&rdn); + goto done; + } + slapi_rdn_set_sdn(rdn, sdn); + ret = slapi_rdn_contains_attr(rdn, cfgentry->attr, &attr); + slapi_rdn_done(rdn); + if (ret == 1) { + /* no need to recheck if it is valid, it will be handled + * later by checking the value in the entry */ + nrdn = slapi_ch_smprintf("%s=%s", + cfgentry->attr, new_value); + if (!nrdn) { + LOG_OOM(); + ret = LDAP_OPERATIONS_ERROR; + slapi_rdn_free(&rdn); + slapi_sdn_free(&sdn); + goto done; + } + + slapi_rdn_set_dn(rdn, nrdn); + slapi_ch_free_string(&nrdn); + slapi_sdn_set_rdn(sdn, rdn); + slapi_entry_set_sdn(e, sdn); + } + slapi_rdn_free(&rdn); + slapi_sdn_free(&sdn); + } else { /* mod - add to mods */ slapi_mods_add_string(smods, LDAP_MOD_REPLACE, -- cgit