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 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
42 /* check parent for "children" acl */
43 if ( ! access_allowed( be, conn, op, e, "entry", NULL,
44 op->o_dn, ACL_WRITE ) )
46 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
48 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
54 if ( (pdn = dn_parent( be, dn )) != NULL ) {
55 /* parent + rdn + separator(s) + null */
56 if( (p = dn2entry_w( be, pdn, &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, "children", NULL,
67 op->o_dn, ACL_WRITE ) )
69 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
71 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
77 newdn = (char *) ch_malloc( strlen( pdn ) + strlen( newrdn )
79 if ( dn_type( dn ) == DN_X500 ) {
80 strcpy( newdn, newrdn );
81 strcat( newdn, ", " );
85 strcpy( newdn, newrdn );
86 s = strchr( newrdn, '\0' );
88 if ( *s != '.' && *s != '@' ) {
89 if ( (s = strpbrk( dn, ".@" )) != NULL ) {
98 /* no parent, modrdn entry directly under root */
99 if( ! be_isroot( be, op->o_dn ) ) {
100 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
102 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
107 pthread_mutex_lock(&li->li_root_mutex);
110 newdn = ch_strdup( newrdn );
113 (void) dn_normalize( newdn );
115 if ( (dn2id ( be, newdn ) ) != NOID ) {
116 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
120 /* check for abandon */
121 pthread_mutex_lock( &op->o_abandonmutex );
122 if ( op->o_abandon ) {
123 pthread_mutex_unlock( &op->o_abandonmutex );
126 pthread_mutex_unlock( &op->o_abandonmutex );
129 if ( dn2id_add( be, newdn, e->e_id ) != 0 ) {
130 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
135 if ( dn2id_delete( be, dn ) != 0 ) {
136 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
140 (void) cache_delete_entry( &li->li_cache, e );
145 * At some point here we need to update the attribute values in
146 * the entry itself that were effected by this RDN change
147 * (respecting the value of the deleteoldrdn parameter).
149 * Since the code to do this has not yet been written, treat this
150 * omission as a (documented) bug.
154 if ( id2entry_add( be, e ) != 0 ) {
156 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
160 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
164 if( newdn != NULL ) free( newdn );
165 if( pdn != NULL ) free( pdn );
166 if( matched != NULL ) free( matched );
169 /* free parent and writer lock */
170 cache_return_entry_w( &li->li_cache, p );
172 } else if ( rootlock ) {
173 /* release root writer lock */
174 pthread_mutex_unlock(&li->li_root_mutex);
177 /* free entry and writer lock */
178 cache_return_entry_w( &li->li_cache, e );