فهرست منبع

Bug 553027 - Support for nsUniqueId and alias in Retro Changelog.

This patch adds support for storing the target's nsUniqueId in change log record and renaming any additional attribute using an alias.
Endi S. Dewata 16 سال پیش
والد
کامیت
9f88491132
3فایلهای تغییر یافته به همراه93 افزوده شده و 11 حذف شده
  1. 44 4
      ldap/servers/plugins/retrocl/retrocl.c
  2. 2 0
      ldap/servers/plugins/retrocl/retrocl.h
  3. 47 7
      ldap/servers/plugins/retrocl/retrocl_po.c

+ 44 - 4
ldap/servers/plugins/retrocl/retrocl.c

@@ -79,6 +79,7 @@ Slapi_Backend *retrocl_be_changelog = NULL;
 PRLock *retrocl_internal_lock = NULL;
 int retrocl_nattributes = 0;
 char **retrocl_attributes = NULL;
+char **retrocl_aliases = NULL;
 
 /* ----------------------------- Retrocl Plugin */
 
@@ -302,6 +303,7 @@ static int retrocl_start (Slapi_PBlock *pb)
     static int retrocl_started = 0;
     int rc = 0;
     Slapi_Entry *e = NULL;
+    char **values = NULL;
 
     if (retrocl_started) {
       return rc;
@@ -323,12 +325,49 @@ static int retrocl_start (Slapi_PBlock *pb)
         return -1;
     }
 
-    retrocl_attributes = slapi_entry_attr_get_charray(e, "nsslapd-attribute");
-    if (retrocl_attributes != NULL) {
+    values = slapi_entry_attr_get_charray(e, "nsslapd-attribute");
+    if (values != NULL) {
+        int n = 0;
+        int i = 0;
+
+        slapi_log_error(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "nsslapd-attribute:\n");
+
+        for (n=0; values && values[n]; n++) {
+            slapi_log_error(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, " - %s\n", values[n]);
+        }
+
+        retrocl_nattributes = n;
+
+        retrocl_attributes = (char **)slapi_ch_calloc(n, sizeof(char *));
+        retrocl_aliases = (char **)slapi_ch_calloc(n, sizeof(char *));
+
         slapi_log_error(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "Attributes:\n");
-        for (retrocl_nattributes=0; retrocl_attributes && retrocl_attributes[retrocl_nattributes]; retrocl_nattributes++) {
-            slapi_log_error(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, " - %s\n", retrocl_attributes[retrocl_nattributes]);
+
+        for (i=0; i<n; i++) {
+            char *value = values[i];
+            size_t length = strlen(value);
+
+            char *pos = strchr(value, ':');
+            if (pos == NULL) {
+                retrocl_attributes[i] = slapi_ch_strdup(value);
+                retrocl_aliases[i] = NULL;
+
+                slapi_log_error(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, " - %s\n",
+                    retrocl_attributes[i]);
+
+            } else {
+                retrocl_attributes[i] = slapi_ch_malloc(pos-value+1);
+                strncpy(retrocl_attributes[i], value, pos-value);
+
+                retrocl_aliases[i] = slapi_ch_malloc(value+length-pos);
+                strcpy(retrocl_aliases[i], pos+1);
+
+                slapi_log_error(SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, " - %s [%s]\n",
+                    retrocl_attributes[i], retrocl_aliases[i]);
+            }
         }
+
+        slapi_ch_array_free(values);
     }
 
     retrocl_started = 1;
@@ -352,6 +391,7 @@ static int retrocl_stop (Slapi_PBlock *pb)
   int rc = 0;
 
   slapi_ch_array_free(retrocl_attributes);
+  slapi_ch_array_free(retrocl_aliases);
 
   retrocl_stop_trimming();  
   retrocl_be_changelog = NULL;

+ 2 - 0
ldap/servers/plugins/retrocl/retrocl.h

@@ -115,6 +115,7 @@ extern void* g_plg_identity [PLUGIN_MAX];
 extern Slapi_Backend *retrocl_be_changelog;
 extern int retrocl_nattributes;
 extern char** retrocl_attributes;
+extern char** retrocl_aliases;
 
 extern const char *attr_changenumber;
 extern const char *attr_targetdn;
@@ -125,6 +126,7 @@ extern const char *attr_deleteoldrdn;
 extern const char *attr_changes;
 extern const char *attr_changetime;
 extern const char *attr_objectclass;
+extern const char *attr_nsuniqueid;
 extern const char *attr_isreplicated;
 
 extern PRLock *retrocl_internal_lock;

+ 47 - 7
ldap/servers/plugins/retrocl/retrocl_po.c

@@ -64,6 +64,7 @@ const char *attr_changes = "changes";
 const char *attr_newsuperior = "newsuperior";
 const char *attr_changetime = "changetime";
 const char *attr_objectclass = "objectclass";
+const char *attr_nsuniqueid = "nsuniqueid";
 const char *attr_isreplicated = "isreplicated";
 
 /*
@@ -176,6 +177,7 @@ write_replog_db(
     Slapi_PBlock	*newPb = NULL;
     changeNumber changenum;
     int			i;
+    int			extensibleObject = 0;
 
     PR_Lock(retrocl_internal_lock);
     changenum = retrocl_assign_changenumber();
@@ -207,24 +209,51 @@ write_replog_db(
     val.bv_len = 14;
     slapi_entry_add_values( e, "objectclass", vals );
 
-    val.bv_val = "extensibleObject";
-    val.bv_len = 16;
-    slapi_entry_add_values( e, "objectclass", vals );
-
     for ( i=0; i<retrocl_nattributes; i++ ) {
         char* attributeName = retrocl_attributes[i];
+        char* attributeAlias = retrocl_aliases[i];
+
+        if ( attributeAlias == NULL ) {
+            attributeAlias = attributeName;
+        }
+
+        if ( strcasecmp( attributeName, attr_nsuniqueid ) == 0 ) {
+            Slapi_Entry *entry = NULL;
+            char *uniqueId = NULL;
+
+            slapi_pblock_get( pb, SLAPI_ENTRY_POST_OP, &entry );
+            if ( entry == NULL ) {
+                slapi_pblock_get( pb, SLAPI_ENTRY_PRE_OP, &entry );
+            }
+
+            uniqueId = slapi_entry_get_uniqueid( entry );
 
-        if ( strcasecmp( attributeName, attr_isreplicated ) == 0 ) {
+            slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
+	        "write_replog_db: add %s: \"%s\"\n", attributeAlias, uniqueId );
+
+            val.bv_val = uniqueId;
+            val.bv_len = strlen( uniqueId );
+
+            slapi_entry_add_values( e, attributeAlias, vals );
+
+            extensibleObject = 1;
+
+        } else if ( strcasecmp( attributeName, attr_isreplicated ) == 0 ) {
             int isReplicated = 0;
             char *attributeValue = NULL;
 
             slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isReplicated );
             attributeValue = isReplicated ? "TRUE" : "FALSE";
 
+            slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
+	        "write_replog_db: add %s: \"%s\"\n", attributeAlias, attributeValue );
+
             val.bv_val = attributeValue;
             val.bv_len = strlen( attributeValue );
 
-            slapi_entry_add_values( e, attributeName, vals );
+            slapi_entry_add_values( e, attributeAlias, vals );
+
+            extensibleObject = 1;
 
         } else {
             Slapi_Entry *entry = NULL;
@@ -250,11 +279,22 @@ write_replog_db(
 
             if ( valueSet == NULL ) continue;
 
-            slapi_entry_add_valueset( e, attributeName, valueSet );
+            slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
+	        "write_replog_db: add %s\n", attributeAlias );
+
+            slapi_entry_add_valueset( e, attributeAlias, valueSet );
             slapi_vattr_values_free( &valueSet, &actual_type_name, buffer_flags );
+
+            extensibleObject = 1;
         }
     }
 
+    if ( extensibleObject ) {
+        val.bv_val = "extensibleObject";
+        val.bv_len = 16;
+        slapi_entry_add_values( e, "objectclass", vals );
+    }
+
     /* Set the changeNumber attribute */
     sprintf( chnobuf, "%lu", changenum );
     val.bv_val = chnobuf;