summaryrefslogtreecommitdiffstats
path: root/ldap/servers/slapd/plugin.c
diff options
context:
space:
mode:
authorNoriko Hosoi <nhosoi@redhat.com>2009-08-31 08:51:03 -0700
committerNoriko Hosoi <nhosoi@redhat.com>2009-08-31 08:51:03 -0700
commit6b08e5b7953dd87e6f4ad92df04d93e670d6d052 (patch)
treed9f2c59760b0ebc7c549372cf9911a21393430f8 /ldap/servers/slapd/plugin.c
parent177f772ec3d596028eb2a633f3ed360186df42fc (diff)
downloadds-6b08e5b7953dd87e6f4ad92df04d93e670d6d052.tar.gz
ds-6b08e5b7953dd87e6f4ad92df04d93e670d6d052.tar.xz
ds-6b08e5b7953dd87e6f4ad92df04d93e670d6d052.zip
Plugin Default Config Entry
Design doc: http://directory.fedoraproject.org/wiki/Entry_USN#Plugin_Default_Config_Entr New slapi APIs in libslapd: int slapi_set_plugin_default_config(const char *type, Slapi_Value *value); Description: Add given "type: value" to the plugin default config entry (cn=plugin default config,cn=config) unless the same "type: value" pair already exists in the entry. Parameters: type - Attribute type to add to the default config entry value - Attribute value to add to the default config entry Return Value: 0 if the operation was successful non-0 if the operation was not successful int slapi_get_plugin_default_config(char *type, Slapi_ValueSet **valueset); Description: Get attribute values of given type from the plugin default config entry (cn=plugin default config,cn=config). Parameters: type - Attribute type to get from the default config entry valueset - Valueset holding the attribute values Return Value: 0 if the operation was successful non-0 if the operation was not successful warning: Caller is responsible to free attrs by slapi_ch_array_free Changes in the Replication plugin: 1) Functions to set replicated attributes agmt_set_replicated_attributes_from_attr and agmt_set_replicated_attributes_from_entry call _agmt_set_default_fractional_attrs to sets the default excluded attribute list from the plugin default config entry before setting them from each replication agreement. To support it, agmt_parse_excluded_attrs_config_attr is changed to be re-entrant. 2) Fixed a minor memory leak in the fractional attributes (ra->frac_attrs). 3) Added a check for the duplicated fractional attributes. Changes in the USN plugin: 1) usn_start calls slapi_set_plugin_default_config to add "entryusn" to the EXCLUDE list of the value of nsds5ReplicatedAttributeList in the plugin default config entry. 2) fix for the bug 518673 - entryusn: wrong lastusn value; When the entryusn is not assigned yet, the next value to be set is 0. Lastusn is calculate as (the next entryusn - 1). Although the entryusn is 64-bit unsigned long, it should be printed as a 64-bit signed integer for lastusn. Other: Fixed a compiler error in ldap/servers/slapd/dse.c.
Diffstat (limited to 'ldap/servers/slapd/plugin.c')
-rw-r--r--ldap/servers/slapd/plugin.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
index e5e016d3..75ec4f92 100644
--- a/ldap/servers/slapd/plugin.c
+++ b/ldap/servers/slapd/plugin.c
@@ -2837,3 +2837,159 @@ bail:
return rc;
}
+
+/*
+ * Set given "type: attr" to the plugin default config entry
+ * (cn=plugin default config,cn=config) unless the same "type: attr" pair
+ * already exists in the entry.
+ */
+int
+slapi_set_plugin_default_config(const char *type, Slapi_Value *value)
+{
+ Slapi_PBlock pb;
+ Slapi_Entry **entries = NULL;
+ int rc = LDAP_SUCCESS;
+ char **search_attrs = NULL; /* used by search */
+
+ if (NULL == type || '\0' == *type || NULL == value ) { /* nothing to do */
+ return rc;
+ }
+
+ charray_add(&search_attrs, slapi_ch_strdup(type));
+
+ /* cn=plugin default config,cn=config */
+ pblock_init(&pb);
+ slapi_search_internal_set_pb(&pb,
+ SLAPI_PLUGIN_DEFAULT_CONFIG, /* Base DN */
+ LDAP_SCOPE_BASE,
+ "(objectclass=*)",
+ search_attrs, /* Attrs */
+ 0, /* AttrOnly */
+ NULL, /* Controls */
+ NULL, /* UniqueID */
+ (void *)plugin_get_default_component_id(),
+ 0);
+ slapi_search_internal_pb(&pb);
+ slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
+ slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
+ if (LDAP_SUCCESS == rc && entries && *entries) {
+ /* plugin default config entry exists */
+ int exists = 0;
+ Slapi_Attr *attr = NULL;
+ rc = slapi_entry_attr_find(*entries, type, &attr);
+
+ if (0 == rc) { /* type exists in the entry */
+ if (0 ==
+ slapi_attr_value_find(attr, slapi_value_get_berval(value))) {
+ /* value exists in the entry; we don't have to do anything. */
+ exists = 1;
+ }
+ }
+ slapi_free_search_results_internal(&pb);
+ pblock_done(&pb);
+
+ if (!exists) {
+ /* The argument attr is not in the plugin default config.
+ * Let's add it. */
+ Slapi_Mods smods;
+ Slapi_Value *va[2];
+
+ va[0] = value;
+ va[1] = NULL;
+ slapi_mods_init(&smods, 1);
+ slapi_mods_add_mod_values(&smods, LDAP_MOD_ADD, type, va);
+
+ pblock_init(&pb);
+ slapi_modify_internal_set_pb(&pb, SLAPI_PLUGIN_DEFAULT_CONFIG,
+ slapi_mods_get_ldapmods_byref(&smods),
+ NULL, NULL, /* UniqueID */
+ (void *)plugin_get_default_component_id(),
+ 0 /* Flags */ );
+ slapi_modify_internal_pb(&pb);
+ slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
+ slapi_mods_done(&smods);
+ pblock_done(&pb);
+ }
+ } else { /* cn=plugin default config does not exist. Let's add it. */
+ Slapi_Mods smods;
+ Slapi_Value *va[2];
+
+ slapi_free_search_results_internal(&pb);
+ pblock_done(&pb);
+
+ va[0] = value;
+ va[1] = NULL;
+ slapi_mods_init(&smods, 1);
+
+ slapi_mods_add_string(&smods, LDAP_MOD_ADD, "objectClass", "top");
+ slapi_mods_add_string(&smods, LDAP_MOD_ADD, "objectClass",
+ "extensibleObject");
+ slapi_mods_add_mod_values(&smods, LDAP_MOD_ADD, type, va);
+
+ pblock_init(&pb);
+ slapi_add_internal_set_pb(&pb, SLAPI_PLUGIN_DEFAULT_CONFIG,
+ slapi_mods_get_ldapmods_byref(&smods), NULL,
+ (void *)plugin_get_default_component_id(),
+ 0 /* Flags */ );
+ slapi_add_internal_pb(&pb);
+ slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
+ slapi_mods_done(&smods);
+ pblock_done(&pb);
+ }
+ charray_free(search_attrs);
+
+ return rc;
+}
+
+/*
+ * Get attribute values of given type from the plugin default config entry
+ * (cn=plugin default config,cn=config).
+ *
+ * Caller is responsible to free attrs by slapi_valueset_free.
+ */
+int
+slapi_get_plugin_default_config(char *type, Slapi_ValueSet **valueset)
+{
+ Slapi_PBlock pb;
+ Slapi_Entry **entries = NULL;
+ int rc = LDAP_PARAM_ERROR;
+ char **search_attrs = NULL; /* used by search */
+
+ if (NULL == type || '\0' == *type || NULL == valueset) { /* nothing to do */
+ return rc;
+ }
+
+ charray_add(&search_attrs, slapi_ch_strdup(type));
+
+ /* cn=plugin default config,cn=config */
+ pblock_init(&pb);
+ slapi_search_internal_set_pb(&pb,
+ SLAPI_PLUGIN_DEFAULT_CONFIG, /* Base DN */
+ LDAP_SCOPE_BASE,
+ "(objectclass=*)",
+ search_attrs, /* Attrs */
+ 0, /* AttrOnly */
+ NULL, /* Controls */
+ NULL, /* UniqueID */
+ (void *)plugin_get_default_component_id(),
+ 0);
+ slapi_search_internal_pb(&pb);
+ slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
+ slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
+ if (LDAP_SUCCESS == rc && entries && *entries) {
+ /* default config entry exists */
+ /* retrieve attribute values from the entry */
+ Slapi_Attr *attr = NULL;
+ rc = slapi_entry_attr_find(*entries, type, &attr);
+ if (0 == rc) { /* type value exists */
+ rc = slapi_attr_get_valueset(attr, valueset);
+ } else {
+ rc = LDAP_NO_SUCH_ATTRIBUTE;
+ }
+ }
+ slapi_free_search_results_internal(&pb);
+ pblock_done(&pb);
+ charray_free(search_attrs);
+
+ return rc;
+}