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 *pdn = NULL, *newdn = NULL;
32 /* get entry with writer lock */
33 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
34 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
35 if ( matched != NULL ) {
41 #define SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL 1
42 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
43 /* check parent for "children" acl */
44 if ( ! access_allowed( be, conn, op, e, "entry", NULL,
45 op->o_dn, ACL_WRITE ) )
47 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
49 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
55 if ( (pdn = dn_parent( be, dn )) != NULL ) {
56 /* parent + rdn + separator(s) + null */
57 if( (p = dn2entry_w( be, pdn, &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, "children", NULL,
68 op->o_dn, ACL_WRITE ) )
70 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
72 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
78 newdn = (char *) ch_malloc( strlen( pdn ) + strlen( newrdn )
80 if ( dn_type( dn ) == DN_X500 ) {
81 strcpy( newdn, newrdn );
82 strcat( newdn, ", " );
86 strcpy( newdn, newrdn );
87 s = strchr( newrdn, '\0' );
89 if ( *s != '.' && *s != '@' ) {
90 if ( (s = strpbrk( dn, ".@" )) != NULL ) {
99 /* no parent, modrdn entry directly under root */
100 if( ! be_isroot( be, op->o_dn ) ) {
101 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
103 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
108 pthread_mutex_lock(&li->li_root_mutex);
111 newdn = ch_strdup( newrdn );
114 (void) dn_normalize( newdn );
116 if ( (dn2id ( be, newdn ) ) != NOID ) {
117 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
121 /* check for abandon */
122 pthread_mutex_lock( &op->o_abandonmutex );
123 if ( op->o_abandon ) {
124 pthread_mutex_unlock( &op->o_abandonmutex );
127 pthread_mutex_unlock( &op->o_abandonmutex );
130 if ( dn2id_add( be, newdn, e->e_id ) != 0 ) {
131 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
136 if ( dn2id_delete( be, dn ) != 0 ) {
137 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
141 (void) cache_delete_entry( &li->li_cache, e );
146 * At some point here we need to update the attribute values in
147 * the entry itself that were effected by this RDN change
148 * (respecting the value of the deleteoldrdn parameter).
150 * Since the code to do this has not yet been written, treat this
151 * omission as a (documented) bug.
155 if ( id2entry_add( be, e ) != 0 ) {
157 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
161 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
165 if( newdn != NULL ) free( newdn );
166 if( pdn != NULL ) free( pdn );
167 if( matched != NULL ) free( matched );
170 /* free parent and writer lock */
171 cache_return_entry_w( &li->li_cache, p );
173 } else if ( rootlock ) {
174 /* release root writer lock */
175 pthread_mutex_unlock(&li->li_root_mutex);
178 /* free entry and writer lock */
179 cache_return_entry_w( &li->li_cache, e );