- *bvobj = tmpberval;
-
- return LDAP_SUCCESS;
-}
-
-/*
- * Function : slapi_int_ldapmod_to_entry
- * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
- * with a link list of the correspondent attributes.
- * Return value : LDAP_SUCCESS
- * LDAP_NO_MEMORY
- * LDAP_OTHER
-*/
-static Entry *
-slapi_int_ldapmod_to_entry(
- Connection *pConn,
- char *ldn,
- LDAPMod **mods )
-{
- struct berval dn = BER_BVNULL;
- Entry *pEntry=NULL;
- LDAPMod *pMod;
- struct berval *bv;
- Operation *op;
-
- Modifications *modlist = NULL;
- Modifications **modtail = &modlist;
- Modifications tmp;
-
- int rc = LDAP_SUCCESS;
- int i;
-
- const char *text = NULL;
-
- op = (Operation *)pConn->c_pending_ops.stqh_first;
-
- pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
- if ( pEntry == NULL) {
- rc = LDAP_NO_MEMORY;
- goto cleanup;
- }
-
- dn.bv_val = ldn;
- dn.bv_len = strlen(ldn);
-
- rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname, NULL );
- if ( rc != LDAP_SUCCESS ) {
- goto cleanup;
- }
-
- if ( rc == LDAP_SUCCESS ) {
- for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod = mods[++i]) {
- Modifications *mod;
-
- if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
- /*
- * Convert an array of pointers to bervals to
- * an array of bervals. Note that we need to copy the
- * values too, as the slap_mods_check() will free the
- * original values after prettying; the modifications
- * being passed in may not have been allocated on the
- * heap.
- */
- rc = bvptr2obj_copy( pMod->mod_bvalues, &bv );
- if ( rc != LDAP_SUCCESS ) goto cleanup;
- tmp.sml_type.bv_val = pMod->mod_type;
- tmp.sml_type.bv_len = strlen( pMod->mod_type );
- tmp.sml_values = bv;
- tmp.sml_nvalues = NULL;
-
- mod = (Modifications *) ch_malloc( sizeof(Modifications) );
-
- mod->sml_op = LDAP_MOD_ADD;
- mod->sml_flags = 0;
- mod->sml_next = NULL;
- mod->sml_desc = NULL;
- mod->sml_type = tmp.sml_type;
- mod->sml_values = tmp.sml_values;
- mod->sml_nvalues = tmp.sml_nvalues;
-
- *modtail = mod;
- modtail = &mod->sml_next;
-
- } else {
- /* attr values are in string format, need to be converted */
- /* to an array of bervals */
- if ( pMod->mod_values == NULL ) {
- rc = LDAP_OTHER;
- } else {
- rc = values2obj_copy( pMod->mod_values, &bv );
- if ( rc != LDAP_SUCCESS ) goto cleanup;
- tmp.sml_type.bv_val = pMod->mod_type;
- tmp.sml_type.bv_len = strlen( pMod->mod_type );
- tmp.sml_values = bv;
- tmp.sml_nvalues = NULL;
-
- mod = (Modifications *) ch_malloc( sizeof(Modifications) );
-
- mod->sml_op = LDAP_MOD_ADD;
- mod->sml_flags = 0;
- mod->sml_next = NULL;
- mod->sml_desc = NULL;
- mod->sml_type = tmp.sml_type;
- mod->sml_values = tmp.sml_values;
- mod->sml_nvalues = tmp.sml_nvalues;
-
- *modtail = mod;
- modtail = &mod->sml_next;
- }
- }
- } /* for each LDAPMod */
- }
-
- op->o_bd = select_backend( &pEntry->e_nname, 0, 0 );
- if ( op->o_bd == NULL ) {
- rc = LDAP_PARTIAL_RESULTS;
- } else {
- int repl_user = be_isupdate_dn( op->o_bd, &op->o_bd->be_rootdn );
- if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
- int update = !BER_BVISNULL( &op->o_bd->be_update_ndn );
- char textbuf[ SLAP_TEXT_BUFLEN ];
- size_t textlen = sizeof( textbuf );
-
- rc = slap_mods_check( modlist, &text,
- textbuf, textlen, NULL );
-
- if ( rc != LDAP_SUCCESS) {
- goto cleanup;
- }
-
- if ( !update ) {
- rc = slap_mods_no_user_mod_check( op, modlist,
- &text, textbuf, textlen );
- if ( rc != LDAP_SUCCESS) {
- goto cleanup;
- }
- }
-
- if ( !repl_user ) {
- rc = slap_mods_opattrs( op, modlist, modtail,
- &text, textbuf, textlen, 1 );
- if ( rc != LDAP_SUCCESS) {
- goto cleanup;
- }
- }
-
- rc = slap_mods2entry( modlist, &pEntry, repl_user,
- 0, &text, textbuf, textlen );
- if (rc != LDAP_SUCCESS) {
- goto cleanup;
- }
-
- } else {
- rc = LDAP_REFERRAL;
- }
- }
-
-cleanup:;
- if ( modlist != NULL )
- slap_mods_free( modlist );