]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/modify.c
Code clean-up.
[openldap] / servers / slapd / back-ldbm / modify.c
index 84f6f109dc672ddb516efafd7d248a183303d37e..940d2c808bf68b20c7f8fd0ca627de43349a1a18 100644 (file)
@@ -1,19 +1,19 @@
 /* modify.c - ldbm backend modify routine */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
 #include "slap.h"
 #include "back-ldbm.h"
+#include "proto-back-ldbm.h"
 
-extern int             global_schemacheck;
-extern Entry           *dn2entry();
-extern Attribute       *attr_find();
-
-static int     add_values();
-static int     delete_values();
-static int     replace_values();
+static int     add_values(Entry *e, LDAPMod *mod, char *dn);
+static int     delete_values(Entry *e, LDAPMod *mod, char *dn);
+static int     replace_values(Entry *e, LDAPMod *mod, char *dn);
 
 int
 ldbm_back_modify(
@@ -21,16 +21,19 @@ ldbm_back_modify(
     Connection *conn,
     Operation  *op,
     char       *dn,
-    LDAPMod    *mods
+    LDAPModList        *modlist
 )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-       char            *matched = NULL;
+       char            *matched;
+       LDAPModList     *ml;
        Entry           *e;
-       int             i, err, modtype;
-       LDAPMod         *mod;
+       int             i, err;
+
+       Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
 
-       if ( (e = dn2entry( be, dn, &matched )) == NULL ) {
+       /* acquire and lock entry */
+       if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
                send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched,
                    NULL );
                if ( matched != NULL ) {
@@ -38,26 +41,26 @@ ldbm_back_modify(
                }
                return( -1 );
        }
-       /* lock entry */
 
-       if ( (err = acl_check_mods( be, conn, op, e, mods )) != LDAP_SUCCESS ) {
+       if ( (err = acl_check_modlist( be, conn, op, e, modlist )) != LDAP_SUCCESS ) {
                send_ldap_result( conn, op, err, NULL, NULL );
-               cache_return_entry( &li->li_cache, e );
-               return( -1 );
+               goto error_return;
        }
 
-       for ( mod = mods; mod != NULL; mod = mod->mod_next ) {
+       for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
+               LDAPMod *mod = &ml->ml_mod;
+
                switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
                case LDAP_MOD_ADD:
-                       err = add_values( e, mod, op->o_dn );
+                       err = add_values( e, mod, op->o_ndn );
                        break;
 
                case LDAP_MOD_DELETE:
-                       err = delete_values( e, mod, op->o_dn );
+                       err = delete_values( e, mod, op->o_ndn );
                        break;
 
                case LDAP_MOD_REPLACE:
-                       err = replace_values( e, mod, op->o_dn );
+                       err = replace_values( e, mod, op->o_ndn );
                        break;
                }
 
@@ -68,14 +71,6 @@ ldbm_back_modify(
                }
        }
 
-       /* check for abandon */
-       pthread_mutex_lock( &op->o_abandonmutex );
-       if ( op->o_abandon ) {
-               pthread_mutex_unlock( &op->o_abandonmutex );
-               goto error_return;
-       }
-       pthread_mutex_unlock( &op->o_abandonmutex );
-
        /* check that the entry still obeys the schema */
        if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
                Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
@@ -83,19 +78,27 @@ ldbm_back_modify(
                goto error_return;
        }
 
+       /* check for abandon */
+       ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
+       if ( op->o_abandon ) {
+               ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
+               goto error_return;
+       }
+       ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
+
        /* modify indexes */
-       if ( index_add_mods( be, mods, e->e_id ) != 0 ) {
+       if ( index_add_mods( be, modlist, e->e_id ) != 0 ) {
                send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
                goto error_return;
        }
 
        /* check for abandon */
-       pthread_mutex_lock( &op->o_abandonmutex );
+       ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
        if ( op->o_abandon ) {
-               pthread_mutex_unlock( &op->o_abandonmutex );
+               ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
                goto error_return;
        }
-       pthread_mutex_unlock( &op->o_abandonmutex );
+       ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
 
        /* change the entry itself */
        if ( id2entry_add( be, e ) != 0 ) {
@@ -104,14 +107,11 @@ ldbm_back_modify(
        }
 
        send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
-       cache_return_entry( &li->li_cache, e );
-
+       cache_return_entry_w( &li->li_cache, e );
        return( 0 );
 
 error_return:;
-       cache_delete_entry( &li->li_cache, e );
-       cache_return_entry( &li->li_cache, e );
-
+       cache_return_entry_w( &li->li_cache, e );
        return( -1 );
 }