for ( i = 0; i < nbackends; i++ ) {
op->o_bd = &backends[i];
- if( op->o_bd->be_abandon ) op->o_bd->be_abandon( op, rs );
+ if ( op->o_bd->be_abandon ) {
+ (void)op->o_bd->be_abandon( op, rs );
+ }
}
+
return LDAP_SUCCESS;
}
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
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 );
+ 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 ( 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;
}
ber_socket_t sd;
ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
- /* us trylock to avoid possible deadlock */
+ /* use trylock to avoid possible deadlock */
rc = ldap_pvt_thread_mutex_trylock( &connections_mutex );
if( rc ) {
Modifications *modlist = NULL;
Modifications **modtail = &modlist;
int increment = 0;
+ char textbuf[ SLAP_TEXT_BUFLEN ];
+ size_t textlen = sizeof( textbuf );
Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
goto cleanup;
}
- /* FIXME: temporary */
+ 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 cleanup;
+ }
+
+ /* FIXME: needs review */
op->orm_modlist = modlist;
op->orm_increment = increment;
LDAPMod **modv = NULL;
#endif
int increment = op->orm_increment;
+ int rc = 0;
if( op->o_req_ndn.bv_len == 0 ) {
Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
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 );
- if( rs->sr_err != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- goto cleanup;
+ 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 cleanup;
+ }
}
+
+
if ( !repl_user ) {
for( modtail = &modlist;
*modtail != NULL;
if ( !repl_user )
#endif
{
- /* but we log only the ones not from a replicator user */
+ /* but multimaster slapd logs only the ones
+ * not from a replicator user */
cb.sc_next = op->o_callback;
op->o_callback = &cb;
}
rs->sr_ref = referral_rewrite( defref,
NULL, &op->o_req_dn,
LDAP_SCOPE_DEFAULT );
- if (!rs->sr_ref) rs->sr_ref = defref;
+ if ( rs->sr_ref == NULL ) {
+ /* FIXME: must duplicate, because
+ * overlays may muck with it */
+ rs->sr_ref = defref;
+ }
rs->sr_err = LDAP_REFERRAL;
send_ldap_result( op, rs );
- if (rs->sr_ref != defref) {
+ if ( rs->sr_ref != defref ) {
ber_bvarray_free( rs->sr_ref );
}
+
} else {
send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
"shadow context; no update referral" );
return rs->sr_err;
}
+/*
+ * Do non-update constraint checking.
+ */
+int
+slap_mods_no_update_check(
+ Modifications *ml,
+ const char **text,
+ char *textbuf,
+ size_t textlen )
+{
+ for ( ; ml != NULL; ml = ml->sml_next ) {
+ if ( is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
+ /* user modification disallowed */
+ snprintf( textbuf, textlen,
+ "%s: no user modification allowed",
+ ml->sml_type.bv_val );
+ *text = textbuf;
+ return LDAP_CONSTRAINT_VIOLATION;
+ }
+ }
+
+ return LDAP_SUCCESS;
+}
+
/*
* Do basic attribute type checking and syntax validation.
*/
int slap_mods_check(
Modifications *ml,
- int update,
const char **text,
char *textbuf,
size_t textlen,
return LDAP_UNDEFINED_TYPE;
}
+#if 0
+ /* moved to slap_mods_no_update_check() */
if (!update && is_at_no_user_mod( ad->ad_type )) {
/* user modification disallowed */
snprintf( textbuf, textlen,
*text = textbuf;
return LDAP_CONSTRAINT_VIOLATION;
}
+#endif
if ( is_at_obsolete( ad->ad_type ) &&
(( ml->sml_op != LDAP_MOD_REPLACE &&
}
break;
case LDAP_REQ_ADD:
+ {
+ int cleanup_attrs = 0;
+
+ if ( op->ora_e->e_attrs == NULL ) {
+ char textbuf[ SLAP_TEXT_BUFLEN ];
+ size_t textlen = sizeof( textbuf );
+
+ /* global overlay; create entry */
+ /* NOTE: this is a hack to use the chain overlay
+ * as global. I expect to be able to remove this
+ * soon by using slap_mods2entry() earlier in
+ * do_add(), adding the operational attrs later
+ * if required. */
+ rs->sr_err = slap_mods2entry( op->ora_modlist,
+ &op->ora_e, 0, 1,
+ &rs->sr_text, textbuf, textlen );
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ rc = 1;
+ break;
+ }
+ }
rc = lback->bi_op_add( op, rs );
+ if ( cleanup_attrs ) {
+ attrs_free( op->ora_e->e_attrs );
+ op->ora_e->e_attrs = NULL;
+ }
break;
+ }
case LDAP_REQ_DELETE:
rc = lback->bi_op_delete( op, rs );
break;
return lastmod_exop( op, rs );
case LDAP_REQ_MODIFY:
- /* if global overlay, modlist is not checked yet */
- if ( op->orm_modlist->sml_desc == NULL ) {
- char textbuf[SLAP_TEXT_BUFLEN];
- size_t textlen = sizeof textbuf;
-
- rs->sr_err = slap_mods_check( op->orm_modlist, 0, &rs->sr_text,
- textbuf, textlen, NULL );
-
- if ( rs->sr_err ) {
- goto return_error;
- }
- }
-
/* allow only changes to overlay status */
for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
if ( ad_cmp( ml->sml_desc, slap_schema.si_ad_modifiersName ) != 0
/*
* modify.c
*/
+LDAP_SLAPD_F( int ) slap_mods_no_update_check(
+ Modifications *ml,
+ const char **text,
+ char *textbuf, size_t textlen );
+
LDAP_SLAPD_F( int ) slap_mods_check(
Modifications *ml,
- int update,
const char **text,
char *textbuf, size_t textlen, void *ctx );
}
*modtail = NULL;
- rc = slap_mods_check( modlist, 0, &text, textbuf, textlen, NULL );
+ rc = slap_mods_check( modlist, &text, textbuf, textlen, NULL );
if ( rc == LDAP_SUCCESS ) {
- rc = slap_mods_opattrs( &op, modlist, modtail, &text, textbuf,
- textlen, 1 );
- }
-
- if ( rc == LDAP_SUCCESS ) {
- op.o_hdr = conn->c_sasl_bindop->o_hdr;
- op.o_tag = LDAP_REQ_MODIFY;
- op.o_ndn = op.o_req_ndn;
- op.o_callback = &cb;
- op.o_time = slap_get_time();
- op.o_do_not_cache = 1;
- op.o_is_auth_check = 1;
- op.o_req_dn = op.o_req_ndn;
- op.orm_modlist = modlist;
-
- rc = op.o_bd->be_modify( &op, &rs );
+ rc = slap_mods_no_update_check( modlist, &text,
+ textbuf, textlen );
+
+ if ( rc == LDAP_SUCCESS ) {
+ rc = slap_mods_opattrs( &op, modlist, modtail,
+ &text, textbuf, textlen, 1 );
+
+ if ( rc == LDAP_SUCCESS ) {
+ op.o_hdr = conn->c_sasl_bindop->o_hdr;
+ op.o_tag = LDAP_REQ_MODIFY;
+ op.o_ndn = op.o_req_ndn;
+ op.o_callback = &cb;
+ op.o_time = slap_get_time();
+ op.o_do_not_cache = 1;
+ op.o_is_auth_check = 1;
+ op.o_req_dn = op.o_req_ndn;
+ op.orm_modlist = modlist;
+
+ rc = op.o_bd->be_modify( &op, &rs );
+ }
+ }
}
slap_mods_free( modlist );
- return rc ? SASL_FAIL : SASL_OK;
+ return rc != LDAP_SUCCESS ? SASL_FAIL : SASL_OK;
}
#endif /* SASL_VERSION_FULL >= 2.1.16 */
} 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 = op->o_bd->be_update_ndn.bv_len;
- char textbuf[SLAP_TEXT_BUFLEN];
- size_t textlen = sizeof textbuf;
+ 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, update, &text,
+ rc = slap_mods_check( modlist, &text,
textbuf, textlen, NULL );
if ( rc != LDAP_SUCCESS) {
goto cleanup;
}
+ if ( !update ) {
+ rc = slap_mods_no_update_check( modlist,
+ &text, textbuf, textlen );
+ if ( rc != LDAP_SUCCESS) {
+ goto cleanup;
+ }
+ }
+
if ( !repl_user ) {
rc = slap_mods_opattrs( op,
modlist, modtail, &text,
if ( op->o_bd->be_modify ) {
int repl_user = be_isupdate( op );
if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) {
- int update = op->o_bd->be_update_ndn.bv_len;
- const char *text = NULL;
- 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 );
+ const char *text = NULL;
+ 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_err = slap_mods_check( modlist,
&text, textbuf, textlen, NULL );
if ( rs.sr_err != LDAP_SUCCESS ) {
goto cleanup;
}
+ if ( !update ) {
+ rs.sr_err = slap_mods_no_update_check( modlist,
+ &text, textbuf, textlen );
+ if ( rs.sr_err != LDAP_SUCCESS ) {
+ goto cleanup;
+ }
+ }
+
if ( !repl_user ) {
rs.sr_err = slap_mods_opattrs( op, modlist,
modtail, &text, textbuf,
goto done;
}
- rc = slap_mods_check( *modlist, 1, &text, txtbuf, textlen, NULL );
+ rc = slap_mods_check( *modlist, &text, txtbuf, textlen, NULL );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: mods check (%s)\n",