]> git.sur5r.net Git - openldap/blob - servers/ldapd/delete.c
Initial revision
[openldap] / servers / ldapd / delete.c
1 /*
2  * Copyright (c) 1990 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13 #include <stdio.h>
14 #include <quipu/commonarg.h>
15 #include <quipu/attrvalue.h>
16 #include <quipu/ds_error.h>
17 #include <quipu/remove.h>
18 #include <quipu/dap2.h>
19 #include <quipu/dua.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include "lber.h"
23 #include "ldap.h"
24 #include "common.h"
25
26 #ifdef COMPAT20
27 extern int      ldap_compat;
28 #define DELTAG  (ldap_compat == 20 ? OLD_LDAP_RES_DELETE : LDAP_RES_DELETE)
29 #else
30 #define DELTAG  LDAP_RES_DELETE
31 #endif
32
33 /*
34  * do_delete - Initiate an X.500 remove entry operation.  Returns 1 if
35  * the operation was initiated successfully, and thus a response will be
36  * coming back from the DSA.  Returns 0 if there was trouble and thus no
37  * DSA response is expected.
38  */
39
40 int
41 do_delete( 
42     Sockbuf     *clientsb,
43     struct msg  *m,
44     BerElement  *ber
45 )
46 {
47         char                            *dn;
48         int                             rc;
49         struct ds_removeentry_arg       ra;
50         static CommonArgs               common = default_common_args;
51         extern DN                       ldap_str2dn();
52
53         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
54
55         /*
56          * Parse the delete request.  It looks like this:
57          *      DelRequest := DistinguishedName
58          */
59
60 #if ISODEPACKAGE == IC
61 #if ICRELEASE > 2
62         DAS_RemoveEntryArgument_INIT( &ra );
63 #endif
64 #endif
65
66         if ( ber_scanf( ber, "a", &dn ) == LBER_ERROR ) {
67                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
68                 send_ldap_msgresult( clientsb, DELTAG, m,
69                     LDAP_PROTOCOL_ERROR, NULL, "" );
70                 return( 0 );
71         }
72
73         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 );
74
75         ra.rma_object = ldap_str2dn( dn );
76         free( dn );
77         if ( ra.rma_object == NULLDN ) {
78                 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
79                 send_ldap_msgresult( clientsb, DELTAG, m,
80                     LDAP_INVALID_DN_SYNTAX, NULL, "" );
81                 return( 0 );
82         }
83
84         ra.rma_common = common; /* struct copy */
85
86         rc = initiate_dap_operation( OP_REMOVEENTRY, m, &ra );
87
88         dn_free( ra.rma_object );
89
90         if ( rc != 0 ) {
91                 send_ldap_msgresult( clientsb, DELTAG, m, rc, NULL, "" );
92                 return( 0 );
93         }
94
95         return( 1 );
96 }
97
98 void
99 delete_result(
100     Sockbuf     *sb,
101     struct msg  *m
102 )
103 {
104         send_ldap_msgresult( sb, DELTAG, m, LDAP_SUCCESS, NULL, "" );
105
106         return;
107 }