]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
Add schema checking, continue mode, and fix a few leaks.
[openldap] / servers / slapd / delete.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 /*
6  * Copyright (c) 1995 Regents of the University of Michigan.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms are permitted
10  * provided that this notice is preserved and that due credit is given
11  * to the University of Michigan at Ann Arbor. The name of the University
12  * may not be used to endorse or promote products derived from this
13  * software without specific prior written permission. This software
14  * is provided ``as is'' without express or implied warranty.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/string.h>
22 #include <ac/socket.h>
23
24 #include "slap.h"
25
26 int
27 do_delete(
28     Connection  *conn,
29     Operation   *op
30 )
31 {
32         char    *ndn;
33         Backend *be;
34         int rc;
35
36         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
37
38         if( op->o_bind_in_progress ) {
39                 Debug( LDAP_DEBUG_ANY, "do_delete: SASL bind in progress.\n",
40                         0, 0, 0 );
41                 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
42                         NULL, "SASL bind in progress", NULL, NULL );
43                 return LDAP_SASL_BIND_IN_PROGRESS;
44         }
45
46         /*
47          * Parse the delete request.  It looks like this:
48          *
49          *      DelRequest := DistinguishedName
50          */
51
52         if ( ber_scanf( op->o_ber, "a", &ndn ) == LBER_ERROR ) {
53                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
54                 send_ldap_disconnect( conn, op,
55                         LDAP_PROTOCOL_ERROR, "decoding error" );
56                 return -1;
57         }
58
59         if(     dn_normalize_case( ndn ) == NULL ) {
60                 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", ndn, 0, 0 );
61                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
62                     "invalid DN", NULL, NULL );
63                 free( ndn );
64                 return rc;
65         }
66
67         if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
68                 free( ndn );
69                 Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
70                 return rc;
71         } 
72
73         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", ndn, 0, 0 );
74         Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", ndn, 0, 0 );
75
76         /*
77          * We could be serving multiple database backends.  Select the
78          * appropriate one, or send a referral to our "referral server"
79          * if we don't hold it.
80          */
81         if ( (be = select_backend( ndn )) == NULL ) {
82                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
83                         NULL, NULL, default_referral, NULL );
84                 free( ndn );
85                 return rc;
86         }
87
88         /* deref suffix alias if appropriate */
89         ndn = suffix_alias( be, ndn );
90
91         /*
92          * do the delete if 1 && (2 || 3)
93          * 1) there is a delete function implemented in this backend;
94          * 2) this backend is master for what it holds;
95          * 3) it's a replica and the dn supplied is the update_ndn.
96          */
97         if ( be->be_delete ) {
98                 /* do the update here */
99 #ifndef SLAPD_MULTIMASTER
100                 if ( be->be_update_ndn == NULL ||
101                         strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
102 #endif
103                 {
104                         if ( (*be->be_delete)( be, conn, op, ndn ) == 0 ) {
105 #ifdef SLAPD_MULTIMASTER
106                                 if (be->be_update_ndn == NULL ||
107                                         strcmp( be->be_update_ndn, op->o_ndn ))
108 #endif
109                                 {
110                                         replog( be, op, ndn, NULL );
111                                 }
112                         }
113 #ifndef SLAPD_MULTIMASTER
114                 } else {
115                         send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
116                                 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
117 #endif
118                 }
119
120         } else {
121                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
122                         NULL, "Function not implemented", NULL, NULL );
123         }
124
125         free( ndn );
126         return rc;
127 }