mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-27 09:09:20 -05:00
error message from be_entry_put tool backend function
This commit is contained in:
parent
ea86a19460
commit
f8fb4aca76
5 changed files with 60 additions and 23 deletions
|
|
@ -112,7 +112,8 @@ Entry* bdb_tool_entry_get( BackendDB *be, ID id )
|
|||
|
||||
ID bdb_tool_entry_put(
|
||||
BackendDB *be,
|
||||
Entry *e )
|
||||
Entry *e,
|
||||
struct berval *text )
|
||||
{
|
||||
int rc;
|
||||
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
||||
|
|
@ -122,6 +123,10 @@ ID bdb_tool_entry_put(
|
|||
assert( be != NULL );
|
||||
assert( slapMode & SLAP_TOOL_MODE );
|
||||
|
||||
assert( text );
|
||||
assert( text->bv_val );
|
||||
assert( text->bv_val[0] == '\0' );
|
||||
|
||||
Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
|
||||
(long) e->e_id, e->e_dn, 0 );
|
||||
|
||||
|
|
@ -129,18 +134,23 @@ ID bdb_tool_entry_put(
|
|||
rc = txn_begin( bdb->bi_dbenv, NULL, &tid,
|
||||
bdb->bi_db_opflags );
|
||||
if( rc != 0 ) {
|
||||
snprintf( text->bv_val, text->bv_len,
|
||||
"txn_begin failed: %s (%d)",
|
||||
db_strerror(rc), rc );
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"=> bdb_tool_entry_put: txn_begin failed: %s (%d)\n",
|
||||
db_strerror(rc), rc, 0 );
|
||||
"=> bdb_tool_entry_put: %s\n",
|
||||
text->bv_val, 0, 0 );
|
||||
return NOID;
|
||||
}
|
||||
}
|
||||
|
||||
rc = bdb_next_id( be, tid, &e->e_id );
|
||||
if( rc != 0 ) {
|
||||
snprintf( text->bv_val, text->bv_len,
|
||||
"next_id failed: %s (%d)",
|
||||
db_strerror(rc), rc );
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"=> bdb_tool_entry_put: next_id failed: %s (%d)\n",
|
||||
db_strerror(rc), rc, 0 );
|
||||
"=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -152,26 +162,32 @@ ID bdb_tool_entry_put(
|
|||
pdn.bv_len = 0;
|
||||
rc = bdb_dn2id_add( be, tid, &pdn, e );
|
||||
if( rc != 0 ) {
|
||||
snprintf( text->bv_val, text->bv_len,
|
||||
"dn2id_add failed: %s (%d)",
|
||||
db_strerror(rc), rc );
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"=> bdb_tool_entry_put: dn2id_add failed: %s (%d)\n",
|
||||
db_strerror(rc), rc, 0 );
|
||||
"=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* id2entry index */
|
||||
rc = bdb_id2entry_add( be, tid, e );
|
||||
if( rc != 0 ) {
|
||||
snprintf( text->bv_val, text->bv_len,
|
||||
"id2entry_add failed: %s (%d)",
|
||||
db_strerror(rc), rc );
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"=> bdb_tool_entry_put: id2entry_add failed: %s (%d)\n",
|
||||
db_strerror(rc), rc, 0 );
|
||||
"=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
|
||||
goto done;
|
||||
}
|
||||
|
||||
rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
|
||||
if( rc != 0 ) {
|
||||
snprintf( text->bv_val, text->bv_len,
|
||||
"index_entry_add failed: %s (%d)",
|
||||
db_strerror(rc), rc );
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"=> bdb_tool_entry_put: index_entry_add failed: %s (%d)\n",
|
||||
db_strerror(rc), rc, 0 );
|
||||
"=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -180,17 +196,23 @@ done:
|
|||
if( rc == 0 ) {
|
||||
rc = txn_commit( tid, 0 );
|
||||
if( rc != 0 ) {
|
||||
snprintf( text->bv_val, text->bv_len,
|
||||
"txn_commit failed: %s (%d)",
|
||||
db_strerror(rc), rc );
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"=> bdb_tool_entry_put: txn_commit failed: %s (%d)\n",
|
||||
db_strerror(rc), rc, 0 );
|
||||
"=> bdb_tool_entry_put: %s\n",
|
||||
text->bv_val, 0, 0 );
|
||||
e->e_id = NOID;
|
||||
}
|
||||
|
||||
} else {
|
||||
txn_abort( tid );
|
||||
snprintf( text->bv_val, text->bv_len,
|
||||
"txn_aborted! %s (%d)",
|
||||
db_strerror(rc), rc );
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"=> bdb_tool_entry_put: txn_aborted! %s (%d)\n",
|
||||
db_strerror(rc), rc, 0 );
|
||||
"=> bdb_tool_entry_put: %s\n",
|
||||
text->bv_val, 0, 0 );
|
||||
e->e_id = NOID;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,8 @@ Entry* ldbm_tool_entry_get( BackendDB *be, ID id )
|
|||
|
||||
ID ldbm_tool_entry_put(
|
||||
BackendDB *be,
|
||||
Entry *e )
|
||||
Entry *e,
|
||||
struct berval *text )
|
||||
{
|
||||
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
||||
Datum key, data;
|
||||
|
|
@ -176,7 +177,12 @@ ID ldbm_tool_entry_put(
|
|||
assert( slapMode & SLAP_TOOL_MODE );
|
||||
assert( id2entry != NULL );
|
||||
|
||||
assert( text );
|
||||
assert( text->bv_val );
|
||||
assert( text->bv_val[0] == '\0' );
|
||||
|
||||
if ( next_id_get( be, &id ) || id == NOID ) {
|
||||
strncpy( text->bv_val, "unable to get nextid", text->bv_len );
|
||||
return NOID;
|
||||
}
|
||||
|
||||
|
|
@ -192,6 +198,7 @@ ID ldbm_tool_entry_put(
|
|||
|
||||
if ( dn2id( be, &e->e_nname, &id ) ) {
|
||||
/* something bad happened to ldbm cache */
|
||||
strncpy( text->bv_val, "ldbm cache corrupted", text->bv_len );
|
||||
return NOID;
|
||||
}
|
||||
|
||||
|
|
@ -205,16 +212,19 @@ ID ldbm_tool_entry_put(
|
|||
"<= ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n",
|
||||
e->e_ndn, id, 0 );
|
||||
#endif
|
||||
strncpy( text->bv_val, "already exists", text->bv_len );
|
||||
return NOID;
|
||||
}
|
||||
|
||||
rc = index_entry_add( be, e, e->e_attrs );
|
||||
if( rc != 0 ) {
|
||||
strncpy( text->bv_val, "index add failed", text->bv_len );
|
||||
return NOID;
|
||||
}
|
||||
|
||||
rc = dn2id_add( be, &e->e_nname, e->e_id );
|
||||
if( rc != 0 ) {
|
||||
strncpy( text->bv_val, "dn2id add failed", text->bv_len );
|
||||
return NOID;
|
||||
}
|
||||
|
||||
|
|
@ -237,6 +247,7 @@ ID ldbm_tool_entry_put(
|
|||
|
||||
if( rc != 0 ) {
|
||||
(void) dn2id_delete( be, &e->e_nname, e->e_id );
|
||||
strncpy( text->bv_val, "cache store failed", text->bv_len );
|
||||
return NOID;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -717,7 +717,8 @@ glue_tool_entry_get (
|
|||
static ID
|
||||
glue_tool_entry_put (
|
||||
BackendDB *b0,
|
||||
Entry *e
|
||||
Entry *e,
|
||||
struct berval *text
|
||||
)
|
||||
{
|
||||
BackendDB *be;
|
||||
|
|
@ -742,7 +743,7 @@ glue_tool_entry_put (
|
|||
return NOID;
|
||||
}
|
||||
glueBack = be;
|
||||
return be->be_entry_put (be, e);
|
||||
return be->be_entry_put (be, e, text);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -1205,7 +1205,8 @@ typedef int (BI_tool_entry_close) LDAP_P(( BackendDB *be ));
|
|||
typedef ID (BI_tool_entry_first) LDAP_P(( BackendDB *be ));
|
||||
typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be ));
|
||||
typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
|
||||
typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e ));
|
||||
typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e,
|
||||
struct berval *text ));
|
||||
typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
|
||||
typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ main( int argc, char **argv )
|
|||
int rc = EXIT_SUCCESS;
|
||||
|
||||
const char *text;
|
||||
char textbuf[SLAP_TEXT_BUFLEN];
|
||||
char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
|
||||
size_t textlen = sizeof textbuf;
|
||||
|
||||
slap_tool_init( "slapadd", SLAPADD, argc, argv );
|
||||
|
|
@ -55,6 +55,8 @@ main( int argc, char **argv )
|
|||
while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
|
||||
ID id;
|
||||
Entry *e = str2entry( buf );
|
||||
char buf[1024];
|
||||
struct berval bvtext = { textlen, textbuf };
|
||||
|
||||
if( e == NULL ) {
|
||||
fprintf( stderr, "%s: could not parse entry (line=%d)\n",
|
||||
|
|
@ -146,10 +148,10 @@ main( int argc, char **argv )
|
|||
}
|
||||
}
|
||||
|
||||
id = be->be_entry_put( be, e );
|
||||
id = be->be_entry_put( be, e, &bvtext );
|
||||
if( id == NOID ) {
|
||||
fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
|
||||
progname, e->e_dn, lineno );
|
||||
fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d): %s\n",
|
||||
progname, e->e_dn, lineno, bvtext.bv_val );
|
||||
rc = EXIT_FAILURE;
|
||||
entry_free( e );
|
||||
if( continuemode ) continue;
|
||||
|
|
|
|||
Loading…
Reference in a new issue