]> git.sur5r.net Git - openldap/blob - libraries/libldap/delete.c
a6ebfecd50ef68248f08e8b0564465b5252e7323
[openldap] / libraries / libldap / delete.c
1 /*
2  *  Copyright (c) 1990 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  delete.c
6  */
7
8 #include "portable.h"
9
10 #ifndef lint 
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
12 #endif
13
14 #include <stdio.h>
15
16 #include <ac/socket.h>
17 #include <ac/string.h>
18
19 #include "lber.h"
20 #include "ldap.h"
21 #include "ldap-int.h"
22
23 /*
24  * ldap_delete - initiate an ldap (and X.500) delete operation. Parameters:
25  *
26  *      ld              LDAP descriptor
27  *      dn              DN of the object to delete
28  *
29  * Example:
30  *      msgid = ldap_delete( ld, dn );
31  */
32 int
33 ldap_delete( LDAP *ld, char *dn )
34 {
35         BerElement      *ber;
36
37         /*
38          * A delete request looks like this:
39          *      DelRequet ::= DistinguishedName,
40          */
41
42         Debug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
43
44         /* create a message to send */
45         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
46                 return( -1 );
47         }
48
49         if ( ber_printf( ber, "{its}", ++ld->ld_msgid, LDAP_REQ_DELETE, dn )
50             == -1 ) {
51                 ld->ld_errno = LDAP_ENCODING_ERROR;
52                 ber_free( ber, 1 );
53                 return( -1 );
54         }
55
56         /* send the message */
57         return ( ldap_send_initial_request( ld, LDAP_REQ_DELETE, dn, ber ));
58 }
59
60
61 int
62 ldap_delete_s( LDAP *ld, char *dn )
63 {
64         int             msgid;
65         LDAPMessage     *res;
66
67         if ( (msgid = ldap_delete( ld, dn )) == -1 )
68                 return( ld->ld_errno );
69
70         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
71                 return( ld->ld_errno );
72
73         return( ldap_result2error( ld, res, 1 ) );
74 }