improve logging

This commit is contained in:
Pierangelo Masarati 2004-04-14 12:50:11 +00:00
parent 62198f1c2e
commit ec34062ed4

View File

@ -518,7 +518,7 @@ backsql_add( Operation *op, SlapReply *rs )
int prc; int prc;
struct berval realdn, realpdn; struct berval realdn, realpdn;
Debug( LDAP_DEBUG_TRACE, "==>backsql_add(): adding entry \"%s\"\n", Debug( LDAP_DEBUG_TRACE, "==>backsql_add(\"%s\")\n",
op->oq_add.rs_e->e_name.bv_val, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
/* check schema */ /* check schema */
@ -529,9 +529,9 @@ backsql_add( Operation *op, SlapReply *rs )
NULL, NULL,
&rs->sr_text, textbuf, sizeof( textbuf ) ); &rs->sr_text, textbuf, sizeof( textbuf ) );
if ( rs->sr_err != LDAP_SUCCESS ) { if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"entry failed schema check -- aborting\n", "entry failed schema check -- aborting\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
goto done; goto done;
} }
} }
@ -550,27 +550,33 @@ backsql_add( Operation *op, SlapReply *rs )
oc = backsql_name2oc( bi, &at->a_vals[0] ); oc = backsql_name2oc( bi, &at->a_vals[0] );
if ( oc == NULL ) { if ( oc == NULL ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"cannot determine objectclass of entry -- aborting\n", "cannot map structuralObjectClass \"%s\" -- aborting\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val,
at->a_vals[0].bv_val, 0 );
rs->sr_err = LDAP_UNWILLING_TO_PERFORM; rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "operation not permitted within namingContext"; rs->sr_text = "operation not permitted within namingContext";
goto done; goto done;
} }
if ( oc->bom_create_proc == NULL ) { if ( oc->bom_create_proc == NULL ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"create procedure is not defined for this objectclass " "create procedure is not defined "
"- aborting\n", 0, 0, 0 ); "for structuralObjectClass \"%s\" - aborting\n",
op->oq_add.rs_e->e_name.bv_val,
at->a_vals[0].bv_val, 0 );
rs->sr_err = LDAP_UNWILLING_TO_PERFORM; rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "operation not permitted within namingContext"; rs->sr_text = "operation not permitted within namingContext";
goto done; goto done;
} else if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) } else if ( BACKSQL_CREATE_NEEDS_SELECT( bi )
&& oc->bom_create_keyval == NULL ) { && oc->bom_create_keyval == NULL ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"create procedure needs select procedure, " "create procedure needs select procedure, "
"but none is defined - aborting\n", 0, 0, 0 ); "but none is defined for structuralObjectClass \"%s\" "
"- aborting\n",
op->oq_add.rs_e->e_name.bv_val,
at->a_vals[0].bv_val, 0 );
rs->sr_err = LDAP_UNWILLING_TO_PERFORM; rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "operation not permitted within namingContext"; rs->sr_text = "operation not permitted within namingContext";
goto done; goto done;
@ -578,9 +584,9 @@ backsql_add( Operation *op, SlapReply *rs )
rs->sr_err = backsql_get_db_conn( op, &dbh ); rs->sr_err = backsql_get_db_conn( op, &dbh );
if ( rs->sr_err != LDAP_SUCCESS ) { if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"could not get connection handle - exiting\n", "could not get connection handle - exiting\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
rs->sr_text = ( rs->sr_err == LDAP_OTHER ) rs->sr_text = ( rs->sr_err == LDAP_OTHER )
? "SQL-backend error" : NULL; ? "SQL-backend error" : NULL;
goto done; goto done;
@ -591,9 +597,10 @@ backsql_add( Operation *op, SlapReply *rs )
*/ */
realdn = op->oq_add.rs_e->e_name; realdn = op->oq_add.rs_e->e_name;
if ( backsql_api_dn2odbc( op, rs, &realdn ) ) { if ( backsql_api_dn2odbc( op, rs, &realdn ) ) {
Debug( LDAP_DEBUG_TRACE, "backsql_search(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"backsql_api_dn2odbc failed\n", "backsql_api_dn2odbc(\"%s\") failed\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val,
op->oq_add.rs_e->e_name.bv_val, 0 );
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error"; rs->sr_text = "SQL-backend error";
goto done; goto done;
@ -601,8 +608,8 @@ backsql_add( Operation *op, SlapReply *rs )
rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realdn ); rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realdn );
if ( rs->sr_err == LDAP_SUCCESS ) { if ( rs->sr_err == LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"entry \"%s\" exists\n", "entry exists\n",
op->oq_add.rs_e->e_name.bv_val, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
rs->sr_err = LDAP_ALREADY_EXISTS; rs->sr_err = LDAP_ALREADY_EXISTS;
goto done; goto done;
@ -614,9 +621,9 @@ backsql_add( Operation *op, SlapReply *rs )
dnParent( &op->oq_add.rs_e->e_name, &pdn ); dnParent( &op->oq_add.rs_e->e_name, &pdn );
realpdn = pdn; realpdn = pdn;
if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) { if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
Debug( LDAP_DEBUG_TRACE, "backsql_search(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"backsql_api_dn2odbc failed\n", "backsql_api_dn2odbc(\"%s\") failed\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, pdn.bv_val, 0 );
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error"; rs->sr_text = "SQL-backend error";
goto done; goto done;
@ -624,9 +631,9 @@ backsql_add( Operation *op, SlapReply *rs )
rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &realpdn ); rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &realpdn );
if ( rs->sr_err != LDAP_SUCCESS ) { if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"could not lookup parent entry for new record \"%s\"\n", "could not lookup parent entry for new record \"%s\"\n",
pdn.bv_val, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, pdn.bv_val, 0 );
if ( rs->sr_err != LDAP_NO_SUCH_OBJECT ) { if ( rs->sr_err != LDAP_NO_SUCH_OBJECT ) {
goto done; goto done;
@ -651,9 +658,10 @@ backsql_add( Operation *op, SlapReply *rs )
*/ */
realpdn = pdn; realpdn = pdn;
if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) { if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) {
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE,
" backsql_add(\"%s\"): "
"backsql_api_dn2odbc failed\n", "backsql_api_dn2odbc failed\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
rs->sr_text = "SQL-backend error"; rs->sr_text = "SQL-backend error";
goto done; goto done;
@ -707,12 +715,13 @@ backsql_add( Operation *op, SlapReply *rs )
SQL_INTEGER, 0, 0, &new_keyval, 0, 0 ); SQL_INTEGER, 0, 0, &new_keyval, 0, 0 );
} }
Debug( LDAP_DEBUG_TRACE, " backsql_add(): executing \"%s\"\n", Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): executing \"%s\"\n",
oc->bom_create_proc, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, oc->bom_create_proc, 0 );
rc = SQLExecDirect( sth, oc->bom_create_proc, SQL_NTS ); rc = SQLExecDirect( sth, oc->bom_create_proc, SQL_NTS );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"create_proc execution failed\n", 0, 0, 0 ); "create_proc execution failed\n",
op->oq_add.rs_e->e_name.bv_val, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
@ -754,9 +763,9 @@ backsql_add( Operation *op, SlapReply *rs )
*/ */
rc = SQLNumResultCols( sth, &ncols ); rc = SQLNumResultCols( sth, &ncols );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"create_proc result evaluation failed\n", "create_proc result evaluation failed\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
@ -764,9 +773,9 @@ backsql_add( Operation *op, SlapReply *rs )
goto done; goto done;
} else if ( ncols != 1 ) { } else if ( ncols != 1 ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"create_proc result is bogus (ncols=%d)\n", "create_proc result is bogus (ncols=%d)\n",
ncols, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, ncols, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
@ -800,9 +809,9 @@ backsql_add( Operation *op, SlapReply *rs )
rc = SQLFetch( sth ); rc = SQLFetch( sth );
if ( value_len <= 0 ) { if ( value_len <= 0 ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"create_proc result is empty?\n", "create_proc result is empty?\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
@ -817,8 +826,9 @@ backsql_add( Operation *op, SlapReply *rs )
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
#endif /* BACKSQL_REALLOC_STMT */ #endif /* BACKSQL_REALLOC_STMT */
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"create_proc returned keyval=%ld\n", new_keyval, 0, 0 ); "create_proc returned keyval=%ld\n",
op->oq_add.rs_e->e_name.bv_val, new_keyval, 0 );
for ( at = op->oq_add.rs_e->e_attrs; at != NULL; at = at->a_next ) { for ( at = op->oq_add.rs_e->e_attrs; at != NULL; at = at->a_next ) {
SQLUSMALLINT currpos; SQLUSMALLINT currpos;
@ -841,11 +851,12 @@ backsql_add( Operation *op, SlapReply *rs )
at_rec = backsql_ad2at( oc, at->a_desc ); at_rec = backsql_ad2at( oc, at->a_desc );
if ( at_rec == NULL ) { if ( at_rec == NULL ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"attribute \"%s\" is not registered " "attribute \"%s\" is not registered "
"in objectclass \"%s\"\n", "in objectclass \"%s\"\n",
op->oq_add.rs_e->e_name.bv_val,
at->a_desc->ad_cname.bv_val, at->a_desc->ad_cname.bv_val,
BACKSQL_OC_NAME( oc ), 0 ); BACKSQL_OC_NAME( oc ) );
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
rs->sr_err = LDAP_UNWILLING_TO_PERFORM; rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
@ -858,10 +869,13 @@ backsql_add( Operation *op, SlapReply *rs )
} }
if ( at_rec->bam_add_proc == NULL ) { if ( at_rec->bam_add_proc == NULL ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"add procedure is not defined " "add procedure is not defined "
"for attribute \"%s\"\n", "for attribute \"%s\" "
at->a_desc->ad_cname.bv_val, 0, 0 ); "of structuralObjectClass \"%s\"\n",
op->oq_add.rs_e->e_name.bv_val,
at->a_desc->ad_cname.bv_val,
BACKSQL_OC_NAME( oc ) );
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
rs->sr_err = LDAP_UNWILLING_TO_PERFORM; rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
@ -906,6 +920,7 @@ backsql_add( Operation *op, SlapReply *rs )
for ( i = 0, at_val = &at->a_vals[ i ]; for ( i = 0, at_val = &at->a_vals[ i ];
at_val->bv_val != NULL; at_val->bv_val != NULL;
i++, at_val = &at->a_vals[ i ] ) { i++, at_val = &at->a_vals[ i ] ) {
char logbuf[] = "val[18446744073709551615UL], id=18446744073709551615UL";
/* /*
* Do not deal with the objectClass that is used * Do not deal with the objectClass that is used
@ -924,14 +939,14 @@ backsql_add( Operation *op, SlapReply *rs )
backsql_BindParamStr( sth, currpos, backsql_BindParamStr( sth, currpos,
at_val->bv_val, at_val->bv_len + 1 ); at_val->bv_val, at_val->bv_len + 1 );
#ifdef SECURITY_PARANOID
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " #ifdef LDAP_DEBUG
"executing \"%s\", id=%ld\n", snprintf( logbuf, sizeof( logbuf ), "val[%d], id=%ld",
at_rec->bam_add_proc, new_keyval, 0 ); i, new_keyval );
#else Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " "executing \"%s\" %s\n",
"executing \"%s\" for val[%d], id=%ld\n", op->oq_add.rs_e->e_name.bv_val,
at_rec->bam_add_proc, i, new_keyval ); at_rec->bam_add_proc, logbuf );
#endif #endif
#ifndef BACKSQL_REALLOC_STMT #ifndef BACKSQL_REALLOC_STMT
rc = SQLExecDirect( sth, at_rec->bam_add_proc, SQL_NTS ); rc = SQLExecDirect( sth, at_rec->bam_add_proc, SQL_NTS );
@ -939,9 +954,10 @@ backsql_add( Operation *op, SlapReply *rs )
rc = SQLExecute( sth ); rc = SQLExecute( sth );
#endif /* BACKSQL_REALLOC_STMT */ #endif /* BACKSQL_REALLOC_STMT */
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE,
" backsql_add(\"%s\"): "
"add_proc execution failed\n", "add_proc execution failed\n",
0, 0, 0 ); op->oq_add.rs_e->e_name.bv_val, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc ); backsql_PrintErrors( bi->db_env, dbh, sth, rc );
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
@ -998,8 +1014,9 @@ backsql_add( Operation *op, SlapReply *rs )
rc = SQLExecute( sth ); rc = SQLExecute( sth );
#endif /* BACKSQL_REALLOC_STMT */ #endif /* BACKSQL_REALLOC_STMT */
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(): " Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"could not insert ldap_entries record\n", 0, 0, 0 ); "could not insert ldap_entries record\n",
op->oq_add.rs_e->e_name.bv_val, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc ); backsql_PrintErrors( bi->db_env, dbh, sth, rc );
/* /*
@ -1043,9 +1060,9 @@ done:;
backsql_free_entryID( &parent_id, 0 ); backsql_free_entryID( &parent_id, 0 );
} }
Debug( LDAP_DEBUG_TRACE, "<==backsql_add(): %d%s%s\n", Debug( LDAP_DEBUG_TRACE, "<==backsql_add(\"%s\"): %d \"%s\"\n",
op->oq_add.rs_e->e_name.bv_val,
rs->sr_err, rs->sr_err,
rs->sr_text ? ": " : "",
rs->sr_text ? rs->sr_text : "" ); rs->sr_text ? rs->sr_text : "" );
return ( ( rs->sr_err == LDAP_SUCCESS ) ? op->o_noop : 1 ); return ( ( rs->sr_err == LDAP_SUCCESS ) ? op->o_noop : 1 );