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