modrdn.c 3.04 KB
Newer Older
1
/* modrdn.c - ldap backend modrdn function */
2
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
4
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Kurt Zeilenga's avatar
Kurt Zeilenga committed
5
 * Copyright 1999-2004 The OpenLDAP Foundation.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
7
 * Portions Copyright 1999-2003 Howard Chu.
 * Portions Copyright 2000-2003 Pierangelo Masarati.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in the file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */
/* ACKNOWLEDGEMENTS:
 * This work was initially developed by the Howard Chu for inclusion
 * in OpenLDAP Software and subsequently enhanced by Pierangelo
 * Masarati.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
22
 */
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include "portable.h"

#include <stdio.h>

#include <ac/socket.h>
#include <ac/string.h>

#include "slap.h"
#include "back-ldap.h"

int
ldap_back_modrdn(
    Operation	*op,
37
    SlapReply	*rs )
38
{
39
	struct ldapinfo	*li = (struct ldapinfo *) op->o_bd->be_private;
40
	struct ldapconn *lc;
41
	ber_int_t msgid;
42
	dncookie dc;
43
44
45
46
#ifdef LDAP_BACK_PROXY_AUTHZ 
	LDAPControl **ctrls = NULL;
	int rc = LDAP_SUCCESS;
#endif /* LDAP_BACK_PROXY_AUTHZ */
47

Kurt Zeilenga's avatar
Kurt Zeilenga committed
48
	struct berval mdn = BER_BVNULL, mnewSuperior = BER_BVNULL;
49

Pierangelo Masarati's avatar
Pierangelo Masarati committed
50
51
	lc = ldap_back_getconn( op, rs );
	if ( !lc || !ldap_back_dobind(lc, op, rs) ) {
52
		return( -1 );
53
	}
54

55
	dc.rwmap = &li->rwmap;
56
57
58
59
60
61
62
63
#ifdef ENABLE_REWRITE
	dc.conn = op->o_conn;
	dc.rs = rs;
#else
	dc.tofrom = 1;
	dc.normalized = 0;
#endif
	if (op->orr_newSup) {
64
65
		int version = LDAP_VERSION3;
		ldap_set_option( lc->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
66
		
Pierangelo Masarati's avatar
Pierangelo Masarati committed
67
68
69
70
		/*
		 * Rewrite the new superior, if defined and required
	 	 */
#ifdef ENABLE_REWRITE
71
		dc.ctx = "newSuperiorDN";
72
73
74
75
76
#endif
		if ( ldap_back_dn_massage( &dc, op->orr_newSup,
			&mnewSuperior ) ) {
			send_ldap_result( op, rs );
			return -1;
Pierangelo Masarati's avatar
Pierangelo Masarati committed
77
		}
78
79
	}

Pierangelo Masarati's avatar
Pierangelo Masarati committed
80
81
82
	/*
	 * Rewrite the modrdn dn, if required
	 */
83
#ifdef ENABLE_REWRITE
84
	dc.ctx = "modrDN";
85
#endif
86
	if ( ldap_back_dn_massage( &dc, &op->o_req_ndn, &mdn ) ) {
87
88
		send_ldap_result( op, rs );
		return -1;
89
90
	}

91
92
93
94
95
96
97
#ifdef LDAP_BACK_PROXY_AUTHZ
	rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
	if ( rc != LDAP_SUCCESS ) {
		goto cleanup;
	}
#endif /* LDAP_BACK_PROXY_AUTHZ */

98
	rs->sr_err = ldap_rename( lc->ld, mdn.bv_val,
99
			op->orr_newrdn.bv_val, mnewSuperior.bv_val,
100
101
102
103
104
105
			op->orr_deleteoldrdn,
#ifdef LDAP_BACK_PROXY_AUTHZ
			ctrls,
#else /* ! LDAP_BACK_PROXY_AUTHZ */
			op->o_ctrls,
#endif /* ! LDAP_BACK_PROXY_AUTHZ */
106
			NULL, &msgid );
107

108
109
110
111
112
113
114
115
#ifdef LDAP_BACK_PROXY_AUTHZ
cleanup:
	if ( ctrls && ctrls != op->o_ctrls ) {
		free( ctrls[ 0 ] );
		free( ctrls );
	}
#endif /* LDAP_BACK_PROXY_AUTHZ */

116
	if ( mdn.bv_val != op->o_req_ndn.bv_val ) {
Howard Chu's avatar
Howard Chu committed
117
		free( mdn.bv_val );
Pierangelo Masarati's avatar
Pierangelo Masarati committed
118
	}
Howard Chu's avatar
Howard Chu committed
119
	if ( mnewSuperior.bv_val != NULL
120
		&& mnewSuperior.bv_val != op->oq_modrdn.rs_newSup->bv_val ) {
Howard Chu's avatar
Howard Chu committed
121
		free( mnewSuperior.bv_val );
Pierangelo Masarati's avatar
Pierangelo Masarati committed
122
	}
123
124
125
126
127
128
129
130

#ifdef LDAP_BACK_PROXY_AUTHZ
	if ( rc != LDAP_SUCCESS ) {
		send_ldap_result( op, rs );
		return -1;
	}
#endif /* LDAP_BACK_PROXY_AUTHZ */

131
	return( ldap_back_op_result( lc, op, rs, msgid, 1 ) );
132
}
133