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