2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2015 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
23 #include <ac/socket.h>
24 #include <ac/string.h>
30 * A delete request looks like this:
31 * DelRequet ::= DistinguishedName,
35 ldap_build_delete_req(
45 /* create a message to send */
46 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
50 LDAP_NEXT_MSGID( ld, *msgidp );
51 rc = ber_printf( ber, "{its", /* '}' */
52 *msgidp, LDAP_REQ_DELETE, dn );
55 ld->ld_errno = LDAP_ENCODING_ERROR;
60 /* Put Server Controls */
61 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
66 if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
67 ld->ld_errno = LDAP_ENCODING_ERROR;
76 * ldap_delete_ext - initiate an ldap extended delete operation. Parameters:
79 * dn DN of the object to delete
80 * sctrls Server Controls
81 * cctrls Client Controls
82 * msgidp Message Id Pointer
85 * rc = ldap_delete( ld, dn, sctrls, cctrls, msgidp );
99 Debug( LDAP_DEBUG_TRACE, "ldap_delete_ext\n", 0, 0, 0 );
101 assert( ld != NULL );
102 assert( LDAP_VALID( ld ) );
103 assert( dn != NULL );
104 assert( msgidp != NULL );
106 /* check client controls */
107 rc = ldap_int_client_controls( ld, cctrls );
108 if( rc != LDAP_SUCCESS ) return rc;
110 ber = ldap_build_delete_req( ld, dn, sctrls, cctrls, &id );
114 /* send the message */
115 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_DELETE, dn, ber, id );
127 LDAPControl **sctrls,
128 LDAPControl **cctrls )
134 rc = ldap_delete_ext( ld, dn, sctrls, cctrls, &msgid );
136 if( rc != LDAP_SUCCESS )
137 return( ld->ld_errno );
139 if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) == -1 || !res )
140 return( ld->ld_errno );
142 return( ldap_result2error( ld, res, 1 ) );
145 * ldap_delete - initiate an ldap (and X.500) delete operation. Parameters:
148 * dn DN of the object to delete
151 * msgid = ldap_delete( ld, dn );
154 ldap_delete( LDAP *ld, LDAP_CONST char *dn )
159 * A delete request looks like this:
160 * DelRequet ::= DistinguishedName,
163 Debug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
165 return ldap_delete_ext( ld, dn, NULL, NULL, &msgid ) == LDAP_SUCCESS
171 ldap_delete_s( LDAP *ld, LDAP_CONST char *dn )
173 return ldap_delete_ext_s( ld, dn, NULL, NULL );