17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
37c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
47c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
57c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
67c478bd9Sstevel@tonic-gate *
77c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
87c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
97c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing
107c478bd9Sstevel@tonic-gate * rights and limitations under the License.
117c478bd9Sstevel@tonic-gate *
127c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
137c478bd9Sstevel@tonic-gate * March 31, 1998.
147c478bd9Sstevel@tonic-gate *
157c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
167c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
177c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
187c478bd9Sstevel@tonic-gate * Rights Reserved.
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * Contributor(s):
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * delete.c
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #if 0
27*1da57d55SToomas Soome #ifndef lint
287c478bd9Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
297c478bd9Sstevel@tonic-gate #endif
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include "ldap-int.h"
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate * ldap_delete - initiate an ldap delete operation. Parameters:
367c478bd9Sstevel@tonic-gate *
377c478bd9Sstevel@tonic-gate * ld LDAP descriptor
387c478bd9Sstevel@tonic-gate * dn DN of the object to delete
397c478bd9Sstevel@tonic-gate *
407c478bd9Sstevel@tonic-gate * Example:
417c478bd9Sstevel@tonic-gate * msgid = ldap_delete( ld, dn );
427c478bd9Sstevel@tonic-gate */
437c478bd9Sstevel@tonic-gate int
447c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete(LDAP * ld,const char * dn)457c478bd9Sstevel@tonic-gate ldap_delete( LDAP *ld, const char *dn )
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate int msgid;
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate LDAPDebug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate if ( ldap_delete_ext( ld, dn, NULL, NULL, &msgid ) == LDAP_SUCCESS ) {
527c478bd9Sstevel@tonic-gate return( msgid );
537c478bd9Sstevel@tonic-gate } else {
547c478bd9Sstevel@tonic-gate return( -1 ); /* error is in ld handle */
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate int
597c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete_ext(LDAP * ld,const char * dn,LDAPControl ** serverctrls,LDAPControl ** clientctrls,int * msgidp)607c478bd9Sstevel@tonic-gate ldap_delete_ext( LDAP *ld, const char *dn, LDAPControl **serverctrls,
617c478bd9Sstevel@tonic-gate LDAPControl **clientctrls, int *msgidp )
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate BerElement *ber;
647c478bd9Sstevel@tonic-gate int rc, lderr;
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate * A delete request looks like this:
687c478bd9Sstevel@tonic-gate * DelRequet ::= DistinguishedName,
697c478bd9Sstevel@tonic-gate */
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate LDAPDebug( LDAP_DEBUG_TRACE, "ldap_delete_ext\n", 0, 0, 0 );
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
747c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate
77*1da57d55SToomas Soome if ( !NSLDAPI_VALID_LDAPMESSAGE_POINTER( msgidp ))
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
807c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate if ( dn == NULL ) {
837c478bd9Sstevel@tonic-gate dn = "";
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate LDAP_MUTEX_LOCK( ld, LDAP_MSGID_LOCK );
877c478bd9Sstevel@tonic-gate *msgidp = ++ld->ld_msgid;
887c478bd9Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, LDAP_MSGID_LOCK );
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate /* see if we should add to the cache */
917c478bd9Sstevel@tonic-gate if ( ld->ld_cache_on && ld->ld_cache_delete != NULL ) {
927c478bd9Sstevel@tonic-gate LDAP_MUTEX_LOCK( ld, LDAP_CACHE_LOCK );
937c478bd9Sstevel@tonic-gate if ( (rc = (ld->ld_cache_delete)( ld, *msgidp, LDAP_REQ_DELETE,
947c478bd9Sstevel@tonic-gate dn )) != 0 ) {
957c478bd9Sstevel@tonic-gate *msgidp = rc;
967c478bd9Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
977c478bd9Sstevel@tonic-gate return( LDAP_SUCCESS );
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /* create a message to send */
1037c478bd9Sstevel@tonic-gate if (( lderr = nsldapi_alloc_ber_with_options( ld, &ber ))
1047c478bd9Sstevel@tonic-gate != LDAP_SUCCESS ) {
1057c478bd9Sstevel@tonic-gate return( lderr );
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate if ( ber_printf( ber, "{its", *msgidp, LDAP_REQ_DELETE, dn )
1097c478bd9Sstevel@tonic-gate == -1 ) {
1107c478bd9Sstevel@tonic-gate lderr = LDAP_ENCODING_ERROR;
1117c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, lderr, NULL, NULL );
1127c478bd9Sstevel@tonic-gate ber_free( ber, 1 );
1137c478bd9Sstevel@tonic-gate return( lderr );
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate if (( lderr = nsldapi_put_controls( ld, serverctrls, 1, ber ))
1177c478bd9Sstevel@tonic-gate != LDAP_SUCCESS ) {
1187c478bd9Sstevel@tonic-gate ber_free( ber, 1 );
1197c478bd9Sstevel@tonic-gate return( lderr );
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate /* send the message */
1237c478bd9Sstevel@tonic-gate rc = nsldapi_send_initial_request( ld, *msgidp, LDAP_REQ_DELETE,
1247c478bd9Sstevel@tonic-gate (char *)dn, ber );
1257c478bd9Sstevel@tonic-gate *msgidp = rc;
1267c478bd9Sstevel@tonic-gate return( rc < 0 ? LDAP_GET_LDERRNO( ld, NULL, NULL ) : LDAP_SUCCESS );
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate int
1307c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete_s(LDAP * ld,const char * dn)1317c478bd9Sstevel@tonic-gate ldap_delete_s( LDAP *ld, const char *dn )
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate return( ldap_delete_ext_s( ld, dn, NULL, NULL ));
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate int
1377c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_delete_ext_s(LDAP * ld,const char * dn,LDAPControl ** serverctrls,LDAPControl ** clientctrls)1387c478bd9Sstevel@tonic-gate ldap_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
1397c478bd9Sstevel@tonic-gate LDAPControl **clientctrls )
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate int err, msgid;
1427c478bd9Sstevel@tonic-gate LDAPMessage *res;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate if (( err = ldap_delete_ext( ld, dn, serverctrls, clientctrls,
1457c478bd9Sstevel@tonic-gate &msgid )) != LDAP_SUCCESS ) {
1467c478bd9Sstevel@tonic-gate return( err );
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate if ( ldap_result( ld, msgid, 1, (struct timeval *)NULL, &res ) == -1 ) {
1507c478bd9Sstevel@tonic-gate return( LDAP_GET_LDERRNO( ld, NULL, NULL ) );
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate return( ldap_result2error( ld, res, 1 ) );
1547c478bd9Sstevel@tonic-gate }
155