void retrocl_create_cle (void) { Slapi_PBlock *pb = NULL; Slapi_Entry *e; int rc; struct berval *vals[2]; struct berval val; vals[0] = &val; vals[1] = NULL; e = slapi_entry_alloc(); slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_CHANGELOG_DN)); /* Set the objectclass attribute */ val.bv_val = "top"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "objectclass", vals ); /* Set the objectclass attribute */ val.bv_val = "nsContainer"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "objectclass", vals ); /* Set the objectclass attribute */ val.bv_val = "changelog"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "cn", vals ); val.bv_val = RETROCL_ACL; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "aci", vals ); pb = slapi_pblock_new (); slapi_add_entry_internal_set_pb( pb, 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); if (rc == 0) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "created cn=changelog\n"); } else if (rc == LDAP_ALREADY_EXISTS) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "cn=changelog already existed\n"); } else { slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=changelog could not be created (%d)\n", rc); } }
/* * Take a bunch of strings, and create a index config entry */ Slapi_Entry * ldbm_instance_init_config_entry(char *cn_val, char *val1, char *val2, char *val3, char *val4){ Slapi_Entry *e = slapi_entry_alloc(); struct berval *vals[2]; struct berval val; vals[0] = &val; vals[1] = NULL; slapi_entry_set_dn(e,slapi_ch_strdup("cn=indexContainer")); val.bv_val = cn_val; val.bv_len = strlen(cn_val); slapi_entry_add_values(e,"cn",vals); val.bv_val = val1; val.bv_len = strlen(val1); slapi_entry_add_values(e,"nsIndexType",vals); if(val2){ val.bv_val = val2; val.bv_len = strlen(val2); slapi_entry_add_values(e,"nsIndexType",vals); } if(val3){ val.bv_val = val3; val.bv_len = strlen(val3); slapi_entry_add_values(e,"nsIndexType",vals); } if(val4){ val.bv_val = val4; val.bv_len = strlen(val4); slapi_entry_add_values(e,"nsIndexType",vals); } return e; }
static int retrocl_create_be(const char *bedir) { Slapi_PBlock *pb = NULL; Slapi_Entry *e; struct berval *vals[2]; struct berval val; int rc; vals[0] = &val; vals[1] = NULL; e = slapi_entry_alloc(); /* RETROCL_LDBM_DN is no need to be normalized. */ slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_LDBM_DN)); /* Set the objectclass attribute */ val.bv_val = "top"; val.bv_len = 3; slapi_entry_add_values( e, "objectclass", vals ); /* Set the objectclass attribute */ val.bv_val = "extensibleObject"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "objectclass", vals ); /* Set the objectclass attribute */ val.bv_val = "nsBackendInstance"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "objectclass", vals ); val.bv_val = "changelog"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "cn", vals ); val.bv_val = RETROCL_BE_CACHESIZE; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsslapd-cachesize", vals ); val.bv_val = RETROCL_CHANGELOG_DN; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsslapd-suffix", vals ); val.bv_val = RETROCL_BE_CACHEMEMSIZE; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsslapd-cachememsize", vals ); val.bv_val = "off"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsslapd-readonly", vals ); if (bedir) { val.bv_val = (char *)bedir; /* cast const */ val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsslapd-directory", vals ); } pb = slapi_pblock_new (); slapi_add_entry_internal_set_pb( pb, 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); if (rc == 0) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "created changelog database node\n"); } else if (rc == LDAP_ALREADY_EXISTS) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "changelog database node already existed\n"); } else { slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend could not be created (%d)\n", rc); return rc; } /* we need the changenumber indexed */ e = slapi_entry_alloc(); /* RETROCL_INDEX_DN is no need to be normalized. */ slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_INDEX_DN)); /* Set the objectclass attribute */ val.bv_val = "top"; val.bv_len = 3; slapi_entry_add_values( e, "objectclass", vals ); /* Set the objectclass attribute */ val.bv_val = "nsIndex"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "objectclass", vals ); val.bv_val = "changenumber"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "cn", vals ); val.bv_val = "false"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nssystemindex", vals ); val.bv_val = "eq"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsindextype", vals ); val.bv_val = "integerOrderingMatch"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsMatchingRule", vals ); pb = slapi_pblock_new (); slapi_add_entry_internal_set_pb( pb, 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); if (rc == 0) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "created changenumber index node\n"); } else if (rc == LDAP_ALREADY_EXISTS) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "changelog index node already existed\n"); } else { slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "Changelog LDBM backend changenumber index could not be created (%d)\n", rc); return rc; } return rc; }
/* * Function: retrocl_create_config * * Returns: LDAP_ * * Arguments: none * * Description: * This function is called if there was no mapping tree node or backend for * cn=changelog. */ int retrocl_create_config(void) { Slapi_PBlock *pb = NULL; Slapi_Entry *e; struct berval *vals[2]; struct berval val; int rc; char *mappingtree_dn = NULL; vals[0] = &val; vals[1] = NULL; /* Assume the mapping tree node is missing. It doesn't hurt to * attempt to add it if it already exists. You will see a warning * in the errors file when the referenced backend does not exist. */ e = slapi_entry_alloc(); /* This function converts the old DN style to the new one. */ mappingtree_dn = slapi_create_dn_string("%s", RETROCL_MAPPINGTREE_DN); if (NULL == mappingtree_dn) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "retrocl_create_config: failed to normalize " "mappingtree dn %s\n", RETROCL_MAPPINGTREE_DN); return LDAP_PARAM_ERROR; } slapi_entry_set_dn(e, mappingtree_dn); /* mappingtree_dn is consumed */ /* Set the objectclass attribute */ val.bv_val = "top"; val.bv_len = 3; slapi_entry_add_values( e, "objectclass", vals ); /* Set the objectclass attribute */ val.bv_val = "extensibleObject"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "objectclass", vals ); /* Set the objectclass attribute */ val.bv_val = "nsMappingTree"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "objectclass", vals ); val.bv_val = "backend"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsslapd-state", vals ); val.bv_val = RETROCL_CHANGELOG_DN; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "cn", vals ); val.bv_val = "changelog"; val.bv_len = strlen(val.bv_val); slapi_entry_add_values( e, "nsslapd-backend", vals ); pb = slapi_pblock_new (); slapi_add_entry_internal_set_pb( pb, 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); if (rc == 0) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "created changelog mapping tree node\n"); } else if (rc == LDAP_ALREADY_EXISTS) { slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "changelog mapping tree node already existed\n"); } else { slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=\"cn=changelog\",cn=mapping tree,cn=config could not be created (%d)\n", rc); return rc; } retrocl_be_changelog = slapi_be_select_by_instance_name("changelog"); if (retrocl_be_changelog == NULL) { /* This is not the nsslapd-changelogdir from cn=changelog4,cn=config */ char *bedir; bedir = retrocl_get_config_str(CONFIG_CHANGELOG_DIRECTORY_ATTRIBUTE); if (bedir == NULL) { /* none specified */ } rc = retrocl_create_be(bedir); slapi_ch_free ((void **)&bedir); if (rc != LDAP_SUCCESS && rc != LDAP_ALREADY_EXISTS) { return rc; } retrocl_be_changelog = slapi_be_select_by_instance_name("changelog"); } return LDAP_SUCCESS; }
/* * Extract the payload from a total update extended operation, * decode it, and produce a Slapi_Entry structure representing a new * entry to be added to the local database. */ static int decode_total_update_extop(Slapi_PBlock *pb, Slapi_Entry **ep) { BerElement *tmp_bere = NULL; Slapi_Entry *e = NULL; Slapi_Attr *attr = NULL; char *str = NULL; struct berval *extop_value = NULL; char *extop_oid = NULL; ber_len_t len; char *lasto; ber_tag_t tag; int rc; PRBool deleted; PR_ASSERT(NULL != pb); PR_ASSERT(NULL != ep); slapi_pblock_get(pb, SLAPI_EXT_OP_REQ_OID, &extop_oid); slapi_pblock_get(pb, SLAPI_EXT_OP_REQ_VALUE, &extop_value); if ((NULL == extop_oid) || ((strcmp(extop_oid, REPL_NSDS50_REPLICATION_ENTRY_REQUEST_OID) != 0) && (strcmp(extop_oid, REPL_NSDS71_REPLICATION_ENTRY_REQUEST_OID) != 0)) || !BV_HAS_DATA(extop_value)) { /* Bogus */ goto loser; } if ((tmp_bere = ber_init(extop_value)) == NULL) { goto loser; } if ((e = slapi_entry_alloc()) == NULL) { goto loser; } if (ber_scanf(tmp_bere, "{") == LBER_ERROR) /* Begin outer sequence */ { goto loser; } /* The entry's uniqueid is first */ if (ber_scanf(tmp_bere, "a", &str) == LBER_ERROR) { goto loser; } slapi_entry_set_uniqueid(e, str); str = NULL; /* Slapi_Entry now owns the uniqueid */ /* The entry's DN is next */ if (ber_scanf(tmp_bere, "a", &str) == LBER_ERROR) { goto loser; } slapi_entry_set_dn(e, str); str = NULL; /* Slapi_Entry now owns the dn */ /* Get the attributes */ for ( tag = ber_first_element( tmp_bere, &len, &lasto ); tag != LBER_ERROR && tag != LBER_END_OF_SEQORSET; tag = ber_next_element( tmp_bere, &len, lasto ) ) { if (my_ber_scanf_attr (tmp_bere, &attr, &deleted) != 0) { goto loser; } /* Add the attribute to the entry */ if (deleted) entry_add_deleted_attribute_wsi(e, attr); /* entry now owns attr */ else entry_add_present_attribute_wsi(e, attr); /* entry now owns attr */ attr = NULL; } if (ber_scanf(tmp_bere, "}") == LBER_ERROR) /* End sequence for this entry */ { goto loser; } /* Check for ldapsubentries and tombstone entries to set flags properly */ slapi_entry_attr_find(e, "objectclass", &attr); if (attr != NULL) { struct berval bv; bv.bv_val = "ldapsubentry"; bv.bv_len = strlen(bv.bv_val); if (slapi_attr_value_find(attr, &bv) == 0) { slapi_entry_set_flag(e, SLAPI_ENTRY_LDAPSUBENTRY); } bv.bv_val = SLAPI_ATTR_VALUE_TOMBSTONE; bv.bv_len = strlen(bv.bv_val); if (slapi_attr_value_find(attr, &bv) == 0) { slapi_entry_set_flag(e, SLAPI_ENTRY_FLAG_TOMBSTONE); } } /* If we get here, the entry is properly constructed. Return it. */ rc = 0; *ep = e; goto free_and_return; loser: rc = -1; /* slapi_ch_free accepts NULL pointer */ slapi_ch_free((void **)&str); if (attr != NULL) { slapi_attr_free (&attr); } if (NULL != e) { slapi_entry_free (e); } *ep = NULL; slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "Error: could not decode extended " "operation containing entry for total update.\n"); free_and_return: if (NULL != tmp_bere) { ber_free(tmp_bere, 1); tmp_bere = NULL; } return rc; }