1 /* modrdn.c - ldbm backend modrdn routine */
6 #include <sys/socket.h>
10 extern Entry *dn2entry();
11 extern char *dn_parent();
23 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
25 char *pdn, *newdn, *p;
30 if ( (e = dn2entry( be, dn, &matched )) == NULL ) {
31 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
32 if ( matched != NULL ) {
38 if ( (pdn = dn_parent( be, dn )) != NULL ) {
39 /* parent + rdn + separator(s) + null */
40 newdn = (char *) ch_malloc( strlen( pdn ) + strlen( newrdn )
42 if ( dn_type( dn ) == DN_X500 ) {
43 strcpy( newdn, newrdn );
44 strcat( newdn, ", " );
47 strcpy( newdn, newrdn );
48 p = strchr( newrdn, '\0' );
50 if ( *p != '.' && *p != '@' ) {
51 if ( (p = strpbrk( dn, ".@" )) != NULL ) {
60 newdn = strdup( newrdn );
62 (void) dn_normalize( newdn );
65 if ( (e2 = dn2entry( be, newdn, &matched )) != NULL ) {
68 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
69 cache_return_entry( &li->li_cache, e2 );
70 cache_return_entry( &li->li_cache, e );
73 if ( matched != NULL ) {
77 /* check for abandon */
78 pthread_mutex_lock( &op->o_abandonmutex );
79 if ( op->o_abandon ) {
80 pthread_mutex_unlock( &op->o_abandonmutex );
83 cache_return_entry( &li->li_cache, e2 );
84 cache_return_entry( &li->li_cache, e );
87 pthread_mutex_unlock( &op->o_abandonmutex );
90 if ( dn2id_add( be, newdn, e->e_id ) != 0 ) {
93 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
94 cache_return_entry( &li->li_cache, e );
99 if ( dn2id_delete( be, dn ) != 0 ) {
102 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
103 cache_return_entry( &li->li_cache, e );
107 (void) cache_delete_entry( &li->li_cache, e );
112 * At some point here we need to update the attribute values in
113 * the entry itself that were effected by this RDN change
114 * (respecting the value of the deleteoldrdn parameter).
116 * Since the code to do this has not yet been written, treat this
117 * omission as a (documented) bug.
121 if ( id2entry_add( be, e ) != 0 ) {
124 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
128 cache_return_entry( &li->li_cache, e );
129 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );