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/>.
|
|
|
|
*
|
2009-01-22 08:40:04 +08:00
|
|
|
* Copyright 1998-2009 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:
|
|
|
|
* DelRequet ::= DistinguishedName,
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-03-28 03:18:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_delete_ext\n", 0, 0, 0 );
|
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;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* create a message to send */
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
1999-05-19 09:12:33 +08:00
|
|
|
ld->ld_errno = LDAP_NO_MEMORY;
|
|
|
|
return( ld->ld_errno );
|
|
|
|
}
|
|
|
|
|
2003-02-14 07:02:31 +08:00
|
|
|
LDAP_NEXT_MSGID( ld, id );
|
|
|
|
rc = ber_printf( ber, "{its", /* '}' */
|
|
|
|
id, LDAP_REQ_DELETE, dn );
|
|
|
|
if ( rc == -1 )
|
1999-05-19 09:12:33 +08:00
|
|
|
{
|
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return( ld->ld_errno );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put Server Controls */
|
|
|
|
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return ld->ld_errno;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2000-06-24 09:40:39 +08:00
|
|
|
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
ber_free( ber, 1 );
|
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:
|
|
|
|
* DelRequet ::= DistinguishedName,
|
|
|
|
*/
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|