1 /* modify.c - bdb2 backend modify routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
16 bdb2i_back_modify_internal(
24 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
30 Debug(LDAP_DEBUG_ARGS, "bdb2i_back_modify:\n", 0, 0, 0);
32 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
33 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched,
35 if ( matched != NULL ) {
41 if ( (err = acl_check_modlist( be, conn, op, e, modlist )) != LDAP_SUCCESS ) {
42 send_ldap_result( conn, op, err, NULL, NULL );
46 for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
47 LDAPMod *mod = &ml->ml_mod;
49 switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
51 err = add_values( e, mod, op->o_ndn );
55 err = delete_values( e, mod, op->o_ndn );
58 case LDAP_MOD_REPLACE:
59 err = replace_values( e, mod, op->o_ndn );
63 if ( err != LDAP_SUCCESS ) {
64 /* unlock entry, delete from cache */
65 send_ldap_result( conn, op, err, NULL, NULL );
70 /* check that the entry still obeys the schema */
71 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
72 Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
73 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, NULL, NULL );
77 /* check for abandon */
78 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
79 if ( op->o_abandon ) {
80 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
83 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
86 if ( bdb2i_index_add_mods( be, modlist, e->e_id ) != 0 ) {
87 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
91 /* check for abandon */
92 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
93 if ( op->o_abandon ) {
94 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
97 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
99 /* change the entry itself */
100 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
101 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
105 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
106 bdb2i_cache_return_entry_w( &li->li_cache, e );
110 bdb2i_cache_return_entry_w( &li->li_cache, e );
125 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
126 struct timeval time1;
129 bdb2i_start_timing( be->bd_info, &time1 );
131 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
133 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
138 /* check, if a new default attribute index will be created,
139 in which case we have to open the index file BEFORE TP */
140 switch ( slapMode ) {
141 case SLAP_SERVER_MODE:
142 case SLAP_TIMEDSERVER_MODE:
144 case SLAP_TOOLID_MODE:
145 bdb2i_check_default_attr_index_mod( li, modlist );
149 ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist );
150 (void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
151 bdb2i_stop_timing( be->bd_info, time1, "MOD", conn, op );
167 /* check if the values we're adding already exist */
168 if ( (a = attr_find( e->e_attrs, mod->mod_type )) != NULL ) {
169 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
170 if ( value_find( a->a_vals, mod->mod_bvalues[i],
171 a->a_syntax, 3 ) == 0 ) {
172 return( LDAP_TYPE_OR_VALUE_EXISTS );
178 if( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
179 return( LDAP_CONSTRAINT_VIOLATION );
182 return( LDAP_SUCCESS );
195 /* delete the entire attribute */
196 if ( mod->mod_bvalues == NULL ) {
197 Debug( LDAP_DEBUG_ARGS, "removing entire attribute %s\n",
198 mod->mod_type, 0, 0 );
199 return( attr_delete( &e->e_attrs, mod->mod_type ) ?
200 LDAP_NO_SUCH_ATTRIBUTE : LDAP_SUCCESS );
203 /* delete specific values - find the attribute first */
204 if ( (a = attr_find( e->e_attrs, mod->mod_type )) == NULL ) {
205 Debug( LDAP_DEBUG_ARGS, "could not find attribute %s\n",
206 mod->mod_type, 0, 0 );
207 return( LDAP_NO_SUCH_ATTRIBUTE );
210 /* find each value to delete */
211 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
213 for ( j = 0; a->a_vals[j] != NULL; j++ ) {
214 if ( value_cmp( mod->mod_bvalues[i], a->a_vals[j],
215 a->a_syntax, 3 ) != 0 ) {
220 /* found a matching value - delete it */
221 ber_bvfree( a->a_vals[j] );
222 for ( k = j + 1; a->a_vals[k] != NULL; k++ ) {
223 a->a_vals[k - 1] = a->a_vals[k];
225 a->a_vals[k - 1] = NULL;
229 /* looked through them all w/o finding it */
231 Debug( LDAP_DEBUG_ARGS,
232 "could not find value for attr %s\n",
233 mod->mod_type, 0, 0 );
234 return( LDAP_NO_SUCH_ATTRIBUTE );
238 return( LDAP_SUCCESS );
248 (void) attr_delete( &e->e_attrs, mod->mod_type );
250 if ( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
251 return( LDAP_CONSTRAINT_VIOLATION );
254 return( LDAP_SUCCESS );