Back to index

openldap  2.4.31
delete.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1999-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 2001-2003 Pierangelo Masarati.
00006  * Portions Copyright 1999-2003 Howard Chu.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This work was initially developed by the Howard Chu for inclusion
00019  * in OpenLDAP Software and subsequently enhanced by Pierangelo
00020  * Masarati.
00021  */
00022 
00023 #include "portable.h"
00024 
00025 #include <stdio.h>
00026 
00027 #include <ac/string.h>
00028 #include <ac/socket.h>
00029 
00030 #include "slap.h"
00031 #include "../back-ldap/back-ldap.h"
00032 #include "back-meta.h"
00033 
00034 int
00035 meta_back_delete( Operation *op, SlapReply *rs )
00036 {
00037        metainfo_t    *mi = ( metainfo_t * )op->o_bd->be_private;
00038        metatarget_t  *mt;
00039        metaconn_t    *mc = NULL;
00040        int           candidate = -1;
00041        struct berval mdn = BER_BVNULL;
00042        dncookie      dc;
00043        int           msgid;
00044        ldap_back_send_t     retrying = LDAP_BACK_RETRYING;
00045        LDAPControl   **ctrls = NULL;
00046 
00047        mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
00048        if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
00049               return rs->sr_err;
00050        }
00051 
00052        assert( mc->mc_conns[ candidate ].msc_ld != NULL );
00053 
00054        /*
00055         * Rewrite the compare dn, if needed
00056         */
00057        mt = mi->mi_targets[ candidate ];
00058        dc.target = mt;
00059        dc.conn = op->o_conn;
00060        dc.rs = rs;
00061        dc.ctx = "deleteDN";
00062 
00063        if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
00064               send_ldap_result( op, rs );
00065               goto cleanup;
00066        }
00067 
00068 retry:;
00069        ctrls = op->o_ctrls;
00070        if ( meta_back_controls_add( op, rs, mc, candidate, &ctrls ) != LDAP_SUCCESS )
00071        {
00072               send_ldap_result( op, rs );
00073               goto cleanup;
00074        }
00075 
00076        rs->sr_err = ldap_delete_ext( mc->mc_conns[ candidate ].msc_ld,
00077                      mdn.bv_val, ctrls, NULL, &msgid );
00078        rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
00079               mt->mt_timeout[ SLAP_OP_DELETE ], ( LDAP_BACK_SENDRESULT | retrying ) );
00080        if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) {
00081               retrying &= ~LDAP_BACK_RETRYING;
00082               if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR ) ) {
00083                      /* if the identity changed, there might be need to re-authz */
00084                      (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
00085                      goto retry;
00086               }
00087        }
00088 
00089 cleanup:;
00090        (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
00091 
00092        if ( mdn.bv_val != op->o_req_dn.bv_val ) {
00093               free( mdn.bv_val );
00094               BER_BVZERO( &mdn );
00095        }
00096        
00097        if ( mc ) {
00098               meta_back_release_conn( mi, mc );
00099        }
00100 
00101        return rs->sr_err;
00102 }
00103