mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-09 02:52:04 +08:00
Added support for newSuperior.
This commit is contained in:
parent
dccfdb97e9
commit
90ebcb8bd9
@ -55,6 +55,15 @@ ldbm_back_modrdn(
|
|||||||
struct berval bv; /* Stores new rdn att */
|
struct berval bv; /* Stores new rdn att */
|
||||||
struct berval *bvals[2]; /* Stores new rdn att */
|
struct berval *bvals[2]; /* Stores new rdn att */
|
||||||
LDAPMod mod; /* Used to delete old rdn */
|
LDAPMod mod; /* Used to delete old rdn */
|
||||||
|
/* Added to support newSuperior */
|
||||||
|
Entry *np = NULL; /* newSuperior Entry */
|
||||||
|
char *np_dn = NULL; /* newSuperior dn */
|
||||||
|
char *np_ndn = NULL; /* newSuperior ndn */
|
||||||
|
char *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE, "==>ldbm_back_modrdn(newSuperior=%s)\n",\
|
||||||
|
(newSuperior ? newSuperior : "NULL"),\
|
||||||
|
0, 0 );
|
||||||
|
|
||||||
/* get entry with writer lock */
|
/* get entry with writer lock */
|
||||||
if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
|
if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
|
||||||
@ -79,7 +88,11 @@ ldbm_back_modrdn(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL ) {
|
if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL ) {
|
||||||
/* parent + rdn + separator(s) + null */
|
|
||||||
|
/* Make sure parent entry exist and we can write its
|
||||||
|
* children.
|
||||||
|
*/
|
||||||
|
|
||||||
if( (p = dn2entry_w( be, p_ndn, &matched )) == NULL) {
|
if( (p = dn2entry_w( be, p_ndn, &matched )) == NULL) {
|
||||||
Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
|
Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
|
||||||
0, 0, 0);
|
0, 0, 0);
|
||||||
@ -99,29 +112,17 @@ ldbm_back_modrdn(
|
|||||||
"", "" );
|
"", "" );
|
||||||
goto return_results;
|
goto return_results;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: wr to children of entry %s OK\n",
|
||||||
|
p_ndn, 0, 0 );
|
||||||
|
#endif
|
||||||
|
|
||||||
p_dn = dn_parent( be, e->e_dn );
|
p_dn = dn_parent( be, e->e_dn );
|
||||||
new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn )
|
|
||||||
+ 3 );
|
|
||||||
if ( dn_type( e->e_dn ) == DN_X500 ) {
|
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
|
||||||
strcpy( new_dn, newrdn );
|
p_dn, 0, 0 );
|
||||||
strcat( new_dn, "," );
|
|
||||||
strcat( new_dn, p_dn );
|
|
||||||
} else {
|
|
||||||
char *s;
|
|
||||||
strcpy( new_dn, newrdn );
|
|
||||||
s = strchr( newrdn, '\0' );
|
|
||||||
s--;
|
|
||||||
if ( *s != '.' && *s != '@' ) {
|
|
||||||
if ( (s = strpbrk( dn, ".@" )) != NULL ) {
|
|
||||||
sep[0] = *s;
|
|
||||||
sep[1] = '\0';
|
|
||||||
strcat( new_dn, sep );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strcat( new_dn, p_dn );
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* no parent, modrdn entry directly under root */
|
/* no parent, modrdn entry directly under root */
|
||||||
@ -135,17 +136,86 @@ ldbm_back_modrdn(
|
|||||||
|
|
||||||
ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
|
ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
|
||||||
rootlock = 1;
|
rootlock = 1;
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: no parent, locked root\n",
|
||||||
|
0, 0, 0 );
|
||||||
|
|
||||||
|
}/* if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL ) else */
|
||||||
|
|
||||||
|
new_parent_dn = p_dn; /* New Parent unless newSuperior given */
|
||||||
|
|
||||||
|
if ( (np_dn = newSuperior) != NULL) {
|
||||||
|
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: new parent requested...\n",
|
||||||
|
0, 0, 0 );
|
||||||
|
|
||||||
|
np_ndn = dn_normalize_case( ch_strdup( np_dn ) );
|
||||||
|
|
||||||
|
/* newSuperior == oldParent?, if so ==> ERROR */
|
||||||
|
|
||||||
|
/* newSuperior == entry being moved?, if so ==> ERROR */
|
||||||
|
|
||||||
|
/* Get Entry with dn=newSuperior. Does newSuperior exist? */
|
||||||
|
|
||||||
|
if( (np = dn2entry_w( be, np_ndn, &matched )) == NULL) {
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
|
||||||
|
np_ndn, 0, 0);
|
||||||
|
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "",
|
||||||
|
"");
|
||||||
|
goto return_results;
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: wr to new parent OK np=%p, id=%d\n",
|
||||||
|
np, np->e_id, 0 );
|
||||||
|
|
||||||
|
#ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
|
||||||
|
/* check newSuperior for "children" acl */
|
||||||
|
if ( !access_allowed( be, conn, op, np, "children", NULL,
|
||||||
|
ACL_WRITE ) )
|
||||||
|
{
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: no wr to newSup children\n",
|
||||||
|
0, 0, 0 );
|
||||||
|
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
|
||||||
|
"", "" );
|
||||||
|
goto return_results;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: wr to new parent's children OK\n",
|
||||||
|
0, 0 , 0 );
|
||||||
|
|
||||||
|
|
||||||
|
new_parent_dn = np_dn;
|
||||||
|
|
||||||
new_dn = ch_strdup( newrdn );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Build target dn and make sure target entry doesn't exist already. */
|
||||||
|
|
||||||
new_ndn = dn_normalize_case( ch_strdup( new_dn ) );
|
build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn );
|
||||||
|
|
||||||
if ( (dn2id ( be, new_ndn ) ) != NOID ) {
|
|
||||||
send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
|
new_ndn = dn_normalize_case( ch_strdup(new_dn) );
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
|
||||||
|
new_ndn, 0, 0 );
|
||||||
|
|
||||||
|
if (dn2id ( be, new_ndn ) != NOID) {
|
||||||
|
send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
|
||||||
goto return_results;
|
goto return_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
"ldbm_back_modrdn: new ndn=%s does not exist\n",
|
||||||
|
new_ndn, 0, 0 );
|
||||||
|
|
||||||
/* check for abandon */
|
/* check for abandon */
|
||||||
ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
|
ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
|
||||||
if ( op->o_abandon ) {
|
if ( op->o_abandon ) {
|
||||||
@ -352,6 +422,11 @@ return_results:
|
|||||||
if( old_rdn_type != NULL ) free(old_rdn_type);
|
if( old_rdn_type != NULL ) free(old_rdn_type);
|
||||||
if( old_rdn_val != NULL ) free(old_rdn_val);
|
if( old_rdn_val != NULL ) free(old_rdn_val);
|
||||||
|
|
||||||
|
|
||||||
|
/* LDAP v3 Support */
|
||||||
|
if ( np_dn != NULL ) free( np_dn );
|
||||||
|
if ( np_ndn != NULL ) free( np_ndn );
|
||||||
|
|
||||||
if( p != NULL ) {
|
if( p != NULL ) {
|
||||||
/* free parent and writer lock */
|
/* free parent and writer lock */
|
||||||
cache_return_entry_w( &li->li_cache, p );
|
cache_return_entry_w( &li->li_cache, p );
|
||||||
|
@ -454,13 +454,20 @@ rdn_attr_value( char * rdn )
|
|||||||
void
|
void
|
||||||
build_new_dn( char ** new_dn, char *e_dn, char * p_dn, char * newrdn )
|
build_new_dn( char ** new_dn, char *e_dn, char * p_dn, char * newrdn )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ( p_dn == NULL ) {
|
||||||
|
|
||||||
|
*new_dn = ch_strdup( newrdn );
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
*new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn ) + 3 );
|
*new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn ) + 3 );
|
||||||
|
|
||||||
if ( dn_type( e_dn ) == DN_X500 ) {
|
if ( dn_type( e_dn ) == DN_X500 ) {
|
||||||
|
|
||||||
strcpy( *new_dn, newrdn );
|
strcpy( *new_dn, newrdn );
|
||||||
strcat( *new_dn, ", " );
|
strcat( *new_dn, "," );
|
||||||
strcat( *new_dn, p_dn );
|
strcat( *new_dn, p_dn );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user