Home | History | Annotate | Line # | Download | only in back-meta
      1 /*	$NetBSD: delete.c,v 1.4 2025/09/05 21:16:28 christos Exp $	*/
      2 
      3 /* $OpenLDAP$ */
      4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      5  *
      6  * Copyright 1999-2024 The OpenLDAP Foundation.
      7  * Portions Copyright 2001-2003 Pierangelo Masarati.
      8  * Portions Copyright 1999-2003 Howard Chu.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted only as authorized by the OpenLDAP
     13  * Public License.
     14  *
     15  * A copy of this license is available in the file LICENSE in the
     16  * top-level directory of the distribution or, alternatively, at
     17  * <http://www.OpenLDAP.org/license.html>.
     18  */
     19 /* ACKNOWLEDGEMENTS:
     20  * This work was initially developed by the Howard Chu for inclusion
     21  * in OpenLDAP Software and subsequently enhanced by Pierangelo
     22  * Masarati.
     23  */
     24 
     25 #include <sys/cdefs.h>
     26 __RCSID("$NetBSD: delete.c,v 1.4 2025/09/05 21:16:28 christos Exp $");
     27 
     28 #include "portable.h"
     29 
     30 #include <stdio.h>
     31 
     32 #include <ac/string.h>
     33 #include <ac/socket.h>
     34 
     35 #include "slap.h"
     36 #include "../back-ldap/back-ldap.h"
     37 #include "back-meta.h"
     38 
     39 int
     40 meta_back_delete( Operation *op, SlapReply *rs )
     41 {
     42 	metainfo_t	*mi = ( metainfo_t * )op->o_bd->be_private;
     43 	metatarget_t	*mt;
     44 	metaconn_t	*mc = NULL;
     45 	int		candidate = -1;
     46 	struct berval	mdn = BER_BVNULL;
     47 	dncookie	dc;
     48 	int		msgid;
     49 	ldap_back_send_t	retrying = LDAP_BACK_RETRYING;
     50 	LDAPControl	**ctrls = NULL;
     51 	SlapReply *candidates = NULL;
     52 
     53 	candidates = meta_back_candidates_get( op );
     54 	mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR, candidates );
     55 	if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR, candidates ) ) {
     56 		op->o_tmpfree( candidates, op->o_tmpmemctx );
     57 		return rs->sr_err;
     58 	}
     59 
     60 	assert( mc->mc_conns[ candidate ].msc_ld != NULL );
     61 
     62 	/*
     63 	 * Rewrite the compare dn, if needed
     64 	 */
     65 	mt = mi->mi_targets[ candidate ];
     66 	dc.target = mt;
     67 	dc.conn = op->o_conn;
     68 	dc.rs = rs;
     69 	dc.ctx = "deleteDN";
     70 
     71 	if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
     72 		send_ldap_result( op, rs );
     73 		goto cleanup;
     74 	}
     75 
     76 retry:;
     77 	ctrls = op->o_ctrls;
     78 	if ( meta_back_controls_add( op, rs, mc, candidate, &ctrls ) != LDAP_SUCCESS )
     79 	{
     80 		send_ldap_result( op, rs );
     81 		goto cleanup;
     82 	}
     83 
     84 	rs->sr_err = ldap_delete_ext( mc->mc_conns[ candidate ].msc_ld,
     85 			mdn.bv_val, ctrls, NULL, &msgid );
     86 	rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
     87 		mt->mt_timeout[ SLAP_OP_DELETE ], ( LDAP_BACK_SENDRESULT | retrying ) );
     88 	if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) {
     89 		retrying &= ~LDAP_BACK_RETRYING;
     90 		if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR, candidates ) ) {
     91 			/* if the identity changed, there might be need to re-authz */
     92 			(void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
     93 			goto retry;
     94 		}
     95 	}
     96 
     97 cleanup:;
     98 	(void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
     99 
    100 	if ( mdn.bv_val != op->o_req_dn.bv_val ) {
    101 		free( mdn.bv_val );
    102 		BER_BVZERO( &mdn );
    103 	}
    104 
    105 	if ( mc ) {
    106 		meta_back_release_conn( mi, mc );
    107 	}
    108 
    109 	op->o_tmpfree( candidates, op->o_tmpmemctx );
    110 	return rs->sr_err;
    111 }
    112 
    113