[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fedora-directory-commits
Subject:    [389-commits] ldap/servers
From:       Mark Reynolds <mreynolds () fedoraproject ! org>
Date:       2012-10-19 20:58:51
Message-ID: 20121019205851.BC73722C0 () hosted02 ! fedoraproject ! org
[Download RAW message or body]

 ldap/servers/plugins/dna/dna.c     |    4 ++
 ldap/servers/slapd/add.c           |   63 ++++++++++++++++++++++++++++++++-----
 ldap/servers/slapd/configdse.c     |    1 
 ldap/servers/slapd/opshared.c      |   15 +++++---
 ldap/servers/slapd/proto-slap.h    |    1 
 ldap/servers/slapd/slapi-private.h |    6 +++
 6 files changed, 76 insertions(+), 14 deletions(-)

New commits:
commit f33e73fe45225c0c7413d74dc846cead3214a404
Author: Mark Reynolds <mreynolds@redhat.com>
Date:   Fri Oct 19 15:55:54 2012 -0400

    Ticket 495 - internalModifiersname not updated by DNA plugin
    
    Bug Description:  If you are using the "nsslapd-plugin-binddn-tracking", and the DNA plugin
                      modifiers the entry, the internalmodifiersname is not updated.
    
    Fix Description:  This is because the DNA plugin directly modifies the entry, and does not
                      use the internal modify functions that would trigger the last mod attributes
                      to be updated.  So we have to call the last mod update function directly from
                      the dna plugin.
    
                      There is also a slight change to the behavior now.  The internalModifiersname &
                      internalCreatorsname will never be the bind dn, but instead it will be the plugin
                      that actually did the update.  So if a entry was not touched by a DS plugin, then
                      the "database" plugin would be the internal modifier/creator:
    
                                    cn=ldbm database,cn=plugins,cn=config
    
                      This would also allow us to detect if someone replaced the default backend.
    
    https://fedorahosted.org/389/ticket/495
    
    Reviewed by: nhosoi & richm(Thanks!)

diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index 34d67ab..2b56967 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -2853,6 +2853,8 @@ _dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e)
                                                  /* no need to dup */
                                                  DNA_NEEDS_UPDATE);
                 }
+                /* Update the internalModifiersname for this add op */
+                add_internal_modifiersname(pb, e);
 
                 /* Make sure we don't generate for this
                  * type again by keeping a list of types
@@ -3106,6 +3108,8 @@ _dna_pre_op_modify(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Mods *smods)
                                           /* no need to dup */
                                           DNA_NEEDS_UPDATE); 
                 }
+                /* Update the internalModifersname for this mod op */
+                modify_update_last_modified_attr(pb, smods);
 
                 /* Make sure we don't generate for this
                  * type again by keeping a list of types
diff --git a/ldap/servers/slapd/add.c b/ldap/servers/slapd/add.c
index d1d23b3..2a70f64 100644
--- a/ldap/servers/slapd/add.c
+++ b/ldap/servers/slapd/add.c
@@ -73,7 +73,7 @@
 /* Forward declarations */
 static int add_internal_pb (Slapi_PBlock *pb);
 static void op_shared_add (Slapi_PBlock *pb);
-static int add_created_attrs(Operation *op, Slapi_Entry *e);
+static int add_created_attrs(Slapi_PBlock *pb, Slapi_Entry *e);
 static int check_rdn_for_created_attrs(Slapi_Entry *e);
 static void handle_fast_add(Slapi_PBlock *pb, Slapi_Entry *entry);
 static int add_uniqueid (Slapi_Entry *e);
@@ -684,7 +684,7 @@ static void op_shared_add (Slapi_PBlock *pb)
 		/* can get lastmod only after backend is selected */
 		slapi_pblock_get(pb, SLAPI_BE_LASTMOD, &lastmod);
 
-		if (lastmod && add_created_attrs(operation, e) != 0)
+		if (lastmod && add_created_attrs(pb, e) != 0)
 		{
 			send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
 				"cannot insert computed attributes", 0, NULL);
@@ -797,32 +797,51 @@ done:
 }
 
 static int 
-add_created_attrs(Operation *op, Slapi_Entry *e)
+add_created_attrs(Slapi_PBlock *pb, Slapi_Entry *e)
 {
 	char   buf[20];
 	char   *binddn = NULL;
+	char   *plugin_dn = NULL;
 	struct berval	bv;
 	struct berval	*bvals[2];
 	time_t		curtime;
 	struct tm	ltm;
+	Operation *op;
+	struct slapdplugin *plugin = NULL;
+	struct slapi_componentid *cid = NULL;
 	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 
 	LDAPDebug(LDAP_DEBUG_TRACE, "add_created_attrs\n", 0, 0, 0);
 
 	bvals[0] = &bv;
 	bvals[1] = NULL;
+	slapi_pblock_get(pb, SLAPI_OPERATION, &op);
 	
 	if(slapdFrontendConfig->plugin_track){
 		/* plugin bindDN tracking is enabled, grab the dn from thread local storage */
 		if(slapi_sdn_isempty(&op->o_sdn)){
 			bv.bv_val = "";
-			bv.bv_len = strlen(bv.bv_val);
+			bv.bv_len = 0;
 		} else {
-			bv.bv_val = (char*)slapi_sdn_get_dn(&op->o_sdn);
-			bv.bv_len = strlen(bv.bv_val);
+			slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &cid);
+			if (cid){
+				plugin=(struct slapdplugin *) cid->sci_plugin;
+			} else {
+				slapi_pblock_get (pb, SLAPI_PLUGIN, &plugin);
+			}
+			if(plugin)
+				plugin_dn = plugin_get_dn (plugin);
+			if(plugin_dn){
+				bv.bv_val = plugin_dn;
+				bv.bv_len = strlen(bv.bv_val);
+			} else {
+				bv.bv_val = (char*)slapi_sdn_get_dn(&op->o_sdn);
+				bv.bv_len = strlen(bv.bv_val);
+			}
 		}
 		slapi_entry_attr_replace(e, "internalCreatorsName", bvals);
 		slapi_entry_attr_replace(e, "internalModifiersName", bvals);
+		slapi_ch_free_string(&plugin_dn);
 
 		/* Grab the thread data(binddn) */
 		slapi_td_get_dn(&binddn);
@@ -830,7 +849,7 @@ add_created_attrs(Operation *op, Slapi_Entry *e)
 		if(binddn == NULL){
 			/* anonymous bind */
 			bv.bv_val = "";
-			bv.bv_len = strlen(bv.bv_val);
+			bv.bv_len = 0;
 		} else {
 			bv.bv_val = binddn;
 			bv.bv_len = strlen(bv.bv_val);
@@ -838,7 +857,7 @@ add_created_attrs(Operation *op, Slapi_Entry *e)
 	} else {
 		if (slapi_sdn_isempty(&op->o_sdn)) {
 			bv.bv_val = "";
-			bv.bv_len = strlen(bv.bv_val);
+			bv.bv_len = 0;
 		} else {
 			bv.bv_val = (char*)slapi_sdn_get_dn(&op->o_sdn);
 			bv.bv_len = strlen(bv.bv_val);
@@ -1023,3 +1042,31 @@ check_oc_subentry(Slapi_Entry *e, struct berval	**vals, char *normtype) {
   }
   return subentry;
 }
+
+/*
+ *  Used by plugins that modify entries on add operations, otherwise the internalModifiersname
+ *  would not be set the the correct plugin name.
+ */
+void
+add_internal_modifiersname(Slapi_PBlock *pb, Slapi_Entry *e)
+{
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+    struct slapi_componentid *cid = NULL;
+    struct slapdplugin *plugin = NULL;
+    char *plugin_dn = NULL;
+
+    if(slapdFrontendConfig->plugin_track){
+        slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &cid);
+        if (cid){
+            plugin=(struct slapdplugin *) cid->sci_plugin;
+        } else {
+            slapi_pblock_get (pb, SLAPI_PLUGIN, &plugin);
+        }
+        if(plugin)
+            plugin_dn = plugin_get_dn (plugin);
+        if(plugin_dn){
+            slapi_entry_attr_set_charptr(e, "internalModifiersname", plugin_dn);
+            slapi_ch_free_string(&plugin_dn);
+        }
+    }
+}
diff --git a/ldap/servers/slapd/configdse.c b/ldap/servers/slapd/configdse.c
index 51f9165..b54062d 100644
--- a/ldap/servers/slapd/configdse.c
+++ b/ldap/servers/slapd/configdse.c
@@ -117,6 +117,7 @@ ignore_attr_type(const char *attr_type)
 		 (strcasecmp (attr_type, "objectclass") == 0) ||
 		 (strcasecmp (attr_type, "numsubordinates") == 0) ||
 		 (strcasecmp (attr_type, "internalModifiersname") == 0) ||
+		 (strcasecmp (attr_type, "internalCreatorsname") == 0) ||
 		 (strcasecmp (attr_type, "modifytimestamp") == 0) ||
 		 (strcasecmp (attr_type, "modifiersname") == 0)) {
 		return 1;
diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c
index 019fe20..afd81ac 100644
--- a/ldap/servers/slapd/opshared.c
+++ b/ldap/servers/slapd/opshared.c
@@ -135,7 +135,8 @@ do_ps_service(Slapi_Entry *e, Slapi_Entry *eprev, ber_int_t chgtype, ber_int_t c
     (ps_service_fn)(e, eprev, chgtype, chgnum);
 }
 
-void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods)
+void
+modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods)
 {
     char        buf[20];
     char        *plugin_dn = NULL;
@@ -159,11 +160,14 @@ void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods)
         /* plugin bindDN tracking is enabled, grab the bind dn from thread local storage */
         if(slapi_sdn_isempty(&op->o_sdn)){
             bv.bv_val = "";
-            bv.bv_len = strlen(bv.bv_val);
+            bv.bv_len = 0;
         } else {
             slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &cid);
-            if (cid)
+            if (cid){
                 plugin=(struct slapdplugin *) cid->sci_plugin;
+            } else {
+                slapi_pblock_get (pb, SLAPI_PLUGIN, &plugin);
+            }
             if(plugin)
                 plugin_dn = plugin_get_dn (plugin);
             if(plugin_dn){
@@ -176,6 +180,7 @@ void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods)
         }
         slapi_mods_add_modbvps(smods, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES,
                                   "internalModifiersName", bvals);
+        slapi_ch_free_string(&plugin_dn);
 
         /* Grab the thread data(binddn) */
         slapi_td_get_dn(&binddn);
@@ -183,7 +188,7 @@ void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods)
         if(binddn == NULL){
             /* anonymous bind */
             bv.bv_val = "";
-            bv.bv_len = strlen(bv.bv_val);
+            bv.bv_len = 0;
    	    } else {
             bv.bv_val = binddn;
             bv.bv_len = strlen(bv.bv_val);
@@ -192,7 +197,7 @@ void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods)
         /* fill in modifiersname */
         if (slapi_sdn_isempty(&op->o_sdn)) {
             bv.bv_val = "";
-            bv.bv_len = strlen(bv.bv_val);
+            bv.bv_len = 0;
         } else {
             bv.bv_val = (char*)slapi_sdn_get_dn(&op->o_sdn);
             bv.bv_len = strlen(bv.bv_val);
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
index 905b0f4..19c06a2 100644
--- a/ldap/servers/slapd/proto-slap.h
+++ b/ldap/servers/slapd/proto-slap.h
@@ -1290,7 +1290,6 @@ void set_config_params (Slapi_PBlock *pb);
 /* set parameters common for all internal operations */
 void set_common_params (Slapi_PBlock *pb);
 void do_ps_service(Slapi_Entry *e, Slapi_Entry *eprev, ber_int_t chgtype, ber_int_t chgnum);
-void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods);
 
 /*
  * debugdump.cpp
diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h
index 6c2781c..3ee1755 100644
--- a/ldap/servers/slapd/slapi-private.h
+++ b/ldap/servers/slapd/slapi-private.h
@@ -1252,6 +1252,12 @@ int slapi_add_internal_attr_syntax( const char *name, const char *oid, const cha
 void pw_exp_init ( void );
 int pw_copy_entry_ext(Slapi_Entry *src_e, Slapi_Entry *dest_e);
 
+/* op_shared.c */
+void modify_update_last_modified_attr(Slapi_PBlock *pb, Slapi_Mods *smods);
+
+/* add.c */
+void add_internal_modifiersname(Slapi_PBlock *pb, Slapi_Entry *e);
+
 #ifdef __cplusplus
 }
 #endif


--
389 commits mailing list
389-commits@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/389-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic