]> git.sur5r.net Git - openldap/blob - servers/ldapd/delete.c
008f341ee3e31ff1afc83c4a145c1d154eb874b2
[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
17 #include <quipu/commonarg.h>
18 #include <quipu/attrvalue.h>
19 #include <quipu/ds_error.h>
20 #include <quipu/remove.h>
21 #include <quipu/dap2.h>
22 #include <quipu/dua.h>
23
24 #include <ac/socket.h>
25
26 #include "lber.h"
27 #include "ldap.h"
28 #include "common.h"
29
30 #ifdef HAVE_COMPAT20
31 extern int      ldap_compat;
32 #define DELTAG  (ldap_compat == 20 ? OLD_LDAP_RES_DELETE : LDAP_RES_DELETE)
33 #else
34 #define DELTAG  LDAP_RES_DELETE
35 #endif
36
37 /*
38  * do_delete - Initiate an X.500 remove entry operation.  Returns 1 if
39  * the operation was initiated successfully, and thus a response will be
40  * coming back from the DSA.  Returns 0 if there was trouble and thus no
41  * DSA response is expected.
42  */
43
44 int
45 do_delete( 
46     Sockbuf     *clientsb,
47     struct msg  *m,
48     BerElement  *ber
49 )
50 {
51         char                            *dn;
52         int                             rc;
53         struct ds_removeentry_arg       ra;
54         static CommonArgs               common = default_common_args;
55         extern DN                       ldap_str2dn();
56
57         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
58
59         /*
60          * Parse the delete request.  It looks like this:
61          *      DelRequest := DistinguishedName
62          */
63
64 #if ISODEPACKAGE == IC
65 #if ICRELEASE > 2
66         DAS_RemoveEntryArgument_INIT( &ra );
67 #endif
68 #endif
69
70         if ( ber_scanf( ber, "a", &dn ) == LBER_ERROR ) {
71                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
72                 send_ldap_msgresult( clientsb, DELTAG, m,
73                     LDAP_PROTOCOL_ERROR, NULL, "" );
74                 return( 0 );
75         }
76
77         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 );
78
79         ra.rma_object = ldap_str2dn( dn );
80         free( dn );
81         if ( ra.rma_object == NULLDN ) {
82                 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
83                 send_ldap_msgresult( clientsb, DELTAG, m,
84                     LDAP_INVALID_DN_SYNTAX, NULL, "" );
85                 return( 0 );
86         }
87
88         ra.rma_common = common; /* struct copy */
89
90         rc = initiate_dap_operation( OP_REMOVEENTRY, m, &ra );
91
92         dn_free( ra.rma_object );
93
94         if ( rc != 0 ) {
95                 send_ldap_msgresult( clientsb, DELTAG, m, rc, NULL, "" );
96                 return( 0 );
97         }
98
99         return( 1 );
100 }
101
102 void
103 delete_result(
104     Sockbuf     *sb,
105     struct msg  *m
106 )
107 {
108         send_ldap_msgresult( sb, DELTAG, m, LDAP_SUCCESS, NULL, "" );
109
110         return;
111 }