1 /* modrdn.c - bdb2 backend modrdn routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
15 bdb2i_back_modrdn_internal(
24 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
26 char *p_dn = NULL, *p_ndn = NULL;
27 char *new_dn = NULL, *new_ndn = NULL;
32 /* get entry with writer lock */
33 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
34 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
35 if ( matched != NULL ) {
41 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
42 /* check parent for "children" acl */
43 if ( ! access_allowed( be, conn, op, e,
44 "entry", NULL, ACL_WRITE ) )
46 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
48 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
54 if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL ) {
55 /* parent + rdn + separator(s) + null */
56 if( (p = bdb2i_dn2entry_w( be, p_ndn, &matched )) == NULL) {
57 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
59 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
64 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
65 /* check parent for "children" acl */
66 if ( ! access_allowed( be, conn, op, p,
67 "children", NULL, ACL_WRITE ) )
69 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
71 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
77 p_dn = dn_parent( be, e->e_dn );
78 new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn )
80 if ( dn_type( e->e_dn ) == DN_X500 ) {
81 strcpy( new_dn, newrdn );
82 strcat( new_dn, "," );
83 strcat( new_dn, p_dn );
86 strcpy( new_dn, newrdn );
87 s = strchr( newrdn, '\0' );
89 if ( *s != '.' && *s != '@' ) {
90 if ( (s = strpbrk( dn, ".@" )) != NULL ) {
93 strcat( new_dn, sep );
96 strcat( new_dn, p_dn );
100 /* no parent, modrdn entry directly under root */
101 if( ! be_isroot( be, op->o_ndn ) ) {
102 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
104 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
109 new_dn = ch_strdup( newrdn );
112 new_ndn = dn_normalize_case( ch_strdup( new_dn ) );
114 if ( (bdb2i_dn2id ( be, new_ndn ) ) != NOID ) {
115 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
119 /* check for abandon */
120 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
121 if ( op->o_abandon ) {
122 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
125 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
128 if ( bdb2i_dn2id_add( be, new_ndn, e->e_id ) != 0 ) {
129 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
134 if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) {
135 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
139 (void) bdb2i_cache_delete_entry( &li->li_cache, e );
144 (void) bdb2i_cache_update_entry( &li->li_cache, e );
147 * At some point here we need to update the attribute values in
148 * the entry itself that were effected by this RDN change
149 * (respecting the value of the deleteoldrdn parameter).
151 * Since the code to do this has not yet been written, treat this
152 * omission as a (documented) bug.
156 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
158 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
162 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
166 if( new_dn != NULL ) free( new_dn );
167 if( new_ndn != NULL ) free( new_ndn );
168 if( p_dn != NULL ) free( p_dn );
169 if( p_ndn != NULL ) free( p_ndn );
171 if( matched != NULL ) free( matched );
174 /* free parent and writer lock */
175 bdb2i_cache_return_entry_w( &li->li_cache, p );
179 /* free entry and writer lock */
180 bdb2i_cache_return_entry_w( &li->li_cache, e );
196 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
197 struct timeval time1;
200 bdb2i_start_timing( be->bd_info, &time1 );
202 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
204 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
209 ret = bdb2i_back_modrdn_internal( be, conn, op, dn,
210 newrdn, deleteoldrdn );
212 (void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
213 bdb2i_stop_timing( be->bd_info, time1, "MODRDN", conn, op );