1 /* modify.c - ldbm backend modify routine */
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.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);
27 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
35 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
36 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched,
38 if ( matched != NULL ) {
44 /* check for deleted */
48 if ( (err = acl_check_modlist( be, conn, op, e, modlist )) != LDAP_SUCCESS ) {
49 send_ldap_result( conn, op, err, NULL, NULL );
53 for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
54 LDAPMod *mod = &ml->ml_mod;
56 switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
58 err = add_values( e, mod, op->o_dn );
62 err = delete_values( e, mod, op->o_dn );
65 case LDAP_MOD_REPLACE:
66 err = replace_values( e, mod, op->o_dn );
70 if ( err != LDAP_SUCCESS ) {
71 /* unlock entry, delete from cache */
72 send_ldap_result( conn, op, err, NULL, NULL );
77 /* check that the entry still obeys the schema */
78 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
79 Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
80 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, NULL, NULL );
84 /* check for abandon */
85 pthread_mutex_lock( &op->o_abandonmutex );
86 if ( op->o_abandon ) {
87 pthread_mutex_unlock( &op->o_abandonmutex );
90 pthread_mutex_unlock( &op->o_abandonmutex );
93 if ( index_add_mods( be, modlist, e->e_id ) != 0 ) {
94 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
98 /* check for abandon */
99 pthread_mutex_lock( &op->o_abandonmutex );
100 if ( op->o_abandon ) {
101 pthread_mutex_unlock( &op->o_abandonmutex );
104 pthread_mutex_unlock( &op->o_abandonmutex );
106 /* change the entry itself */
107 if ( id2entry_add( be, e ) != 0 ) {
108 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
112 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
113 cache_return_entry_w( &li->li_cache, e );
117 cache_return_entry_w( &li->li_cache, e );
131 /* check if the values we're adding already exist */
132 if ( (a = attr_find( e->e_attrs, mod->mod_type )) != NULL ) {
133 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
134 if ( value_find( a->a_vals, mod->mod_bvalues[i],
135 a->a_syntax, 3 ) == 0 ) {
136 return( LDAP_TYPE_OR_VALUE_EXISTS );
142 if( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
143 return( LDAP_CONSTRAINT_VIOLATION );
146 return( LDAP_SUCCESS );
159 /* delete the entire attribute */
160 if ( mod->mod_bvalues == NULL ) {
161 Debug( LDAP_DEBUG_ARGS, "removing entire attribute %s\n",
162 mod->mod_type, 0, 0 );
163 return( attr_delete( &e->e_attrs, mod->mod_type ) ?
164 LDAP_NO_SUCH_ATTRIBUTE : LDAP_SUCCESS );
167 /* delete specific values - find the attribute first */
168 if ( (a = attr_find( e->e_attrs, mod->mod_type )) == NULL ) {
169 Debug( LDAP_DEBUG_ARGS, "could not find attribute %s\n",
170 mod->mod_type, 0, 0 );
171 return( LDAP_NO_SUCH_ATTRIBUTE );
174 /* find each value to delete */
175 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
177 for ( j = 0; a->a_vals[j] != NULL; j++ ) {
178 if ( value_cmp( mod->mod_bvalues[i], a->a_vals[j],
179 a->a_syntax, 3 ) != 0 ) {
184 /* found a matching value - delete it */
185 ber_bvfree( a->a_vals[j] );
186 for ( k = j + 1; a->a_vals[k] != NULL; k++ ) {
187 a->a_vals[k - 1] = a->a_vals[k];
189 a->a_vals[k - 1] = NULL;
193 /* looked through them all w/o finding it */
195 Debug( LDAP_DEBUG_ARGS,
196 "could not find value for attr %s\n",
197 mod->mod_type, 0, 0 );
198 return( LDAP_NO_SUCH_ATTRIBUTE );
202 return( LDAP_SUCCESS );
212 (void) attr_delete( &e->e_attrs, mod->mod_type );
214 if ( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
215 return( LDAP_CONSTRAINT_VIOLATION );
218 return( LDAP_SUCCESS );