1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2021-01-12 03:25:53 +08:00
|
|
|
* Copyright 1998-2021 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +08:00
|
|
|
* All rights reserved.
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
2003-11-26 15:16:36 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* Portions Copyright (c) 1990 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
1999-06-04 03:22:33 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
2006-10-28 03:37:04 +08:00
|
|
|
/*
|
|
|
|
* A delete request looks like this:
|
2017-02-26 15:49:31 +08:00
|
|
|
* DelRequest ::= DistinguishedName,
|
2006-10-28 03:37:04 +08:00
|
|
|
*/
|
|
|
|
|
2015-10-02 12:02:15 +08:00
|
|
|
BerElement *
|
|
|
|
ldap_build_delete_req(
|
|
|
|
LDAP *ld,
|
|
|
|
LDAP_CONST char *dn,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls,
|
|
|
|
int *msgidp )
|
|
|
|
{
|
|
|
|
BerElement *ber;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* create a message to send */
|
|
|
|
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
LDAP_NEXT_MSGID( ld, *msgidp );
|
|
|
|
rc = ber_printf( ber, "{its", /* '}' */
|
|
|
|
*msgidp, LDAP_REQ_DELETE, dn );
|
|
|
|
if ( rc == -1 )
|
|
|
|
{
|
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put Server Controls */
|
|
|
|
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( ber );
|
|
|
|
}
|
2006-10-28 03:37:04 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1999-05-19 09:12:33 +08:00
|
|
|
* ldap_delete_ext - initiate an ldap extended delete operation. Parameters:
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
|
|
|
* ld LDAP descriptor
|
|
|
|
* dn DN of the object to delete
|
1999-05-19 09:12:33 +08:00
|
|
|
* sctrls Server Controls
|
|
|
|
* cctrls Client Controls
|
|
|
|
* msgidp Message Id Pointer
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
|
|
|
* Example:
|
1999-05-19 09:12:33 +08:00
|
|
|
* rc = ldap_delete( ld, dn, sctrls, cctrls, msgidp );
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ldap_delete_ext(
|
|
|
|
LDAP *ld,
|
|
|
|
LDAP_CONST char* dn,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls,
|
|
|
|
int *msgidp )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
2001-07-06 11:13:42 +08:00
|
|
|
int rc;
|
1998-08-09 08:43:13 +08:00
|
|
|
BerElement *ber;
|
2003-02-14 07:02:31 +08:00
|
|
|
ber_int_t id;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2019-02-16 00:47:40 +08:00
|
|
|
Debug0( LDAP_DEBUG_TRACE, "ldap_delete_ext\n" );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-06-06 04:18:32 +08:00
|
|
|
assert( ld != NULL );
|
|
|
|
assert( LDAP_VALID( ld ) );
|
|
|
|
assert( dn != NULL );
|
|
|
|
assert( msgidp != NULL );
|
|
|
|
|
2001-07-06 11:13:42 +08:00
|
|
|
/* check client controls */
|
|
|
|
rc = ldap_int_client_controls( ld, cctrls );
|
|
|
|
if( rc != LDAP_SUCCESS ) return rc;
|
|
|
|
|
2015-10-02 12:02:15 +08:00
|
|
|
ber = ldap_build_delete_req( ld, dn, sctrls, cctrls, &id );
|
|
|
|
if( !ber )
|
1999-05-19 09:12:33 +08:00
|
|
|
return ld->ld_errno;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/* send the message */
|
2003-02-14 07:02:31 +08:00
|
|
|
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_DELETE, dn, ber, id );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
if(*msgidp < 0)
|
|
|
|
return ld->ld_errno;
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ldap_delete_ext_s(
|
|
|
|
LDAP *ld,
|
|
|
|
LDAP_CONST char *dn,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
int msgid;
|
|
|
|
int rc;
|
1998-08-09 08:43:13 +08:00
|
|
|
LDAPMessage *res;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
rc = ldap_delete_ext( ld, dn, sctrls, cctrls, &msgid );
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS )
|
1998-08-09 08:43:13 +08:00
|
|
|
return( ld->ld_errno );
|
|
|
|
|
2007-02-05 20:30:40 +08:00
|
|
|
if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) == -1 || !res )
|
1998-08-09 08:43:13 +08:00
|
|
|
return( ld->ld_errno );
|
|
|
|
|
|
|
|
return( ldap_result2error( ld, res, 1 ) );
|
|
|
|
}
|
1999-05-19 09:12:33 +08:00
|
|
|
/*
|
|
|
|
* ldap_delete - initiate an ldap (and X.500) delete operation. Parameters:
|
|
|
|
*
|
|
|
|
* ld LDAP descriptor
|
|
|
|
* dn DN of the object to delete
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* msgid = ldap_delete( ld, dn );
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_delete( LDAP *ld, LDAP_CONST char *dn )
|
|
|
|
{
|
|
|
|
int msgid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A delete request looks like this:
|
2017-02-26 15:49:31 +08:00
|
|
|
* DelRequest ::= DistinguishedName,
|
1999-05-19 09:12:33 +08:00
|
|
|
*/
|
|
|
|
|
2019-02-16 00:47:40 +08:00
|
|
|
Debug0( LDAP_DEBUG_TRACE, "ldap_delete\n" );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
return ldap_delete_ext( ld, dn, NULL, NULL, &msgid ) == LDAP_SUCCESS
|
|
|
|
? msgid : -1 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_delete_s( LDAP *ld, LDAP_CONST char *dn )
|
|
|
|
{
|
|
|
|
return ldap_delete_ext_s( ld, dn, NULL, NULL );
|
|
|
|
}
|