1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
3*7c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
4*7c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
5*7c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
6*7c478bd9Sstevel@tonic-gate *
7*7c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
8*7c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9*7c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing
10*7c478bd9Sstevel@tonic-gate * rights and limitations under the License.
11*7c478bd9Sstevel@tonic-gate *
12*7c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
13*7c478bd9Sstevel@tonic-gate * March 31, 1998.
14*7c478bd9Sstevel@tonic-gate *
15*7c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
16*7c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
17*7c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
18*7c478bd9Sstevel@tonic-gate * Rights Reserved.
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * Contributor(s):
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * delete.c
24*7c478bd9Sstevel@tonic-gate */
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate #if 0
27*7c478bd9Sstevel@tonic-gate #ifndef lint
28*7c478bd9Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
29*7c478bd9Sstevel@tonic-gate #endif
30*7c478bd9Sstevel@tonic-gate #endif
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include "ldap-int.h"
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate /*
35*7c478bd9Sstevel@tonic-gate * ldap_delete - initiate an ldap delete operation. Parameters:
36*7c478bd9Sstevel@tonic-gate *
37*7c478bd9Sstevel@tonic-gate * ld LDAP descriptor
38*7c478bd9Sstevel@tonic-gate * dn DN of the object to delete
39*7c478bd9Sstevel@tonic-gate *
40*7c478bd9Sstevel@tonic-gate * Example:
41*7c478bd9Sstevel@tonic-gate * msgid = ldap_delete( ld, dn );
42*7c478bd9Sstevel@tonic-gate */
43*7c478bd9Sstevel@tonic-gate int
44*7c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete(LDAP * ld,const char * dn)45*7c478bd9Sstevel@tonic-gate ldap_delete( LDAP *ld, const char *dn )
46*7c478bd9Sstevel@tonic-gate {
47*7c478bd9Sstevel@tonic-gate int msgid;
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate LDAPDebug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate if ( ldap_delete_ext( ld, dn, NULL, NULL, &msgid ) == LDAP_SUCCESS ) {
52*7c478bd9Sstevel@tonic-gate return( msgid );
53*7c478bd9Sstevel@tonic-gate } else {
54*7c478bd9Sstevel@tonic-gate return( -1 ); /* error is in ld handle */
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate }
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate int
59*7c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete_ext(LDAP * ld,const char * dn,LDAPControl ** serverctrls,LDAPControl ** clientctrls,int * msgidp)60*7c478bd9Sstevel@tonic-gate ldap_delete_ext( LDAP *ld, const char *dn, LDAPControl **serverctrls,
61*7c478bd9Sstevel@tonic-gate LDAPControl **clientctrls, int *msgidp )
62*7c478bd9Sstevel@tonic-gate {
63*7c478bd9Sstevel@tonic-gate BerElement *ber;
64*7c478bd9Sstevel@tonic-gate int rc, lderr;
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate /*
67*7c478bd9Sstevel@tonic-gate * A delete request looks like this:
68*7c478bd9Sstevel@tonic-gate * DelRequet ::= DistinguishedName,
69*7c478bd9Sstevel@tonic-gate */
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate LDAPDebug( LDAP_DEBUG_TRACE, "ldap_delete_ext\n", 0, 0, 0 );
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
74*7c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
75*7c478bd9Sstevel@tonic-gate }
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAPMESSAGE_POINTER( msgidp ))
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
80*7c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate if ( dn == NULL ) {
83*7c478bd9Sstevel@tonic-gate dn = "";
84*7c478bd9Sstevel@tonic-gate }
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate LDAP_MUTEX_LOCK( ld, LDAP_MSGID_LOCK );
87*7c478bd9Sstevel@tonic-gate *msgidp = ++ld->ld_msgid;
88*7c478bd9Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, LDAP_MSGID_LOCK );
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate /* see if we should add to the cache */
91*7c478bd9Sstevel@tonic-gate if ( ld->ld_cache_on && ld->ld_cache_delete != NULL ) {
92*7c478bd9Sstevel@tonic-gate LDAP_MUTEX_LOCK( ld, LDAP_CACHE_LOCK );
93*7c478bd9Sstevel@tonic-gate if ( (rc = (ld->ld_cache_delete)( ld, *msgidp, LDAP_REQ_DELETE,
94*7c478bd9Sstevel@tonic-gate dn )) != 0 ) {
95*7c478bd9Sstevel@tonic-gate *msgidp = rc;
96*7c478bd9Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
97*7c478bd9Sstevel@tonic-gate return( LDAP_SUCCESS );
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
100*7c478bd9Sstevel@tonic-gate }
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate /* create a message to send */
103*7c478bd9Sstevel@tonic-gate if (( lderr = nsldapi_alloc_ber_with_options( ld, &ber ))
104*7c478bd9Sstevel@tonic-gate != LDAP_SUCCESS ) {
105*7c478bd9Sstevel@tonic-gate return( lderr );
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate if ( ber_printf( ber, "{its", *msgidp, LDAP_REQ_DELETE, dn )
109*7c478bd9Sstevel@tonic-gate == -1 ) {
110*7c478bd9Sstevel@tonic-gate lderr = LDAP_ENCODING_ERROR;
111*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, lderr, NULL, NULL );
112*7c478bd9Sstevel@tonic-gate ber_free( ber, 1 );
113*7c478bd9Sstevel@tonic-gate return( lderr );
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate if (( lderr = nsldapi_put_controls( ld, serverctrls, 1, ber ))
117*7c478bd9Sstevel@tonic-gate != LDAP_SUCCESS ) {
118*7c478bd9Sstevel@tonic-gate ber_free( ber, 1 );
119*7c478bd9Sstevel@tonic-gate return( lderr );
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate /* send the message */
123*7c478bd9Sstevel@tonic-gate rc = nsldapi_send_initial_request( ld, *msgidp, LDAP_REQ_DELETE,
124*7c478bd9Sstevel@tonic-gate (char *)dn, ber );
125*7c478bd9Sstevel@tonic-gate *msgidp = rc;
126*7c478bd9Sstevel@tonic-gate return( rc < 0 ? LDAP_GET_LDERRNO( ld, NULL, NULL ) : LDAP_SUCCESS );
127*7c478bd9Sstevel@tonic-gate }
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate int
130*7c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete_s(LDAP * ld,const char * dn)131*7c478bd9Sstevel@tonic-gate ldap_delete_s( LDAP *ld, const char *dn )
132*7c478bd9Sstevel@tonic-gate {
133*7c478bd9Sstevel@tonic-gate return( ldap_delete_ext_s( ld, dn, NULL, NULL ));
134*7c478bd9Sstevel@tonic-gate }
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate int
137*7c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete_ext_s(LDAP * ld,const char * dn,LDAPControl ** serverctrls,LDAPControl ** clientctrls)138*7c478bd9Sstevel@tonic-gate ldap_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
139*7c478bd9Sstevel@tonic-gate LDAPControl **clientctrls )
140*7c478bd9Sstevel@tonic-gate {
141*7c478bd9Sstevel@tonic-gate int err, msgid;
142*7c478bd9Sstevel@tonic-gate LDAPMessage *res;
143*7c478bd9Sstevel@tonic-gate
144*7c478bd9Sstevel@tonic-gate if (( err = ldap_delete_ext( ld, dn, serverctrls, clientctrls,
145*7c478bd9Sstevel@tonic-gate &msgid )) != LDAP_SUCCESS ) {
146*7c478bd9Sstevel@tonic-gate return( err );
147*7c478bd9Sstevel@tonic-gate }
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gate if ( ldap_result( ld, msgid, 1, (struct timeval *)NULL, &res ) == -1 ) {
150*7c478bd9Sstevel@tonic-gate return( LDAP_GET_LDERRNO( ld, NULL, NULL ) );
151*7c478bd9Sstevel@tonic-gate }
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate return( ldap_result2error( ld, res, 1 ) );
154*7c478bd9Sstevel@tonic-gate }
155