1 /* modify.c - ldbm backend modify routine */
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
24 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
30 Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
32 /* acquire and lock entry */
33 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
34 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched,
36 if ( matched != NULL ) {
42 if ( (err = acl_check_modlist( be, conn, op, e, modlist )) != LDAP_SUCCESS ) {
43 send_ldap_result( conn, op, err, NULL, NULL );
47 for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
48 LDAPMod *mod = &ml->ml_mod;
50 switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
52 err = add_values( e, mod, op->o_ndn );
56 err = delete_values( e, mod, op->o_ndn );
59 case LDAP_MOD_REPLACE:
60 err = replace_values( e, mod, op->o_ndn );
64 if ( err != LDAP_SUCCESS ) {
65 /* unlock entry, delete from cache */
66 send_ldap_result( conn, op, err, NULL, NULL );
71 /* check that the entry still obeys the schema */
72 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
73 Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
74 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, NULL, NULL );
78 /* check for abandon */
79 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
80 if ( op->o_abandon ) {
81 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
84 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
87 if ( index_add_mods( be, modlist, e->e_id ) != 0 ) {
88 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
92 /* check for abandon */
93 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
94 if ( op->o_abandon ) {
95 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
98 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
100 /* change the entry itself */
101 if ( id2entry_add( be, e ) != 0 ) {
102 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
106 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
107 cache_return_entry_w( &li->li_cache, e );
111 cache_return_entry_w( &li->li_cache, e );
125 /* check if the values we're adding already exist */
126 if ( (a = attr_find( e->e_attrs, mod->mod_type )) != NULL ) {
127 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
128 if ( value_find( a->a_vals, mod->mod_bvalues[i],
129 a->a_syntax, 3 ) == 0 ) {
130 return( LDAP_TYPE_OR_VALUE_EXISTS );
136 if( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
137 return( LDAP_CONSTRAINT_VIOLATION );
140 return( LDAP_SUCCESS );
153 /* delete the entire attribute */
154 if ( mod->mod_bvalues == NULL ) {
155 Debug( LDAP_DEBUG_ARGS, "removing entire attribute %s\n",
156 mod->mod_type, 0, 0 );
157 return( attr_delete( &e->e_attrs, mod->mod_type ) ?
158 LDAP_NO_SUCH_ATTRIBUTE : LDAP_SUCCESS );
161 /* delete specific values - find the attribute first */
162 if ( (a = attr_find( e->e_attrs, mod->mod_type )) == NULL ) {
163 Debug( LDAP_DEBUG_ARGS, "could not find attribute %s\n",
164 mod->mod_type, 0, 0 );
165 return( LDAP_NO_SUCH_ATTRIBUTE );
168 /* find each value to delete */
169 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
171 for ( j = 0; a->a_vals[j] != NULL; j++ ) {
172 if ( value_cmp( mod->mod_bvalues[i], a->a_vals[j],
173 a->a_syntax, 3 ) != 0 ) {
178 /* found a matching value - delete it */
179 ber_bvfree( a->a_vals[j] );
180 for ( k = j + 1; a->a_vals[k] != NULL; k++ ) {
181 a->a_vals[k - 1] = a->a_vals[k];
183 a->a_vals[k - 1] = NULL;
187 /* looked through them all w/o finding it */
189 Debug( LDAP_DEBUG_ARGS,
190 "could not find value for attr %s\n",
191 mod->mod_type, 0, 0 );
192 return( LDAP_NO_SUCH_ATTRIBUTE );
196 return( LDAP_SUCCESS );
206 (void) attr_delete( &e->e_attrs, mod->mod_type );
208 if ( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
209 return( LDAP_CONSTRAINT_VIOLATION );
212 return( LDAP_SUCCESS );