Back to index

openldap  2.4.31
delete.c
Go to the documentation of this file.
00001 /* delete.c - ldap backend delete function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2003-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 1999-2003 Howard Chu.
00007  * Portions Copyright 2000-2003 Pierangelo Masarati.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted only as authorized by the OpenLDAP
00012  * Public License.
00013  *
00014  * A copy of this license is available in the file LICENSE in the
00015  * top-level directory of the distribution or, alternatively, at
00016  * <http://www.OpenLDAP.org/license.html>.
00017  */
00018 /* ACKNOWLEDGEMENTS:
00019  * This work was initially developed by the Howard Chu for inclusion
00020  * in OpenLDAP Software and subsequently enhanced by Pierangelo
00021  * Masarati.
00022  */
00023 
00024 #include "portable.h"
00025 
00026 #include <stdio.h>
00027 
00028 #include <ac/string.h>
00029 #include <ac/socket.h>
00030 
00031 #include "slap.h"
00032 #include "back-ldap.h"
00033 
00034 int
00035 ldap_back_delete(
00036               Operation     *op,
00037               SlapReply     *rs )
00038 {
00039        ldapinfo_t           *li = (ldapinfo_t *)op->o_bd->be_private;
00040 
00041        ldapconn_t           *lc = NULL;
00042        ber_int_t            msgid;
00043        LDAPControl          **ctrls = NULL;
00044        ldap_back_send_t     retrying = LDAP_BACK_RETRYING;
00045        int                  rc = LDAP_SUCCESS;
00046 
00047        if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
00048               return rs->sr_err;
00049        }
00050 
00051 retry:
00052        ctrls = op->o_ctrls;
00053        rc = ldap_back_controls_add( op, rs, lc, &ctrls );
00054        if ( rc != LDAP_SUCCESS ) {
00055               send_ldap_result( op, rs );
00056               rc = rs->sr_err;
00057               goto cleanup;
00058        }
00059 
00060        rs->sr_err = ldap_delete_ext( lc->lc_ld, op->o_req_dn.bv_val,
00061                      ctrls, NULL, &msgid );
00062        rc = ldap_back_op_result( lc, op, rs, msgid,
00063               li->li_timeout[ SLAP_OP_DELETE ],
00064               ( LDAP_BACK_SENDRESULT | retrying ) );
00065        if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) {
00066               retrying &= ~LDAP_BACK_RETRYING;
00067               if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
00068                      /* if the identity changed, there might be need to re-authz */
00069                      (void)ldap_back_controls_free( op, rs, &ctrls );
00070                      goto retry;
00071               }
00072        }
00073 
00074 cleanup:
00075        (void)ldap_back_controls_free( op, rs, &ctrls );
00076 
00077        if ( lc != NULL ) {
00078               ldap_back_release_conn( li, lc );
00079        }
00080 
00081        return rc;
00082 }