diff options
author | Rich Megginson <rmeggins@redhat.com> | 2005-03-11 03:47:36 +0000 |
---|---|---|
committer | Rich Megginson <rmeggins@redhat.com> | 2005-03-11 03:47:36 +0000 |
commit | 9667f84c94b16d51743bea68df24aeee57bf6f82 (patch) | |
tree | 3e4ac798dc26f0fb3c7883c88d83c5e254f08384 /ldap/servers/slapd/backend_manager.c | |
parent | 5a9fd42bc4bfc2ca4a4fad2f10881ea16cf504ea (diff) | |
download | ds-9667f84c94b16d51743bea68df24aeee57bf6f82.tar.gz ds-9667f84c94b16d51743bea68df24aeee57bf6f82.tar.xz ds-9667f84c94b16d51743bea68df24aeee57bf6f82.zip |
This one is mostly strcpy/strcat checking, checking for null strings before strlen, removing some dead code, other odds and ends.
Diffstat (limited to 'ldap/servers/slapd/backend_manager.c')
-rw-r--r-- | ldap/servers/slapd/backend_manager.c | 255 |
1 files changed, 2 insertions, 253 deletions
diff --git a/ldap/servers/slapd/backend_manager.c b/ldap/servers/slapd/backend_manager.c index 842d2a55..e7a085d9 100644 --- a/ldap/servers/slapd/backend_manager.c +++ b/ldap/servers/slapd/backend_manager.c @@ -379,259 +379,6 @@ be_nbackends_public() #define SUFFIX_ATTR "nsslapd-suffix" #define CACHE_ATTR "nsslapd-cachememsize" -/* add nsslapd-instance attribute to cn=config,cn=ldbm database,cn=plugins,cn=config - entry. This causes empty backend instance creation */ -/* JCM - Should be adding an instance entry, not an attr value */ -static int -be_add_instance (const char *name, void *plugin_identity) -{ - Slapi_PBlock pb; - Slapi_Mods smods; - int rc; - - PR_ASSERT (name && plugin_identity); - - slapi_mods_init (&smods, 1); - slapi_mods_add(&smods, LDAP_MOD_ADD, INSTANCE_ATTR, strlen (name), name); - - pblock_init (&pb); - slapi_modify_internal_set_pb (&pb, LDBM_CONFIG_ENTRY, - slapi_mods_get_ldapmods_byref(&smods), NULL, - NULL, plugin_identity, 0); - slapi_modify_internal_pb (&pb); - slapi_mods_done (&smods); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT,&rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to modify ldbm configuration entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - - pblock_done(&pb); - return 0; -} - -static char* -be_get_instance_dn (const char *index_name, const char *name) -{ - char *dn; - - PR_ASSERT (name); - - if (index_name) { - dn = slapi_ch_smprintf("cn=%s,cn=index,cn=config,cn=%s,%s", index_name, name, - LDBM_CLASS_PREFIX); - } else { - dn = slapi_ch_smprintf("cn=config,cn=%s,%s", name, LDBM_CLASS_PREFIX); - } - - return dn; -} - - -/* configure newly added backend by modifying instance's configuration entry: - cn=config,cn=<instance name>,cn=ldbm database,cn=plugins,cn=config. - Can configure backend root and cache size */ -static int -be_configure_instance (const char *name, const char *root, int cache_size, - void *plugin_identity) -{ - Slapi_PBlock pb; - Slapi_Mods smods; - char value [128]; - char *dn; - int rc; - - PR_ASSERT (name && root && plugin_identity); - - dn = be_get_instance_dn (NULL, name); - - slapi_mods_init (&smods, 2); - slapi_mods_add(&smods, LDAP_MOD_ADD, SUFFIX_ATTR, strlen (root), root); - if (cache_size > 0) - { - sprintf (value, "%d", cache_size); - slapi_mods_add(&smods, LDAP_MOD_REPLACE, CACHE_ATTR, strlen (value), value); - } - - pblock_init (&pb); - slapi_modify_internal_set_pb (&pb, dn, slapi_mods_get_ldapmods_byref(&smods), - NULL, NULL, plugin_identity, 0); - slapi_modify_internal_pb (&pb); - - slapi_mods_done (&smods); - slapi_ch_free ((void**)&dn); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to update instance entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - - pblock_done(&pb); - return 0; -} - -/* configure instance indexes by adding an index entry: - "cn=<attr name>,cn=index,cn=config,cn=<instance name>, - cn=ldbm database,cn=plugins,cn=config".*/ -static int -be_configure_instance_indexes (const char *name, IndexConfig *indexes, - int index_count, void *plugin_identity) -{ - int rc; - Slapi_PBlock pb; - Slapi_Entry *e; - char *dn; - int i; - char *start, *end; - char index_type [16]; - - PR_ASSERT (name && indexes && index_count > 0 && plugin_identity); - - for (i = 0; i < index_count; i++) - { - dn = be_get_instance_dn (indexes[i].attr_name, name); - e = slapi_entry_alloc (); - slapi_entry_init (e, dn, NULL); - - /* add objectclases */ - slapi_entry_add_string (e, "objectclass", "top"); - slapi_entry_add_string (e, "objectclass", "nsIndex"); - slapi_entry_add_string (e, "cn", indexes[i].attr_name); - slapi_entry_add_string (e, "nssystemindex", indexes[i].system ? "true" : "false"); - - start = indexes[i].index_type; - while ((end = strchr (start, ' ')) != NULL) - { - if ((end - start) >= 16) - continue; - - strncpy (index_type, start, end - start); - slapi_entry_add_string (e, "nsindextype", index_type); - start = end + 1; - } - - slapi_entry_add_string (e, "nsindextype", start); - - pblock_init (&pb); - slapi_add_entry_internal_set_pb (&pb, e, NULL /* controls */, plugin_identity, - 0/* operation flags */); - slapi_add_internal_pb (&pb); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to update instance entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - } - - pblock_done(&pb); - return 0; -} - -int -be_create_instance (const char *type, const char *name, const char *root, - int cache_size, IndexConfig *indexes, int index_count, - void *plugin_identity) -{ - int rc; - - if (type == NULL || strcasecmp (type, "ldbm") != 0) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "invalid backend type: %s.\n", type ? type : "null"); - return -1; - } - - if (name == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: null instance name.\n"); - return -1; - } - - if (root == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: null root dn.\n"); - return -1; - } - - if (plugin_identity == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: null plugin identity.\n"); - return -1; - } - - rc = be_add_instance (name, plugin_identity); - if (rc != 0) - return rc; - - rc = be_configure_instance (name, root, cache_size, plugin_identity); - if (rc != 0) - return rc; - - if (index_count > 0) - rc = be_configure_instance_indexes (name, indexes, index_count, plugin_identity); - - return rc; -} - -int -be_remove_instance (const char *type, const char *name, void *plugin_identity) -{ - int rc; - char *dn; - Slapi_PBlock pb; - - if (type == NULL || strcasecmp (type, "ldbm") != 0) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_remove_instance: " - "invalid backend type: %s.\n", type ? type : "null"); - return -1; - } - - if (name == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_remove_instance: null instance name.\n"); - return -1; - } - - if (plugin_identity == NULL) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_remove_instance: null plugin identity.\n"); - return -1; - } - - dn = be_get_instance_dn (NULL, name); - - pblock_init (&pb); - slapi_delete_internal_set_pb (&pb, dn, NULL, NULL, plugin_identity, 0); - slapi_delete_internal_pb (&pb); - - slapi_ch_free ((void**)&dn); - - slapi_pblock_get (&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); - if (rc != LDAP_SUCCESS) - { - slapi_log_error(SLAPI_LOG_FATAL, NULL, "be_create_instance: " - "failed to update instance entry; LDAP error - %d\n", rc); - pblock_done(&pb); - return -1; - } - - pblock_done(&pb); - return 0; -} - void slapi_be_Rlock(Slapi_Backend * be) { @@ -680,6 +427,8 @@ slapi_lookup_instance_name_by_suffix(char *suffix, if (instances == NULL) return rval; + PR_ASSERT(suffix); + rval = 0; suffixlen = strlen(suffix); cookie = NULL; |