]> git.sur5r.net Git - openldap/blob - servers/ldapd/delete.c
7c7b6ebfe86cb7ef75d62cf050490401cca49ed6
[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 "portable.h"
14
15 #include <stdio.h>
16 /* ac/socket.h must precede ISODE #includes or p_type must be #undeffed
17  * after it is included.  (Because ISODE uses p_type as a field name, and
18  * SunOS 5.5:sys/vtype.h defines it (and ac/socket.h indirectly includes it) */
19 #include <ac/socket.h>
20
21 #include <quipu/commonarg.h>
22 #include <quipu/attrvalue.h>
23 #include <quipu/ds_error.h>
24 #include <quipu/remove.h>
25 #include <quipu/dap2.h>
26 #include <quipu/dua.h>
27
28 #include "lber.h"
29 #include "ldap.h"
30 #include "common.h"
31
32 #ifdef HAVE_COMPAT20
33 extern int      ldap_compat;
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         extern DN                       ldap_str2dn();
58
59         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
60
61         /*
62          * Parse the delete request.  It looks like this:
63          *      DelRequest := DistinguishedName
64          */
65
66 #if ISODEPACKAGE == IC
67 #if ICRELEASE > 2
68         DAS_RemoveEntryArgument_INIT( &ra );
69 #endif
70 #endif
71
72         if ( ber_scanf( ber, "a", &dn ) == LBER_ERROR ) {
73                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
74                 send_ldap_msgresult( clientsb, DELTAG, m,
75                     LDAP_PROTOCOL_ERROR, NULL, "" );
76                 return( 0 );
77         }
78
79         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 );
80
81         ra.rma_object = ldap_str2dn( dn );
82         free( dn );
83         if ( ra.rma_object == NULLDN ) {
84                 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
85                 send_ldap_msgresult( clientsb, DELTAG, m,
86                     LDAP_INVALID_DN_SYNTAX, NULL, "" );
87                 return( 0 );
88         }
89
90         ra.rma_common = common; /* struct copy */
91
92         rc = initiate_dap_operation( OP_REMOVEENTRY, m, &ra );
93
94         dn_free( ra.rma_object );
95
96         if ( rc != 0 ) {
97                 send_ldap_msgresult( clientsb, DELTAG, m, rc, NULL, "" );
98                 return( 0 );
99         }
100
101         return( 1 );
102 }
103
104 void
105 delete_result(
106     Sockbuf     *sb,
107     struct msg  *m
108 )
109 {
110         send_ldap_msgresult( sb, DELTAG, m, LDAP_SUCCESS, NULL, "" );
111
112         return;
113 }