]> git.sur5r.net Git - openldap/blob - servers/slapd/modrdn.c
Import cache_delete_entry_internal/dntree&idtree delete fix from -devel.
[openldap] / servers / slapd / modrdn.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/socket.h>
18 #include <ac/string.h>
19
20 #include "slap.h"
21
22 void
23 do_modrdn(
24     Connection  *conn,
25     Operation   *op
26 )
27 {
28         char    *dn, *odn, *newrdn;
29         int     deloldrdn;
30         Backend *be;
31
32         Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
33
34         /*
35          * Parse the modrdn request.  It looks like this:
36          *
37          *      ModifyRDNRequest := SEQUENCE {
38          *              entry   DistinguishedName,
39          *              newrdn  RelativeDistinguishedName
40          *      }
41          */
42
43         if ( ber_scanf( op->o_ber, "{aab}", &dn, &newrdn, &deloldrdn )
44             == LBER_ERROR ) {
45                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
46                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
47                 return;
48         }
49         odn = ch_strdup( dn );
50         dn_normalize( dn );
51
52         Debug( LDAP_DEBUG_ARGS,
53             "do_modrdn: dn (%s) newrdn (%s) deloldrdn (%d)\n", dn, newrdn,
54             deloldrdn );
55
56         Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
57             conn->c_connid, op->o_opid, dn, 0, 0 );
58
59         /*
60          * We could be serving multiple database backends.  Select the
61          * appropriate one, or send a referral to our "referral server"
62          * if we don't hold it.
63          */
64
65         if ( (be = select_backend( dn )) == NULL ) {
66                 free( dn );
67                 free( odn );
68                 free( newrdn );
69                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
70                     default_referral );
71                 return;
72         }
73
74         /*
75          * do the add if 1 && (2 || 3)
76          * 1) there is an add function implemented in this backend;
77          * 2) this backend is master for what it holds;
78          * 3) it's a replica and the dn supplied is the updatedn.
79          */
80         if ( be->be_modrdn != NULL ) {
81                 /* do the update here */
82                 if ( be->be_updatedn == NULL || strcasecmp( be->be_updatedn,
83                     op->o_dn ) == 0 ) {
84                         if ( (*be->be_modrdn)( be, conn, op, dn, newrdn,
85                             deloldrdn ) == 0 ) {
86                                 replog( be, LDAP_REQ_MODRDN, odn, newrdn,
87                                     deloldrdn );
88                         }
89                 } else {
90                         send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
91                             default_referral );
92                 }
93         } else {
94                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
95                     "Function not implemented" );
96         }
97
98         free( dn );
99         free( odn );
100         free( newrdn );
101 }