]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
Add limited LDAP_INVALID_DN_SYNTAX support. dn_normalize{,_case}() now returns
[openldap] / servers / slapd / delete.c
1 /*
2  * Copyright (c) 1995 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 <ac/string.h>
18 #include <ac/socket.h>
19
20 #include "slap.h"
21
22 int
23 do_delete(
24     Connection  *conn,
25     Operation   *op
26 )
27 {
28         char    *ndn;
29         Backend *be;
30         int rc;
31
32         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
33
34         if( op->o_bind_in_progress ) {
35                 Debug( LDAP_DEBUG_ANY, "do_delete: SASL bind in progress.\n",
36                         0, 0, 0 );
37                 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
38                         NULL, "SASL bind in progress", NULL, NULL );
39                 return LDAP_SASL_BIND_IN_PROGRESS;
40         }
41
42         /*
43          * Parse the delete request.  It looks like this:
44          *
45          *      DelRequest := DistinguishedName
46          */
47
48         if ( ber_scanf( op->o_ber, "a", &ndn ) == LBER_ERROR ) {
49                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
50                 send_ldap_disconnect( conn, op,
51                         LDAP_PROTOCOL_ERROR, "decoding error" );
52                 return -1;
53         }
54
55         if(     dn_normalize_case( ndn ) == NULL ) {
56                 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", ndn, 0, 0 );
57                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
58                     "invalid DN", NULL, NULL );
59                 free( ndn );
60                 return rc;
61         }
62
63         if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
64                 free( ndn );
65                 Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
66                 return rc;
67         } 
68
69         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", ndn, 0, 0 );
70         Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", ndn, 0, 0 );
71
72         /*
73          * We could be serving multiple database backends.  Select the
74          * appropriate one, or send a referral to our "referral server"
75          * if we don't hold it.
76          */
77         if ( (be = select_backend( ndn )) == NULL ) {
78                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
79                         NULL, NULL, default_referral, NULL );
80                 free( ndn );
81                 return rc;
82         }
83
84         /*
85          * do the delete if 1 && (2 || 3)
86          * 1) there is a delete function implemented in this backend;
87          * 2) this backend is master for what it holds;
88          * 3) it's a replica and the dn supplied is the update_ndn.
89          */
90         if ( be->be_delete ) {
91                 /* do the update here */
92                 if ( be->be_update_ndn == NULL ||
93                         strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
94                 {
95                         if ( (*be->be_delete)( be, conn, op, ndn ) == 0 ) {
96                                 replog( be, LDAP_REQ_DELETE, ndn, NULL, 0 );
97                         }
98                 } else {
99                         send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
100                                 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
101                 }
102         } else {
103                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
104                         NULL, "Function not implemented", NULL, NULL );
105         }
106
107         free( ndn );
108         return rc;
109 }