]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/modrdn.c
1ea94a0ba8e445d4b593d6f118df97ef7b0e3cb6
[openldap] / servers / slapd / back-ldap / modrdn.c
1 /* modrdn.c - ldap backend modrdn function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1999-2006 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/socket.h>
29 #include <ac/string.h>
30
31 #include "slap.h"
32 #include "back-ldap.h"
33
34 int
35 ldap_back_modrdn(
36                 Operation       *op,
37                 SlapReply       *rs )
38 {
39         ldapinfo_t      *li = (ldapinfo_t *)op->o_bd->be_private;
40
41         ldapconn_t      *lc;
42         ber_int_t       msgid;
43         LDAPControl     **ctrls = NULL;
44         int             do_retry = 1;
45         int             rc = LDAP_SUCCESS;
46         char            *newSup = NULL;
47
48         lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
49         if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
50                 return rs->sr_err;
51         }
52
53         if ( op->orr_newSup ) {
54                 int     version = LDAP_VERSION3;
55                 
56                 ldap_set_option( lc->lc_ld, LDAP_OPT_PROTOCOL_VERSION, &version );
57                 newSup = op->orr_newSup->bv_val;
58         }
59
60         ctrls = op->o_ctrls;
61         rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
62         if ( rc != LDAP_SUCCESS ) {
63                 send_ldap_result( op, rs );
64                 rc = -1;
65                 goto cleanup;
66         }
67
68 retry:
69         rs->sr_err = ldap_rename( lc->lc_ld, op->o_req_dn.bv_val,
70                         op->orr_newrdn.bv_val, newSup,
71                         op->orr_deleteoldrdn, ctrls, NULL, &msgid );
72         rc = ldap_back_op_result( lc, op, rs, msgid,
73                 li->li_timeout[ LDAP_BACK_OP_MODRDN ], LDAP_BACK_SENDRESULT );
74         if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
75                 do_retry = 0;
76                 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
77                         goto retry;
78                 }
79         }
80
81 cleanup:
82         (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
83
84         if ( lc != NULL ) {
85                 ldap_back_release_conn( op, rs, lc );
86         }
87
88         return rc;
89 }
90