]> git.sur5r.net Git - openldap/blob - servers/slapd/modrdn.c
Don't try to free NULL idl. Did not cause a problem, though, as
[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    *ndn, *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}", &ndn, &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
50         Debug( LDAP_DEBUG_ARGS,
51             "do_modrdn: dn (%s) newrdn (%s) deloldrdn (%d)\n", ndn, newrdn,
52             deloldrdn );
53
54         dn_normalize_case( ndn );
55
56         Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
57             conn->c_connid, op->o_opid, ndn, 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( ndn )) == NULL ) {
66                 free( ndn );
67                 free( newrdn );
68                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
69                     default_referral );
70                 return;
71         }
72
73         /* alias suffix if approp */
74         ndn = suffixAlias( ndn, op, be );
75
76         /*
77          * do the add if 1 && (2 || 3)
78          * 1) there is an add function implemented in this backend;
79          * 2) this backend is master for what it holds;
80          * 3) it's a replica and the dn supplied is the update_ndn.
81          */
82         if ( be->be_modrdn != NULL ) {
83                 /* do the update here */
84                 if ( be->be_update_ndn == NULL ||
85                         strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
86                 {
87                         if ( (*be->be_modrdn)( be, conn, op, ndn, newrdn,
88                             deloldrdn ) == 0 ) {
89                                 replog( be, LDAP_REQ_MODRDN, ndn, newrdn,
90                                     deloldrdn );
91                         }
92                 } else {
93                         send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
94                             default_referral );
95                 }
96         } else {
97                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
98                     "Function not implemented" );
99         }
100
101         free( ndn );
102         free( newrdn );
103 }