1 /* modrdn.c - bdb2 backend modrdn routine */
4 * LDAP v3 newSuperior support.
6 * Copyright 1999, Juan C. Gomez, All rights reserved.
7 * This software is not subject to any license of Silicon Graphics
8 * Inc. or Purdue University.
10 * Redistribution and use in source and binary forms are permitted
11 * without restriction or fee of any kind as long as this notice
20 #include <ac/string.h>
21 #include <ac/socket.h>
24 #include "back-bdb2.h"
25 #include "proto-back-bdb2.h"
28 bdb2i_back_modrdn_internal(
38 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
40 char *p_dn = NULL, *p_ndn = NULL;
41 char *new_dn = NULL, *new_ndn = NULL;
46 /* get entry with writer lock */
47 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
48 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
49 if ( matched != NULL ) {
55 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
56 /* check parent for "children" acl */
57 if ( ! access_allowed( be, conn, op, e,
58 "entry", NULL, ACL_WRITE ) )
60 Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
62 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
68 if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL ) {
69 /* parent + rdn + separator(s) + null */
70 if( (p = bdb2i_dn2entry_w( be, p_ndn, &matched )) == NULL) {
71 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
73 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
78 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
79 /* check parent for "children" acl */
80 if ( ! access_allowed( be, conn, op, p,
81 "children", NULL, ACL_WRITE ) )
83 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
85 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
91 p_dn = dn_parent( be, e->e_dn );
92 new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn )
94 if ( dn_type( e->e_dn ) == DN_X500 ) {
95 strcpy( new_dn, newrdn );
96 strcat( new_dn, "," );
97 strcat( new_dn, p_dn );
100 strcpy( new_dn, newrdn );
101 s = strchr( newrdn, '\0' );
103 if ( *s != '.' && *s != '@' ) {
104 if ( (s = strpbrk( dn, ".@" )) != NULL ) {
107 strcat( new_dn, sep );
110 strcat( new_dn, p_dn );
114 /* no parent, modrdn entry directly under root */
115 if( ! be_isroot( be, op->o_ndn ) ) {
116 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
118 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
123 new_dn = ch_strdup( newrdn );
126 new_ndn = dn_normalize_case( ch_strdup( new_dn ) );
128 if ( (bdb2i_dn2id ( be, new_ndn ) ) != NOID ) {
129 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
133 /* check for abandon */
134 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
135 if ( op->o_abandon ) {
136 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
139 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
142 if ( bdb2i_dn2id_add( be, new_ndn, e->e_id ) != 0 ) {
143 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
148 if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) {
149 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
153 (void) bdb2i_cache_delete_entry( &li->li_cache, e );
158 (void) bdb2i_cache_update_entry( &li->li_cache, e );
161 * At some point here we need to update the attribute values in
162 * the entry itself that were effected by this RDN change
163 * (respecting the value of the deleteoldrdn parameter).
165 * Since the code to do this has not yet been written, treat this
166 * omission as a (documented) bug.
170 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
172 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
176 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
180 if( new_dn != NULL ) free( new_dn );
181 if( new_ndn != NULL ) free( new_ndn );
182 if( p_dn != NULL ) free( p_dn );
183 if( p_ndn != NULL ) free( p_ndn );
185 if( matched != NULL ) free( matched );
188 /* free parent and writer lock */
189 bdb2i_cache_return_entry_w( &li->li_cache, p );
193 /* free entry and writer lock */
194 bdb2i_cache_return_entry_w( &li->li_cache, e );
211 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
212 struct timeval time1;
215 bdb2i_start_timing( be->bd_info, &time1 );
217 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
219 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
224 ret = bdb2i_back_modrdn_internal( be, conn, op, dn,
225 newrdn, deleteoldrdn,
228 (void) bdb2i_leave_backend_w( lock );
229 bdb2i_stop_timing( be->bd_info, time1, "MODRDN", conn, op );