/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2007 The OpenLDAP Foundation.
* Portions Copyright 1999 Dmitry Kovalev.
* Portions Copyright 2002 Pierangelo Masarati.
* All rights reserved.
RETCODE rc;
int prc = LDAP_SUCCESS;
backsql_oc_map_rec *oc = NULL;
- backsql_srch_info bsi;
+ backsql_srch_info bsi = { 0 };
backsql_entryID e_id = { 0 };
Entry d = { 0 }, p = { 0 }, *e = NULL;
struct berval pdn = BER_BVNULL;
int manageDSAit = get_manageDSAit( op );
/* first parameter no */
- SQLUSMALLINT pno;
- SQLUSMALLINT CompletionType = SQL_ROLLBACK;
+ SQLUSMALLINT pno = 0;
Debug( LDAP_DEBUG_TRACE, "==>backsql_delete(): deleting entry \"%s\"\n",
op->o_req_ndn.bv_val, 0, 0 );
* Get the entry
*/
bsi.bsi_e = &d;
- rc = backsql_init_search( &bsi, &op->o_req_ndn,
+ rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn,
LDAP_SCOPE_BASE,
- SLAP_NO_LIMIT, SLAP_NO_LIMIT,
(time_t)(-1), NULL, dbh, op, rs, slap_anlist_no_attrs,
( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) );
- switch ( rc ) {
+ switch ( rs->sr_err ) {
case LDAP_SUCCESS:
break;
case LDAP_REFERRAL:
- if ( !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
- dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname )
- && manageDSAit )
+ if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
+ dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname ) )
{
rs->sr_err = LDAP_SUCCESS;
rs->sr_text = NULL;
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
"could not retrieve deleteDN ID - no such entry\n",
0, 0, 0 );
+ if ( !BER_BVISNULL( &d.e_nname ) ) {
+ /* FIXME: should always be true! */
+ e = &d;
+
+ } else {
+ e = NULL;
+ }
+ goto done;
+ }
+
+ if ( get_assert( op ) &&
+ ( test_filter( op, &d, get_assertion( op ) )
+ != LDAP_COMPARE_TRUE ) )
+ {
+ rs->sr_err = LDAP_ASSERTION_FAILED;
+ e = &d;
goto done;
}
if ( !access_allowed( op, &d, slap_schema.si_ad_entry,
- NULL, ACL_WRITE, NULL ) )
+ NULL, ACL_WDEL, NULL ) )
{
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"no write access to entry\n",
goto done;
}
- rs->sr_err = backsql_has_children( bi, dbh, &op->o_req_ndn );
+ rs->sr_err = backsql_has_children( op, dbh, &op->o_req_ndn );
switch ( rs->sr_err ) {
case LDAP_COMPARE_FALSE:
rs->sr_err = LDAP_SUCCESS;
break;
case LDAP_COMPARE_TRUE:
+ if ( get_treeDelete( op ) ) {
+ /* not supported yet */ ;
+ }
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"entry \"%s\" has children\n",
op->o_req_dn.bv_val, 0, 0 );
rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
- rs->sr_text = "subtree delete not supported";
+ rs->sr_text = "subordinate objects must be deleted first";
/* fallthru */
default:
/*
* Get the parent
*/
- dnParent( &op->o_req_ndn, &pdn );
- bsi.bsi_e = &p;
e_id = bsi.bsi_base_id;
- rc = backsql_init_search( &bsi, &pdn,
- LDAP_SCOPE_BASE,
- SLAP_NO_LIMIT, SLAP_NO_LIMIT,
- (time_t)(-1), NULL, dbh, op, rs, slap_anlist_no_attrs,
- BACKSQL_ISF_GET_ENTRY );
- if ( rc != LDAP_SUCCESS ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
- "could not retrieve deleteDN ID - no such entry\n",
- 0, 0, 0 );
- e = &p;
- goto done;
- }
+ if ( !be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
+ dnParent( &op->o_req_ndn, &pdn );
+ bsi.bsi_e = &p;
+ rs->sr_err = backsql_init_search( &bsi, &pdn,
+ LDAP_SCOPE_BASE,
+ (time_t)(-1), NULL, dbh, op, rs,
+ slap_anlist_no_attrs,
+ BACKSQL_ISF_GET_ENTRY );
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
+ "could not retrieve deleteDN ID "
+ "- no such entry\n",
+ 0, 0, 0 );
+ e = &p;
+ goto done;
+ }
- (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+ (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
- /* check parent for "children" acl */
- if ( !access_allowed( op, &p, slap_schema.si_ad_children,
- NULL, ACL_WRITE, NULL ) )
- {
- Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
- "no write access to parent\n",
- 0, 0, 0 );
- rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
- e = &p;
- goto done;
+ /* check parent for "children" acl */
+ if ( !access_allowed( op, &p, slap_schema.si_ad_children,
+ NULL, ACL_WDEL, NULL ) )
+ {
+ Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
+ "no write access to parent\n",
+ 0, 0, 0 );
+ rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+ e = &p;
+ goto done;
+ }
}
/* avl_apply ... */
e = NULL;
goto done;
}
-
- } else {
- pno = 0;
}
rc = backsql_BindParamID( sth, pno + 1, SQL_PARAM_INPUT, &e_id.eid_keyval );
}
SQLFreeStmt( sth, SQL_DROP );
- /* delete referrals, if any... */
- rc = backsql_Prepare( dbh, &sth, bi->sql_delreferrals_stmt, 0 );
- if ( rc != SQL_SUCCESS ) {
- Debug( LDAP_DEBUG_TRACE,
- " backsql_delete(): "
- "error preparing ldap_referrals delete query\n",
- 0, 0, 0 );
- backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
-
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- e = NULL;
- goto done;
- }
-
- rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
- if ( rc != SQL_SUCCESS ) {
- Debug( LDAP_DEBUG_TRACE,
- " backsql_delete(): "
- "error binding referrals entry ID parameter "
- "for objectClass %s\n",
- oc->bom_oc->soc_cname.bv_val, 0, 0 );
- backsql_PrintErrors( bi->sql_db_env, dbh,
- sth, rc );
- SQLFreeStmt( sth, SQL_DROP );
-
- rs->sr_text = "SQL-backend error";
- rs->sr_err = LDAP_OTHER;
- e = NULL;
- goto done;
- }
-
- rc = SQLExecute( sth );
- switch ( rc ) {
- case SQL_NO_DATA:
- /* apparently there were no referrals
- * for this entry... */
- case SQL_SUCCESS:
- break;
-
- default:
- Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
- "failed to delete record from ldap_referrals\n",
- 0, 0, 0 );
- backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
- SQLFreeStmt( sth, SQL_DROP );
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- e = NULL;
- goto done;
- }
- SQLFreeStmt( sth, SQL_DROP );
-
/* delete entry... */
rc = backsql_Prepare( dbh, &sth, bi->sql_delentry_stmt, 0 );
if ( rc != SQL_SUCCESS ) {
rs->sr_err = LDAP_SUCCESS;
-done:;
-
/*
* Commit only if all operations succeed
- *
- * FIXME: backsql_add() does not fail if add operations
- * are not available for some attributes, or if
- * a multiple value add actually results in a replace,
- * or if a single operation on an attribute fails
- * for any reason
*/
- if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
- CompletionType = SQL_COMMIT;
+ if ( sth != SQL_NULL_HSTMT ) {
+ SQLUSMALLINT CompletionType = SQL_ROLLBACK;
+
+ if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+ assert( e == NULL );
+ CompletionType = SQL_COMMIT;
+ }
+
+ SQLTransact( SQL_NULL_HENV, dbh, CompletionType );
}
- SQLTransact( SQL_NULL_HENV, dbh, CompletionType );
-#ifdef SLAP_ACL_HONOR_DISCLOSE
+done:;
if ( e != NULL ) {
if ( !access_allowed( op, e, slap_schema.si_ad_entry, NULL,
ACL_DISCLOSE, NULL ) )
}
}
-#endif /* SLAP_ACL_HONOR_DISCLOSE */
+ if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
+ rs->sr_err = LDAP_X_NO_OPERATION;
+ }
send_ldap_result( op, rs );
}
if ( !BER_BVISNULL( &d.e_nname ) ) {
- entry_clean( &d );
+ backsql_entry_clean( op, &d );
}
if ( !BER_BVISNULL( &p.e_nname ) ) {
- entry_clean( &p );
+ backsql_entry_clean( op, &p );
+ }
+
+ if ( rs->sr_ref ) {
+ ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
}
return rs->sr_err;