/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Modifications *modlist = NULL;
Modifications **modtail = &modlist;
Modifications tmp;
+ char textbuf[ SLAP_TEXT_BUFLEN ];
+ size_t textlen = sizeof( textbuf );
+ int rc = 0;
Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
/*
rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
op->o_tmpmemctx );
- if( rs->sr_err != LDAP_SUCCESS ) {
+ if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn.bv_val, 0, 0 );
send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
goto done;
goto done;
}
- if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
+ if ( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
goto done;
}
Statslog( LDAP_DEBUG_STATS, "%s ADD dn=\"%s\"\n",
op->o_log_prefix, e->e_name.bv_val, 0, 0, 0 );
- if( e->e_nname.bv_len == 0 ) {
+ if ( dn_match( &e->e_nname, &slap_empty_bv ) ) {
/* protocolError may be a more appropriate error */
send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
"root DSE already exists" );
goto done;
- } else if ( bvmatch( &e->e_nname, &frontendDB->be_schemandn ) ) {
+ } else if ( dn_match( &e->e_nname, &frontendDB->be_schemandn ) ) {
send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
"subschema subentry already exists" );
goto done;
}
+ rs->sr_err = slap_mods_check( modlist, &rs->sr_text,
+ textbuf, textlen, NULL );
+
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ goto done;
+ }
+
/* temporary; remove if not invoking backend function */
op->ora_e = e;
op->ora_modlist = modlist;
op->o_bd = frontendDB;
- rs->sr_err = frontendDB->be_add( op, rs );
- if ( rs->sr_err == 0 ) {
+ rc = frontendDB->be_add( op, rs );
+ if ( rc == 0 ) {
e = NULL;
}
done:;
slap_graduate_commit_csn( op );
- if( modlist != NULL ) {
+ if ( modlist != NULL ) {
slap_mods_free( modlist );
}
- if( e != NULL ) {
+ if ( e != NULL ) {
entry_free( e );
}
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
- return rs->sr_err;
+ return rc;
}
int
Entry *e = op->ora_e;
Modifications *modlist = op->ora_modlist;
Modifications **modtail = &modlist;
+ int rc = 0;
+ BackendDB *op_be;
manageDSAit = get_manageDSAit( op );
* appropriate one, or send a referral to our "referral server"
* if we don't hold it.
*/
- op->o_bd = select_backend( &e->e_nname, manageDSAit, 0 );
+ op->o_bd = select_backend( &e->e_nname, manageDSAit, 1 );
if ( op->o_bd == NULL ) {
rs->sr_ref = referral_rewrite( default_referral,
NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
if ( !rs->sr_ref ) rs->sr_ref = default_referral;
if ( rs->sr_ref ) {
rs->sr_err = LDAP_REFERRAL;
+ op->o_bd = frontendDB;
send_ldap_result( op, rs );
+ op->o_bd = NULL;
if ( rs->sr_ref != default_referral ) {
ber_bvarray_free( rs->sr_ref );
}
} else {
+ op->o_bd = frontendDB;
send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
"no global superior knowledge" );
+ op->o_bd = NULL;
}
goto done;
}
+ /* If we've got a glued backend, check the real backend */
+ op_be = op->o_bd;
+ if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
+ op->o_bd = select_backend( &e->e_nname, manageDSAit, 0 );
+ }
+
/* check restrictions */
if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
if ( !SLAP_SHADOW(op->o_bd) || repl_user )
#endif
{
- int update = op->o_bd->be_update_ndn.bv_len;
- char textbuf[SLAP_TEXT_BUFLEN];
- size_t textlen = sizeof textbuf;
- slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
+ int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
+ char textbuf[ SLAP_TEXT_BUFLEN ];
+ size_t textlen = sizeof( textbuf );
+ slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
- rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
- textbuf, textlen, NULL );
+ op->o_bd = op_be;
- if( rs->sr_err != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- goto done;
+ if ( !update ) {
+ rs->sr_err = slap_mods_no_update_check( modlist,
+ &rs->sr_text,
+ textbuf, textlen );
+
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ goto done;
+ }
}
if ( !repl_user ) {
- for( modtail = &modlist;
- *modtail != NULL;
- modtail = &(*modtail)->sml_next )
+ /* go to the last mod */
+ for ( modtail = &modlist;
+ *modtail != NULL;
+ modtail = &(*modtail)->sml_next )
{
assert( (*modtail)->sml_op == LDAP_MOD_ADD );
assert( (*modtail)->sml_desc != NULL );
}
- rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
- &rs->sr_text, textbuf, textlen, 1 );
- if( rs->sr_err != LDAP_SUCCESS ) {
+
+ rs->sr_err = slap_mods_opattrs( op, modlist,
+ modtail, &rs->sr_text,
+ textbuf, textlen, 1 );
+ if ( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
goto done;
}
rs->sr_err = slap_mods2entry( modlist, &e, repl_user, 0,
&rs->sr_text, textbuf, textlen );
- if( rs->sr_err != LDAP_SUCCESS ) {
+ if ( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
goto done;
}
cb.sc_next = op->o_callback;
op->o_callback = &cb;
}
- if ( (op->o_bd->be_add)( op, rs ) == 0 ) {
+ rc = (op->o_bd->be_add)( op, rs );
+ if ( rc == 0 ) {
+ /* FIXME: be_entry_release_w() should be
+ * called by do_add(), so that global
+ * overlays on the way back can
+ * at least read the entry */
be_entry_release_w( op, e );
e = NULL;
}
+ op->ora_e = NULL;
#ifndef SLAPD_MULTIMASTER
} else {
#endif /* LDAP_SLAPI */
done:;
- return rs->sr_err;
+ return rc;
}
int
tail = &attr->a_next;
}
+ *text = NULL;
+
return LDAP_SUCCESS;
}