1 /* modify.c - bdb2 backend modify routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
14 static int add_values(Entry *e, LDAPMod *mod, char *dn);
15 static int delete_values(Entry *e, LDAPMod *mod, char *dn);
16 static int replace_values(Entry *e, LDAPMod *mod, char *dn);
19 bdb2i_back_modify_internal(
27 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 Debug(LDAP_DEBUG_ARGS, "bdb2i_back_modify:\n", 0, 0, 0);
35 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
36 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched,
38 if ( matched != NULL ) {
44 if ( (err = acl_check_modlist( be, conn, op, e, modlist )) != LDAP_SUCCESS ) {
45 send_ldap_result( conn, op, err, NULL, NULL );
49 for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
50 LDAPMod *mod = &ml->ml_mod;
52 switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
54 err = add_values( e, mod, op->o_ndn );
58 err = delete_values( e, mod, op->o_ndn );
61 case LDAP_MOD_REPLACE:
62 err = replace_values( e, mod, op->o_ndn );
66 if ( err != LDAP_SUCCESS ) {
67 /* unlock entry, delete from cache */
68 send_ldap_result( conn, op, err, NULL, NULL );
73 /* check that the entry still obeys the schema */
74 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
75 Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
76 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, NULL, NULL );
80 /* check for abandon */
81 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
82 if ( op->o_abandon ) {
83 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
86 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
89 if ( bdb2i_index_add_mods( be, modlist, e->e_id ) != 0 ) {
90 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
94 /* check for abandon */
95 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
96 if ( op->o_abandon ) {
97 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
100 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
102 /* change the entry itself */
103 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
104 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
108 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
109 bdb2i_cache_return_entry_w( &li->li_cache, e );
113 bdb2i_cache_return_entry_w( &li->li_cache, e );
128 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
129 struct timeval time1;
132 bdb2i_start_timing( be->bd_info, &time1 );
134 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
136 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
141 /* check, if a new default attribute index will be created,
142 in which case we have to open the index file BEFORE TP */
143 switch ( slapMode ) {
144 case SLAP_SERVER_MODE:
145 case SLAP_TIMEDSERVER_MODE:
147 case SLAP_TOOLID_MODE:
148 bdb2i_check_default_attr_index_mod( li, modlist );
152 ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist );
153 (void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
154 bdb2i_stop_timing( be->bd_info, time1, "MOD", conn, op );
170 /* check if the values we're adding already exist */
171 if ( (a = attr_find( e->e_attrs, mod->mod_type )) != NULL ) {
172 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
173 if ( value_find( a->a_vals, mod->mod_bvalues[i],
174 a->a_syntax, 3 ) == 0 ) {
175 return( LDAP_TYPE_OR_VALUE_EXISTS );
181 if( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
182 return( LDAP_CONSTRAINT_VIOLATION );
185 return( LDAP_SUCCESS );
198 /* delete the entire attribute */
199 if ( mod->mod_bvalues == NULL ) {
200 Debug( LDAP_DEBUG_ARGS, "removing entire attribute %s\n",
201 mod->mod_type, 0, 0 );
202 return( attr_delete( &e->e_attrs, mod->mod_type ) ?
203 LDAP_NO_SUCH_ATTRIBUTE : LDAP_SUCCESS );
206 /* delete specific values - find the attribute first */
207 if ( (a = attr_find( e->e_attrs, mod->mod_type )) == NULL ) {
208 Debug( LDAP_DEBUG_ARGS, "could not find attribute %s\n",
209 mod->mod_type, 0, 0 );
210 return( LDAP_NO_SUCH_ATTRIBUTE );
213 /* find each value to delete */
214 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
216 for ( j = 0; a->a_vals[j] != NULL; j++ ) {
217 if ( value_cmp( mod->mod_bvalues[i], a->a_vals[j],
218 a->a_syntax, 3 ) != 0 ) {
223 /* found a matching value - delete it */
224 ber_bvfree( a->a_vals[j] );
225 for ( k = j + 1; a->a_vals[k] != NULL; k++ ) {
226 a->a_vals[k - 1] = a->a_vals[k];
228 a->a_vals[k - 1] = NULL;
232 /* looked through them all w/o finding it */
234 Debug( LDAP_DEBUG_ARGS,
235 "could not find value for attr %s\n",
236 mod->mod_type, 0, 0 );
237 return( LDAP_NO_SUCH_ATTRIBUTE );
241 return( LDAP_SUCCESS );
251 (void) attr_delete( &e->e_attrs, mod->mod_type );
253 if ( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
254 return( LDAP_CONSTRAINT_VIOLATION );
257 return( LDAP_SUCCESS );