[Freeipa-devel] [PATCHES] Address #413 and Complete UUID related changes

2010-10-27 Thread Simo Sorce

These patches apply on top of the previous ipa_uuid related patches.

#1 handles automatic generation of the uuid when the uuid
attribute is the RDN (fixes #413).

#2 prevents cases of false positives when enforcing is set and we are
handling a simple modification of an object that falls into the plugin
scope.

#3 remove the python uuid plugin and changes all callers to always pass
in the special value 'autogenerate' for the ipauniqueid attribute. This
way uuids are generated server side.


#3 introduces a problem with the baseldap class LDAPCreate, because
that calss always tries to reuse the passed in DN to lookup the entry
after creation. Unfortunately when ipaUniqueID is part of the DN, the
DN is changed on add so the lookup using the special autogenerate
value will fail. Pavel is looking into it to provide an alternative way
to lookup the entry in these cases.

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York
From c6aa13c14280cc36fb3ad443b2f584d488d2fe53 Mon Sep 17 00:00:00 2001
From: Simo Sorce sso...@redhat.com
Date: Tue, 26 Oct 2010 11:29:53 -0400
Subject: [PATCH 1/3] ipa_uuid: Handle generation of the uuid when it is a RDN

---
 daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c |   60 
 1 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c b/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c
index eb5b40d..c0fde90 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,
-- 
1.7.2.3

From 

Re: [Freeipa-devel] [PATCHES] Address #413 and Complete UUID related changes

2010-10-27 Thread Rob Crittenden

Simo Sorce wrote:


These patches apply on top of the previous ipa_uuid related patches.

#1 handles automatic generation of the uuid when the uuid
attribute is the RDN (fixes #413).

#2 prevents cases of false positives when enforcing is set and we are
handling a simple modification of an object that falls into the plugin
scope.

#3 remove the python uuid plugin and changes all callers to always pass
in the special value 'autogenerate' for the ipauniqueid attribute. This
way uuids are generated server side.


#3 introduces a problem with the baseldap class LDAPCreate, because
that calss always tries to reuse the passed in DN to lookup the entry
after creation. Unfortunately when ipaUniqueID is part of the DN, the
DN is changed on add so the lookup using the special autogenerate
value will fail. Pavel is looking into it to provide an alternative way
to lookup the entry in these cases.

Simo.


There is one minor problem in the 3rd patch. The admin user has the 
wrong magic value for ipauniqueid. Fix that and you have a pre-ack x3.


rob

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel