]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/add.c
return structuralObjectClass errors
[openldap] / servers / slapd / back-bdb / add.c
index bb9cd4cb2e4874053e050e0beebfd07211a2348e..b66f19f6db0f36154bf0f5b0def3f8d6a2b68170 100644 (file)
@@ -44,18 +44,66 @@ bdb_add(Operation *op, SlapReply *rs )
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
 
+#ifdef LDAP_X_TXN
+       int settle = 0;
+#endif
+
        Debug(LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(bdb_add) ": %s\n",
                op->oq_add.rs_e->e_name.bv_val, 0, 0);
 
+#ifdef LDAP_X_TXN
+       if( op->o_txnSpec ) {
+               /* acquire connection lock */
+               ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
+               if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) {
+                       rs->sr_text = "invalid transaction identifier";
+                       rs->sr_err = LDAP_X_TXN_ID_INVALID;
+                       goto txnReturn;
+               } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) {
+                       settle=1;
+                       goto txnReturn;
+               }
+
+               if( op->o_conn->c_txn_backend == NULL ) {
+                       op->o_conn->c_txn_backend = op->o_bd;
+
+               } else if( op->o_conn->c_txn_backend != op->o_bd ) {
+                       rs->sr_text = "transaction cannot span multiple database contexts";
+                       rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
+                       goto txnReturn;
+               }
+
+               /* insert operation into transaction */
+
+               rs->sr_text = "transaction specified";
+               rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY;
+
+txnReturn:
+               /* release connection lock */
+               ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
+
+               if( !settle ) {
+                       send_ldap_result( op, rs );
+                       return rs->sr_err;
+               }
+       }
+#endif
+
        ctrls[num_ctrls] = 0;
 
        /* add opattrs to shadow as well, only missing attrs will actually
         * be added; helps compatibility with older OL versions */
-       slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
+       rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
+       if ( rs->sr_err != LDAP_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       LDAP_XSTRING(bdb_add) ": entry failed op attrs add: "
+                       "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
+               goto return_results;
+       }
 
        /* check entry's schema */
        rs->sr_err = entry_schema_check( op, op->oq_add.rs_e, NULL,
-               get_manageDIT(op), &rs->sr_text, textbuf, textlen );
+               get_relax(op), &rs->sr_text, textbuf, textlen );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        LDAP_XSTRING(bdb_add) ": entry failed schema check: "
@@ -83,7 +131,9 @@ bdb_add(Operation *op, SlapReply *rs )
 retry: /* transaction retry */
                if( p ) {
                        /* free parent and reader lock */
-                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
+                       if ( p != (Entry *)&slap_entry_root ) {
+                               bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
+                       }
                        p = NULL;
                }
                rs->sr_err = TXN_ABORT( ltid );
@@ -99,7 +149,6 @@ retry:       /* transaction retry */
                        rs->sr_err = SLAPD_ABANDON;
                        goto return_results;
                }
-               ldap_pvt_thread_yield();
                bdb_trans_backoff( ++num_retries );
        }
 
@@ -156,42 +205,45 @@ retry:    /* transaction retry */
        }
 
        p = ei->bei_e;
-       if ( p ) {
-               if ( !bvmatch( &pdn, &p->e_nname ) ) {
-                       rs->sr_matched = ber_strdup_x( p->e_name.bv_val,
-                               op->o_tmpmemctx );
-                       rs->sr_ref = is_entry_referral( p )
-                               ? get_entry_referrals( op, p )
-                               : NULL;
-                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
-                       p = NULL;
-                       Debug( LDAP_DEBUG_TRACE,
-                               LDAP_XSTRING(bdb_add) ": parent "
-                               "does not exist\n", 0, 0, 0 );
-
-                       rs->sr_err = LDAP_REFERRAL;
-                       rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
-                       goto return_results;
-               }
+       if ( !p )
+               p = (Entry *)&slap_entry_root;
+
+       if ( !bvmatch( &pdn, &p->e_nname ) ) {
+               rs->sr_matched = ber_strdup_x( p->e_name.bv_val,
+                       op->o_tmpmemctx );
+               rs->sr_ref = is_entry_referral( p )
+                       ? get_entry_referrals( op, p )
+                       : NULL;
+               bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
+               p = NULL;
+               Debug( LDAP_DEBUG_TRACE,
+                       LDAP_XSTRING(bdb_add) ": parent "
+                       "does not exist\n", 0, 0, 0 );
 
-               rs->sr_err = access_allowed( op, p,
-                       children, NULL, ACL_WADD, NULL );
+               rs->sr_err = LDAP_REFERRAL;
+               rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+               goto return_results;
+       }
 
-               if ( ! rs->sr_err ) {
-                       switch( opinfo.boi_err ) {
-                       case DB_LOCK_DEADLOCK:
-                       case DB_LOCK_NOTGRANTED:
-                               goto retry;
-                       }
+       rs->sr_err = access_allowed( op, p,
+               children, NULL, ACL_WADD, NULL );
 
-                       Debug( LDAP_DEBUG_TRACE,
-                               LDAP_XSTRING(bdb_add) ": no write access to parent\n",
-                               0, 0, 0 );
-                       rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
-                       rs->sr_text = "no write access to parent";
-                       goto return_results;;
+       if ( ! rs->sr_err ) {
+               switch( opinfo.boi_err ) {
+               case DB_LOCK_DEADLOCK:
+               case DB_LOCK_NOTGRANTED:
+                       goto retry;
                }
 
+               Debug( LDAP_DEBUG_TRACE,
+                       LDAP_XSTRING(bdb_add) ": no write access to parent\n",
+                       0, 0, 0 );
+               rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+               rs->sr_text = "no write access to parent";
+               goto return_results;;
+       }
+
+       if ( p != (Entry *)&slap_entry_root ) {
                if ( is_entry_subentry( p ) ) {
                        /* parent is a subentry, don't allow add */
                        Debug( LDAP_DEBUG_TRACE,
@@ -201,6 +253,7 @@ retry:      /* transaction retry */
                        rs->sr_text = "parent is a subentry";
                        goto return_results;;
                }
+
                if ( is_entry_alias( p ) ) {
                        /* parent is an alias, don't allow add */
                        Debug( LDAP_DEBUG_TRACE,
@@ -231,27 +284,13 @@ retry:    /* transaction retry */
                        /* FIXME: */
                        /* parent must be an administrative point of the required kind */
                }
+       }
 
-               /* free parent and reader lock */
+       /* free parent and reader lock */
+       if ( p != (Entry *)&slap_entry_root ) {
                bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
-               p = NULL;
-
-       } else {
-               /*
-                * no parent!
-                *  if not attempting to add entry at suffix or with parent ""
-                */
-               if ((( !be_isroot( op ) && !be_shadow_update(op) )
-                       || pdn.bv_len > 0 ) && !is_entry_glue( op->oq_add.rs_e ))
-               {
-                       Debug( LDAP_DEBUG_TRACE,
-                               LDAP_XSTRING(bdb_add) ": %s denied\n",
-                               pdn.bv_len == 0 ? "suffix" : "entry at root",
-                               0, 0 );
-                       rs->sr_err = LDAP_NO_SUCH_OBJECT;
-                       goto return_results;
-               }
        }
+       p = NULL;
 
        rs->sr_err = access_allowed( op, op->oq_add.rs_e,
                entry, NULL, ACL_WADD, NULL );
@@ -411,21 +450,19 @@ retry:    /* transaction retry */
 
 return_results:
        send_ldap_result( op, rs );
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
 
        if( ltid != NULL ) {
                TXN_ABORT( ltid );
        }
        op->o_private = NULL;
 
-       if( postread_ctrl != NULL ) {
+       if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
                slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
                slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
        }
 
        if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
-               ldap_pvt_thread_yield();
                TXN_CHECKPOINT( bdb->bi_dbenv,
                        bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
        }