]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/modrdn.c
Fix prev commit, return generated passwd
[openldap] / servers / slapd / back-meta / modrdn.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2003 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This work was initially developed by the Howard Chu for inclusion
17  * in OpenLDAP Software and subsequently enhanced by Pierangelo
18  * Masarati.
19  */
20 /* This is an altered version */
21 /*
22  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
23  *
24  * This work has been developed to fulfill the requirements
25  * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
26  * to the OpenLDAP Foundation in the hope that it may be useful
27  * to the Open Source community, but WITHOUT ANY WARRANTY.
28  *
29  * Permission is granted to anyone to use this software for any purpose
30  * on any computer system, and to alter it and redistribute it, subject
31  * to the following restrictions:
32  *
33  * 1. The author and SysNet s.n.c. are not responsible for the consequences
34  *    of use of this software, no matter how awful, even if they arise from 
35  *    flaws in it.
36  *
37  * 2. The origin of this software must not be misrepresented, either by
38  *    explicit claim or by omission.  Since few users ever read sources,
39  *    credits should appear in the documentation.
40  *
41  * 3. Altered versions must be plainly marked as such, and must not be
42  *    misrepresented as being the original software.  Since few users
43  *    ever read sources, credits should appear in the documentation.
44  *    SysNet s.n.c. cannot be responsible for the consequences of the
45  *    alterations.
46  *
47  * 4. This notice may not be removed or altered.
48  *
49  *
50  * This software is based on the backend back-ldap, implemented
51  * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
52  * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
53  * contributors. The contribution of the original software to the present
54  * implementation is acknowledged in this copyright statement.
55  *
56  * A special acknowledgement goes to Howard for the overall architecture
57  * (and for borrowing large pieces of code), and to Mark, who implemented
58  * from scratch the attribute/objectclass mapping.
59  *
60  * The original copyright statement follows.
61  *
62  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
63  *
64  * Permission is granted to anyone to use this software for any purpose
65  * on any computer system, and to alter it and redistribute it, subject
66  * to the following restrictions:
67  *
68  * 1. The author is not responsible for the consequences of use of this
69  *    software, no matter how awful, even if they arise from flaws in it.
70  *
71  * 2. The origin of this software must not be misrepresented, either by
72  *    explicit claim or by omission.  Since few users ever read sources,
73  *    credits should appear in the documentation.
74  *
75  * 3. Altered versions must be plainly marked as such, and must not be
76  *    misrepresented as being the original software.  Since few users
77  *    ever read sources, credits should appear in the
78  *    documentation.
79  *
80  * 4. This notice may not be removed or altered.
81  *
82  */
83
84 #include "portable.h"
85
86 #include <stdio.h>
87
88 #include <ac/socket.h>
89 #include <ac/string.h>
90
91 #include "slap.h"
92 #include "../back-ldap/back-ldap.h"
93 #include "back-meta.h"
94
95 int
96 meta_back_modrdn( Operation *op, SlapReply *rs )
97                 /*
98                 Backend         *be,
99                 Connection      *conn,
100                 Operation       *op,
101                 struct berval   *dn,
102                 struct berval   *ndn,
103                 struct berval   *newrdn,
104                 struct berval   *nnewrdn,
105                 int             deleteoldrdn,
106                 struct berval   *newSuperior,
107                 struct berval   *nnewSuperior
108 ) */
109 {
110         struct metainfo         *li = ( struct metainfo * )op->o_bd->be_private;
111         struct metaconn         *lc;
112         int                     rc = 0;
113         int                     candidate = -1;
114         struct berval           mdn = { 0, NULL },
115                                 mnewSuperior = { 0, NULL };
116         dncookie                dc;
117
118         lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
119                         &op->o_req_ndn, &candidate );
120         if ( !lc ) {
121                 rc = -1;
122                 goto cleanup;
123         }
124
125         if ( !meta_back_dobind( lc, op ) 
126                         || !meta_back_is_valid( lc, candidate ) ) {
127                 rs->sr_err = LDAP_OTHER;
128                 rc = -1;
129                 goto cleanup;
130         }
131
132         dc.conn = op->o_conn;
133         dc.rs = rs;
134
135         if ( op->oq_modrdn.rs_newSup ) {
136                 int nsCandidate, version = LDAP_VERSION3;
137
138                 nsCandidate = meta_back_select_unique_candidate( li,
139                                 op->oq_modrdn.rs_newSup );
140
141                 if ( nsCandidate != candidate ) {
142                         /*
143                          * FIXME: one possibility is to delete the entry
144                          * from one target and add it to the other;
145                          * unfortunately we'd need write access to both,
146                          * which is nearly impossible; for administration
147                          * needs, the rootdn of the metadirectory could
148                          * be mapped to an administrative account on each
149                          * target (the binddn?); we'll see.
150                          */
151                         /*
152                          * FIXME: is this the correct return code?
153                          */
154                         rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
155                         rc = -1;
156                         goto cleanup;
157                 }
158
159                 ldap_set_option( lc->conns[ nsCandidate ].ld,
160                                 LDAP_OPT_PROTOCOL_VERSION, &version );
161
162                 /*
163                  * Rewrite the new superior, if defined and required
164                  */
165                 dc.rwmap = &li->targets[ nsCandidate ]->rwmap;
166                 dc.ctx = "newSuperiorDN";
167                 if ( ldap_back_dn_massage( &dc, op->oq_modrdn.rs_newSup, &mnewSuperior ) ) {
168                         rc = -1;
169                         goto cleanup;
170                 }
171         }
172
173         /*
174          * Rewrite the modrdn dn, if required
175          */
176         dc.rwmap = &li->targets[ candidate ]->rwmap;
177         dc.ctx = "modrDN";
178         if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
179                 rc = -1;
180                 goto cleanup;
181         }
182
183         ldap_rename2_s( lc->conns[ candidate ].ld, mdn.bv_val,
184                         op->oq_modrdn.rs_newrdn.bv_val,
185                         mnewSuperior.bv_val,
186                         op->oq_modrdn.rs_deleteoldrdn );
187
188 cleanup:;
189         if ( mdn.bv_val != op->o_req_dn.bv_val ) {
190                 free( mdn.bv_val );
191         }
192         
193         if ( mnewSuperior.bv_val != NULL 
194                         && mnewSuperior.bv_val != op->oq_modrdn.rs_newSup->bv_val ) {
195                 free( mnewSuperior.bv_val );
196         }
197
198         if ( rc == 0 ) {
199                 return meta_back_op_result( lc, op, rs ) == LDAP_SUCCESS
200                         ? 0 : 1;
201         } /* else */
202
203         send_ldap_result( op, rs );
204         return rc;
205
206 }
207