summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRich Megginson <rmeggins@redhat.com>2009-08-25 13:20:47 -0600
committerRich Megginson <rmeggins@redhat.com>2009-08-25 13:24:29 -0600
commit30e3822919e20cb13dfc5dabc50e7c1fe5e21d40 (patch)
tree6677a7a1a062931b63b7b0a022959198b1cca6ca
parent66aa2197b7de316f540fe924ea3435c9275a82d7 (diff)
downloadds-1.2.tar.gz
ds-1.2.tar.xz
ds-1.2.zip
Need to store additional attributes in Retro Changelog389-ds-base-1.2.21.2
https://bugzilla.redhat.com/show_bug.cgi?id=504651 Resolves: 504651 Bug Description: Need to store additional attributes in Retro Changelog Submitted by: Endi Sukma Dewata <edewata@redhat.com> Reviewed by: rmeggins (thanks!) Platforms tested: FC10 x86_64 Fix Description: The fix allows recording some user-defined attributes from the target entry of the operation (e.g. objectGUID) and built-in attributes generated by the plugin (e.g. isReplicated) into the change log entry. The attributes should be specified in the configuration entry: dn: cn=Retro Changelog Plugin,cn=plugins,cn=config ... nsslapd-attribute: objectGUID nsslapd-attribute: isReplicated The change log entry will contain the additional attributes: dn: changeNumber=...,cn=changelog ... objectGUID: ... isReplicated: ... ---
-rw-r--r--ldap/schema/01common.ldif1
-rw-r--r--ldap/schema/60changelog.ldif11
-rw-r--r--ldap/servers/plugins/retrocl/retrocl.c40
-rw-r--r--ldap/servers/plugins/retrocl/retrocl.h3
-rw-r--r--ldap/servers/plugins/retrocl/retrocl_po.c65
5 files changed, 104 insertions, 16 deletions
diff --git a/ldap/schema/01common.ldif b/ldap/schema/01common.ldif
index 01e0727d..c62a57dc 100644
--- a/ldap/schema/01common.ldif
+++ b/ldap/schema/01common.ldif
@@ -226,6 +226,7 @@ attributeTypes: ( 2.16.840.1.113730.3.1.2063 NAME 'nsEncryptionAlgorithm' DESC '
attributeTypes: ( 2.16.840.1.113730.3.1.2064 NAME 'nsSaslMapRegexString' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
attributeTypes: ( 2.16.840.1.113730.3.1.2065 NAME 'nsSaslMapBaseDNTemplate' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
attributeTypes: ( 2.16.840.1.113730.3.1.2066 NAME 'nsSaslMapFilterTemplate' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
+attributeTypes: ( 2.16.840.1.113730.3.1.2085 NAME 'isReplicated' DESC 'Changelog attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 X-ORIGIN 'Netscape Directory Server' )
#
# objectclasses:
#
diff --git a/ldap/schema/60changelog.ldif b/ldap/schema/60changelog.ldif
index 20dff136..ba3b82e9 100644
--- a/ldap/schema/60changelog.ldif
+++ b/ldap/schema/60changelog.ldif
@@ -81,6 +81,17 @@ attributeTypes: (
#
################################################################################
#
+attributeTypes: (
+ 2.16.840.1.113730.3.1.2085
+ NAME 'isReplicated'
+ DESC 'a flag which indicates whether the change was replicated'
+ EQUALITY booleanMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
+ SINGLE-VALUE
+ )
+#
+################################################################################
+#
objectClasses: (
2.16.840.1.113730.3.2.1
NAME 'changeLogEntry'
diff --git a/ldap/servers/plugins/retrocl/retrocl.c b/ldap/servers/plugins/retrocl/retrocl.c
index dd900f2b..0fb15c2f 100644
--- a/ldap/servers/plugins/retrocl/retrocl.c
+++ b/ldap/servers/plugins/retrocl/retrocl.c
@@ -76,6 +76,8 @@ void plugin_init_debug_level(int *level_ptr)
void* g_plg_identity [PLUGIN_MAX];
Slapi_Backend *retrocl_be_changelog = NULL;
+int retrocl_nattributes = 0;
+char **retrocl_attributes = NULL;
/* ----------------------------- Retrocl Plugin */
@@ -298,21 +300,39 @@ static int retrocl_start (Slapi_PBlock *pb)
{
static int retrocl_started = 0;
int rc = 0;
+ Slapi_Entry *e = NULL;
- if (!retrocl_started) {
- retrocl_rootdse_init();
+ if (retrocl_started) {
+ return rc;
+ }
+
+ retrocl_rootdse_init();
- rc = retrocl_select_backend();
+ rc = retrocl_select_backend();
- if (rc == 0) {
- retrocl_init_trimming();
- } else {
- LDAPDebug1Arg(LDAP_DEBUG_TRACE,"Couldnt find backend, not trimming retro changelog (%d).\n",rc);
- }
+ if (rc != 0) {
+ LDAPDebug1Arg(LDAP_DEBUG_TRACE,"Couldnt find backend, not trimming retro changelog (%d).\n",rc);
+ return rc;
}
+ retrocl_init_trimming();
+
+ if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e) != 0) {
+ slapi_log_error(SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Missing config entry.\n");
+ return -1;
+ }
+
+ retrocl_attributes = slapi_entry_attr_get_charray(e, "nsslapd-attribute");
+ if (retrocl_attributes != NULL) {
+ 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]);
+ }
+ }
+
retrocl_started = 1;
- return rc;
+
+ return 0;
}
/*
@@ -330,6 +350,8 @@ static int retrocl_stop (Slapi_PBlock *pb)
{
int rc = 0;
+ slapi_ch_array_free(retrocl_attributes);
+
retrocl_stop_trimming();
retrocl_be_changelog = NULL;
retrocl_forget_changenumbers();
diff --git a/ldap/servers/plugins/retrocl/retrocl.h b/ldap/servers/plugins/retrocl/retrocl.h
index e7b65c62..5c0cad1c 100644
--- a/ldap/servers/plugins/retrocl/retrocl.h
+++ b/ldap/servers/plugins/retrocl/retrocl.h
@@ -113,6 +113,8 @@ enum {
extern void* g_plg_identity [PLUGIN_MAX];
extern Slapi_Backend *retrocl_be_changelog;
+extern int retrocl_nattributes;
+extern char** retrocl_attributes;
extern const char *attr_changenumber;
extern const char *attr_targetdn;
@@ -123,6 +125,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_isreplicated;
extern PRLock *retrocl_internal_lock;
diff --git a/ldap/servers/plugins/retrocl/retrocl_po.c b/ldap/servers/plugins/retrocl/retrocl_po.c
index a29fefbe..93c67769 100644
--- a/ldap/servers/plugins/retrocl/retrocl_po.c
+++ b/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_isreplicated = "isreplicated";
/*
* Function: make_changes_string
@@ -154,6 +155,7 @@ static lenstr *make_changes_string(LDAPMod **ldm, const char **includeattrs)
*/
static void
write_replog_db(
+ Slapi_PBlock *pb,
int optype,
char *dn,
LDAPMod **log_m,
@@ -171,8 +173,9 @@ write_replog_db(
Slapi_Entry *e;
char chnobuf[ 20 ];
int err;
- Slapi_PBlock *pb = NULL;
+ Slapi_PBlock *newPb = NULL;
changeNumber changenum;
+ int i;
PR_Lock(retrocl_internal_lock);
changenum = retrocl_assign_changenumber();
@@ -204,6 +207,54 @@ 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];
+
+ 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";
+
+ val.bv_val = attributeValue;
+ val.bv_len = strlen( attributeValue );
+
+ slapi_entry_add_values( e, attributeName, vals );
+
+ } else {
+ Slapi_Entry *entry = NULL;
+ Slapi_ValueSet *valueSet = NULL;
+ int type_name_disposition = 0;
+ char *actual_type_name = NULL;
+ int flags = 0;
+ int buffer_flags = 0;
+
+ slapi_pblock_get( pb, SLAPI_ENTRY_POST_OP, &entry );
+ if ( entry != NULL ) {
+ slapi_vattr_values_get( entry, attributeName, &valueSet,
+ &type_name_disposition, &actual_type_name, flags, &buffer_flags );
+ }
+
+ if ( valueSet == NULL ) {
+ slapi_pblock_get( pb, SLAPI_ENTRY_PRE_OP, &entry );
+ if ( entry != NULL ) {
+ slapi_vattr_values_get( entry, attributeName, &valueSet,
+ &type_name_disposition, &actual_type_name, flags, &buffer_flags );
+ }
+ }
+
+ if ( valueSet == NULL ) continue;
+
+ slapi_entry_add_valueset( e, attributeName, valueSet );
+ slapi_vattr_values_free( &valueSet, &actual_type_name, buffer_flags );
+ }
+ }
+
/* Set the changeNumber attribute */
sprintf( chnobuf, "%lu", changenum );
val.bv_val = chnobuf;
@@ -261,13 +312,13 @@ write_replog_db(
if ( 0 == err ) {
int rc;
- pb = slapi_pblock_new ();
- slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */,
+ newPb = slapi_pblock_new ();
+ slapi_add_entry_internal_set_pb( newPb, e, NULL /* controls */,
g_plg_identity[PLUGIN_RETROCL],
0 /* actions */ );
- slapi_add_internal_pb (pb);
- slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
- slapi_pblock_destroy(pb);
+ slapi_add_internal_pb (newPb);
+ slapi_pblock_get( newPb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
+ slapi_pblock_destroy(newPb);
if ( 0 != rc ) {
slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
"replog: an error occured while adding change "
@@ -552,7 +603,7 @@ int retrocl_postob (Slapi_PBlock *pb,int optype)
/* check if we should log change to retro changelog, and
* if so, do it here */
- write_replog_db( optype, dn, log_m, flag, curtime, te,
+ write_replog_db( pb, optype, dn, log_m, flag, curtime, te,
newrdn, modrdn_mods, newsuperior );
return 0;