]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/add.c
Fix typo
[openldap] / servers / slapd / back-bdb / add.c
index 983ddd9dba9c5c56ab6d25c083c8f70a85c7885c..286c44f864e638731176995a4744a76858578b09 100644 (file)
@@ -23,11 +23,12 @@ bdb_add(
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        struct berval   pdn;
        Entry           *p = NULL;
-       int             rc, ret
+       int             rc; 
        const char      *text;
        char textbuf[SLAP_TEXT_BUFLEN];
        size_t textlen = sizeof textbuf;
        AttributeDescription *children = slap_schema.si_ad_children;
+       AttributeDescription *entry = slap_schema.si_ad_entry;
        DB_TXN          *ltid = NULL;
        struct bdb_op_info opinfo;
 #ifdef BDB_SUBENTRIES
@@ -39,6 +40,11 @@ bdb_add(
        u_int32_t       lockid;
        DB_LOCK         lock;
 #endif
+       int             noop = 0;
+
+#ifdef LDAP_CLIENT_UPDATE
+       Operation* ps_list;
+#endif
 
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ARGS, "==> bdb_add: %s\n", e->e_dn, 0, 0 );
@@ -85,6 +91,11 @@ bdb_add(
 
        if( 0 ) {
 retry: /* transaction retry */
+               if( p ) {
+                       /* free parent and reader lock */
+                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
+                       p = NULL;
+               }
                rc = TXN_ABORT( ltid );
                ltid = NULL;
                op->o_private = NULL;
@@ -207,9 +218,6 @@ retry:      /* transaction retry */
                switch( opinfo.boi_err ) {
                case DB_LOCK_DEADLOCK:
                case DB_LOCK_NOTGRANTED:
-                       /* free parent and reader lock */
-                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
-                       p = NULL;
                        goto retry;
                }
 
@@ -297,12 +305,14 @@ retry:    /* transaction retry */
                 */
                if ( !be_isroot( be, &op->o_ndn )) {
                        if ( be_issuffix( be, (struct berval *)&slap_empty_bv )
-                               || be_isupdate( be, &op->o_ndn ) ) {
+                               || be_isupdate( be, &op->o_ndn ) )
+                       {
                                p = (Entry *)&slap_entry_root;
 
                                /* check parent for "children" acl */
                                rc = access_allowed( be, conn, op, p,
                                        children, NULL, ACL_WRITE, NULL );
+
                                p = NULL;
 
                                switch( opinfo.boi_err ) {
@@ -365,6 +375,28 @@ retry:     /* transaction retry */
 #endif
        }
 
+       rc = access_allowed( be, conn, op, e,
+               entry, NULL, ACL_WRITE, NULL );
+
+       switch( opinfo.boi_err ) {
+       case DB_LOCK_DEADLOCK:
+       case DB_LOCK_NOTGRANTED:
+               goto retry;
+       }
+
+       if ( ! rc ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG ( OPERATION, DETAIL1, 
+                       "bdb_add: no write access to entry\n", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_TRACE, "bdb_add: no write access to entry\n",
+                       0, 0, 0 );
+#endif
+               rc = LDAP_INSUFFICIENT_ACCESS;
+               text = "no write access to entry";
+               goto return_results;;
+       }
+
        /* dn2id index */
        rc = bdb_dn2id_add( be, ltid, &pdn, e );
        if ( rc != 0 ) {
@@ -430,10 +462,12 @@ retry:    /* transaction retry */
                goto return_results;
        }
 
+
        if( op->o_noop ) {
                if (( rc=TXN_ABORT( ltid )) != 0 ) {
                        text = "txn_abort (no-op) failed";
                } else {
+                       noop = 1;
                        rc = LDAP_SUCCESS;
                }
 
@@ -447,7 +481,9 @@ retry:      /* transaction retry */
                        text = "txn_prepare failed";
 
                } else {
-                       ret = bdb_cache_add_entry_rw(bdb->bi_dbenv, &bdb->bi_cache, e, CACHE_WRITE_LOCK, locker, &lock);
+                       int ret = bdb_cache_add_entry_rw(bdb->bi_dbenv,
+                                       &bdb->bi_cache, e, CACHE_WRITE_LOCK,
+                                       locker, &lock);
 #if 0
                        if ( bdb_cache_add_entry_rw(&bdb->bi_cache,
                                e, CACHE_WRITE_LOCK) != 0 )
@@ -492,7 +528,9 @@ retry:      /* transaction retry */
                        op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn );
 #endif
                text = NULL;
-               bdb_cache_entry_commit( e );
+               if ( !noop ) {
+                       bdb_cache_entry_commit( e );
+               }
        }
        else {
 #ifdef NEW_LOGGING
@@ -509,6 +547,14 @@ return_results:
        send_ldap_result( conn, op, rc,
                NULL, text, NULL, NULL );
 
+#ifdef LDAP_CLIENT_UPDATE
+       if ( rc == LDAP_SUCCESS && !noop ) {
+               LDAP_LIST_FOREACH ( ps_list, &bdb->psearch_list, link ) {
+                       bdb_psearch( be, conn, op, ps_list, e, LCUP_PSEARCH_BY_ADD );
+               }
+       }
+#endif /* LDAP_CLIENT_UPDATE */
+
        if( rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
                ldap_pvt_thread_yield();
                TXN_CHECKPOINT( bdb->bi_dbenv,
@@ -522,5 +568,6 @@ done:
                op->o_private = NULL;
        }
 
-       return rc;
+       return ( ( rc == LDAP_SUCCESS ) ? noop : rc );
 }
+