Commit 07c563b8 authored by Ondrej Kuznik's avatar Ondrej Kuznik Committed by Howard Chu
Browse files

ITS#7256 Rework entry retrieval and cleanup.

When doing deletes, lastmod has no entry to work on.
parent fde1f80a
...@@ -132,7 +132,7 @@ slapmodify( int argc, char **argv ) ...@@ -132,7 +132,7 @@ slapmodify( int argc, char **argv )
lineno=nextline+1 ) lineno=nextline+1 )
{ {
BackendDB *bd; BackendDB *bd;
Entry *e; Entry *e_orig = NULL, *e = NULL;
struct berval rbuf; struct berval rbuf;
LDIFRecord lr; LDIFRecord lr;
struct berval ndn; struct berval ndn;
...@@ -273,13 +273,33 @@ slapmodify( int argc, char **argv ) ...@@ -273,13 +273,33 @@ slapmodify( int argc, char **argv )
break; break;
} }
/* get entry */ /* get id and/or entry */
id = be->be_dn2id_get( be, &ndn ); switch ( lr.lr_op ) {
e = be->be_entry_get( be, id ); case LDAP_REQ_ADD:
if ( e != NULL ) { e = entry_alloc();
Entry *e_tmp = entry_dup( e ); ber_dupbv( &e->e_name, &lr.lr_dn );
/* FIXME: release? */ ber_dupbv( &e->e_nname, &ndn );
e = e_tmp; break;
//case LDAP_REQ_MODRDN:
case LDAP_REQ_DELETE:
case LDAP_REQ_MODIFY:
id = be->be_dn2id_get( be, &ndn );
rc = (id == NOID);
if ( rc == LDAP_SUCCESS && lr.lr_op != LDAP_REQ_DELETE ) {
e_orig = be->be_entry_get( be, id );
e = entry_dup( e_orig );
}
break;
}
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: no such entry \"%s\" in database (lineno=%d)\n",
progname, ndn.bv_val, lineno );
rc = EXIT_FAILURE;
SLAP_FREE( ndn.bv_val );
if( continuemode ) continue;
goto done;
} }
if ( lr.lrop_mods ) { if ( lr.lrop_mods ) {
...@@ -301,6 +321,7 @@ slapmodify( int argc, char **argv ) ...@@ -301,6 +321,7 @@ slapmodify( int argc, char **argv )
SLAP_FREE( ndn.bv_val ); SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr ); ldap_ldif_record_done( &lr );
entry_free( e ); entry_free( e );
be_entry_release_w( op, e_orig );
goto done; goto done;
} }
...@@ -370,6 +391,7 @@ slapmodify( int argc, char **argv ) ...@@ -370,6 +391,7 @@ slapmodify( int argc, char **argv )
SLAP_FREE( ndn.bv_val ); SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr ); ldap_ldif_record_done( &lr );
entry_free( e ); entry_free( e );
be_entry_release_w( op, e_orig );
goto done; goto done;
} }
...@@ -396,6 +418,7 @@ slapmodify( int argc, char **argv ) ...@@ -396,6 +418,7 @@ slapmodify( int argc, char **argv )
SLAP_FREE( ndn.bv_val ); SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr ); ldap_ldif_record_done( &lr );
entry_free( e ); entry_free( e );
be_entry_release_w( op, e_orig );
goto done; goto done;
} }
} }
...@@ -440,6 +463,7 @@ slapmodify( int argc, char **argv ) ...@@ -440,6 +463,7 @@ slapmodify( int argc, char **argv )
SLAP_FREE( ndn.bv_val ); SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr ); ldap_ldif_record_done( &lr );
entry_free( e ); entry_free( e );
be_entry_release_w( op, e_orig );
goto done; goto done;
} }
} }
...@@ -455,7 +479,7 @@ slapmodify( int argc, char **argv ) ...@@ -455,7 +479,7 @@ slapmodify( int argc, char **argv )
} }
} }
if ( SLAP_LASTMOD(be) ) { if ( SLAP_LASTMOD(be) && e != NULL ) {
time_t now = slap_get_time(); time_t now = slap_get_time();
char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ]; char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
struct berval vals[ 2 ]; struct berval vals[ 2 ];
...@@ -574,6 +598,7 @@ slapmodify( int argc, char **argv ) ...@@ -574,6 +598,7 @@ slapmodify( int argc, char **argv )
case LDAP_REQ_DELETE: case LDAP_REQ_DELETE:
rc = be->be_entry_delete( be, id, &bvtext ); rc = be->be_entry_delete( be, id, &bvtext );
e_orig = NULL;
break; break;
} }
...@@ -599,7 +624,10 @@ slapmodify( int argc, char **argv ) ...@@ -599,7 +624,10 @@ slapmodify( int argc, char **argv )
request, e->e_dn ); request, e->e_dn );
} }
entry_free( e ); ldap_ldif_record_done( &lr );
if ( e ) entry_free( e );
if ( e_orig ) be_entry_release_w( op, e_orig );
if ( rc != LDAP_SUCCESS && !continuemode ) break;
} }
done:; done:;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment