1 /* modrdn.c - ldbm backend modrdn routine */
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
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 = 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 = 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 ( (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 ( dn2id_add( be, new_ndn, e->e_id ) != 0 ) {
133 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
138 if ( dn2id_delete( be, e->e_ndn ) != 0 ) {
139 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
143 (void) cache_delete_entry( &li->li_cache, e );
149 (void) cache_update_entry( &li->li_cache, e );
152 * At some point here we need to update the attribute values in
153 * the entry itself that were effected by this RDN change
154 * (respecting the value of the deleteoldrdn parameter).
156 * Since the code to do this has not yet been written, treat this
157 * omission as a (documented) bug.
161 if ( id2entry_add( be, e ) != 0 ) {
163 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
167 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
171 if( new_dn != NULL ) free( new_dn );
172 if( new_ndn != NULL ) free( new_ndn );
173 if( p_dn != NULL ) free( p_dn );
174 if( p_ndn != NULL ) free( p_ndn );
176 if( matched != NULL ) free( matched );
179 /* free parent and writer lock */
180 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 cache_return_entry_w( &li->li_cache, e );