1 /* modify.c - ldbm backend modify routine */
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
14 extern int global_schemacheck;
15 extern Attribute *attr_find();
17 static int add_values();
18 static int delete_values();
19 static int replace_values();
30 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
36 Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
38 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
39 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched,
41 if ( matched != NULL ) {
47 /* check for deleted */
51 if ( (err = acl_check_mods( be, conn, op, e, mods )) != LDAP_SUCCESS ) {
52 send_ldap_result( conn, op, err, NULL, NULL );
56 for ( mod = mods; mod != NULL; mod = mod->mod_next ) {
57 switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
59 err = add_values( e, mod, op->o_dn );
63 err = delete_values( e, mod, op->o_dn );
66 case LDAP_MOD_REPLACE:
67 err = replace_values( e, mod, op->o_dn );
71 if ( err != LDAP_SUCCESS ) {
72 /* unlock entry, delete from cache */
73 send_ldap_result( conn, op, err, NULL, NULL );
78 /* check that the entry still obeys the schema */
79 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
80 Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
81 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, NULL, NULL );
85 /* check for abandon */
86 pthread_mutex_lock( &op->o_abandonmutex );
87 if ( op->o_abandon ) {
88 pthread_mutex_unlock( &op->o_abandonmutex );
91 pthread_mutex_unlock( &op->o_abandonmutex );
94 if ( index_add_mods( be, mods, e->e_id ) != 0 ) {
95 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
99 /* check for abandon */
100 pthread_mutex_lock( &op->o_abandonmutex );
101 if ( op->o_abandon ) {
102 pthread_mutex_unlock( &op->o_abandonmutex );
105 pthread_mutex_unlock( &op->o_abandonmutex );
107 /* change the entry itself */
108 if ( id2entry_add( be, e ) != 0 ) {
109 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
113 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
114 cache_return_entry_w( &li->li_cache, e );
118 cache_return_entry_w( &li->li_cache, e );
132 /* check if the values we're adding already exist */
133 if ( (a = attr_find( e->e_attrs, mod->mod_type )) != NULL ) {
134 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
135 if ( value_find( a->a_vals, mod->mod_bvalues[i],
136 a->a_syntax, 3 ) == 0 ) {
137 return( LDAP_TYPE_OR_VALUE_EXISTS );
143 if( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
144 return( LDAP_CONSTRAINT_VIOLATION );
147 return( LDAP_SUCCESS );
160 /* delete the entire attribute */
161 if ( mod->mod_bvalues == NULL ) {
162 Debug( LDAP_DEBUG_ARGS, "removing entire attribute %s\n",
163 mod->mod_type, 0, 0 );
164 return( attr_delete( &e->e_attrs, mod->mod_type ) ?
165 LDAP_NO_SUCH_ATTRIBUTE : LDAP_SUCCESS );
168 /* delete specific values - find the attribute first */
169 if ( (a = attr_find( e->e_attrs, mod->mod_type )) == NULL ) {
170 Debug( LDAP_DEBUG_ARGS, "could not find attribute %s\n",
171 mod->mod_type, 0, 0 );
172 return( LDAP_NO_SUCH_ATTRIBUTE );
175 /* find each value to delete */
176 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
178 for ( j = 0; a->a_vals[j] != NULL; j++ ) {
179 if ( value_cmp( mod->mod_bvalues[i], a->a_vals[j],
180 a->a_syntax, 3 ) != 0 ) {
185 /* found a matching value - delete it */
186 ber_bvfree( a->a_vals[j] );
187 for ( k = j + 1; a->a_vals[k] != NULL; k++ ) {
188 a->a_vals[k - 1] = a->a_vals[k];
190 a->a_vals[k - 1] = NULL;
194 /* looked through them all w/o finding it */
196 Debug( LDAP_DEBUG_ARGS,
197 "could not find value for attr %s\n",
198 mod->mod_type, 0, 0 );
199 return( LDAP_NO_SUCH_ATTRIBUTE );
203 return( LDAP_SUCCESS );
213 (void) attr_delete( &e->e_attrs, mod->mod_type );
215 if ( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
216 return( LDAP_CONSTRAINT_VIOLATION );
219 return( LDAP_SUCCESS );