]> git.sur5r.net Git - openldap/blob - libraries/libldap/delete.c
5e8ea7605649f9716a073858410e4e2a906acf0a
[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 #include <ac/time.h>
19
20 #include "ldap-int.h"
21
22 /*
23  * ldap_delete - initiate an ldap (and X.500) delete operation. Parameters:
24  *
25  *      ld              LDAP descriptor
26  *      dn              DN of the object to delete
27  *
28  * Example:
29  *      msgid = ldap_delete( ld, dn );
30  */
31 int
32 ldap_delete( LDAP *ld, char *dn )
33 {
34         BerElement      *ber;
35
36         /*
37          * A delete request looks like this:
38          *      DelRequet ::= DistinguishedName,
39          */
40
41         Debug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
42
43         /* create a message to send */
44         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
45                 return( -1 );
46         }
47
48         if ( ber_printf( ber, "{its}", ++ld->ld_msgid, LDAP_REQ_DELETE, dn )
49             == -1 ) {
50                 ld->ld_errno = LDAP_ENCODING_ERROR;
51                 ber_free( ber, 1 );
52                 return( -1 );
53         }
54
55         /* send the message */
56         return ( ldap_send_initial_request( ld, LDAP_REQ_DELETE, dn, ber ));
57 }
58
59
60 int
61 ldap_delete_s( LDAP *ld, char *dn )
62 {
63         int             msgid;
64         LDAPMessage     *res;
65
66         if ( (msgid = ldap_delete( ld, dn )) == -1 )
67                 return( ld->ld_errno );
68
69         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
70                 return( ld->ld_errno );
71
72         return( ldap_result2error( ld, res, 1 ) );
73 }