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;
33 /* get entry with writer lock */
34 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
35 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
36 if ( matched != NULL ) {
42 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
43 /* check parent for "children" acl */
44 if ( ! access_allowed( be, conn, op, e,
45 "entry", NULL, ACL_WRITE ) )
47 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
49 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
55 if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL ) {
56 /* parent + rdn + separator(s) + null */
57 if( (p = bdb2i_dn2entry_w( be, p_ndn, &matched )) == NULL) {
58 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
60 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
65 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
66 /* check parent for "children" acl */
67 if ( ! access_allowed( be, conn, op, p,
68 "children", NULL, ACL_WRITE ) )
70 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
72 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
78 p_dn = dn_parent( be, e->e_dn );
79 new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn )
81 if ( dn_type( e->e_dn ) == DN_X500 ) {
82 strcpy( new_dn, newrdn );
83 strcat( new_dn, "," );
84 strcat( new_dn, p_dn );
87 strcpy( new_dn, newrdn );
88 s = strchr( newrdn, '\0' );
90 if ( *s != '.' && *s != '@' ) {
91 if ( (s = strpbrk( dn, ".@" )) != NULL ) {
94 strcat( new_dn, sep );
97 strcat( new_dn, p_dn );
101 /* no parent, modrdn entry directly under root */
102 if( ! be_isroot( be, op->o_ndn ) ) {
103 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
105 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
110 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
113 new_dn = ch_strdup( newrdn );
116 new_ndn = dn_normalize_case( ch_strdup( new_dn ) );
118 if ( (bdb2i_dn2id ( be, new_ndn ) ) != NOID ) {
119 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
123 /* check for abandon */
124 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
125 if ( op->o_abandon ) {
126 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
129 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
132 if ( bdb2i_dn2id_add( be, new_ndn, e->e_id ) != 0 ) {
133 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
138 if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) {
139 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
143 (void) bdb2i_cache_delete_entry( &li->li_cache, e );
148 (void) bdb2i_cache_update_entry( &li->li_cache, e );
151 * At some point here we need to update the attribute values in
152 * the entry itself that were effected by this RDN change
153 * (respecting the value of the deleteoldrdn parameter).
155 * Since the code to do this has not yet been written, treat this
156 * omission as a (documented) bug.
160 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
162 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
166 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
170 if( new_dn != NULL ) free( new_dn );
171 if( new_ndn != NULL ) free( new_ndn );
172 if( p_dn != NULL ) free( p_dn );
173 if( p_ndn != NULL ) free( p_ndn );
175 if( matched != NULL ) free( matched );
178 /* free parent and writer lock */
179 bdb2i_cache_return_entry_w( &li->li_cache, p );
184 /* release root writer lock */
185 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
188 /* free entry and writer lock */
189 bdb2i_cache_return_entry_w( &li->li_cache, e );
205 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
207 struct timeval time1, time2;
211 gettimeofday( &time1, NULL );
213 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
215 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
220 ret = bdb2i_back_modrdn_internal( be, conn, op, dn,
221 newrdn, deleteoldrdn );
223 (void) bdb2i_leave_backend( get_dbenv( be ), lock );
225 if ( bdb2i_do_timing ) {
227 gettimeofday( &time2, NULL);
228 elapsed_time = bdb2i_elapsed( time1, time2 );
229 Debug( LDAP_DEBUG_ANY, "conn=%d op=%d MODRDN elapsed=%s\n",
230 conn->c_connid, op->o_opid, elapsed_time );
231 free( elapsed_time );