From: Kurt Zeilenga Date: Fri, 3 Mar 2000 22:37:06 +0000 (+0000) Subject: Rework error handling. Add error descriptions. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~3162 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4710c74605d21f17a3292806ed7e02e81b9af450;p=openldap Rework error handling. Add error descriptions. Don't use LDAP_OPERATIONS_ERROR for internal errors. Use LDAP_OTHER instead. (more changes needed in this area) --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 3b20cde293..ed710f0afa 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -48,8 +48,8 @@ do_add( Connection *conn, Operation *op ) LDAPModList *modlist = NULL; LDAPModList **modtail = &modlist; Modifications *mods = NULL; - char *text; #endif + char *text; int rc = LDAP_SUCCESS; Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 ); @@ -181,11 +181,11 @@ do_add( Connection *conn, Operation *op ) } /* make sure this backend recongizes critical controls */ - rc = backend_check_controls( be, conn, op ) ; + rc = backend_check_controls( be, conn, op, &text ) ; if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, text, NULL, NULL ); goto done; } @@ -238,8 +238,7 @@ do_add( Connection *conn, Operation *op ) #endif if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, text, - NULL, NULL ); + NULL, text, NULL, NULL ); goto done; } } diff --git a/servers/slapd/back-ldbm/modify.c b/servers/slapd/back-ldbm/modify.c index b504462893..54c71a8d76 100644 --- a/servers/slapd/back-ldbm/modify.c +++ b/servers/slapd/back-ldbm/modify.c @@ -159,7 +159,7 @@ int ldbm_modify_internal( /* modify indexes */ if ( index_add_mods( be, modlist, e->e_id ) != 0 ) { /* our indices are likely hosed */ - return LDAP_OPERATIONS_ERROR; + return LDAP_OTHER; } return LDAP_SUCCESS; @@ -241,7 +241,7 @@ ldbm_back_modify( /* change the entry itself */ if ( id2entry_add( be, e ) != 0 ) { - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, NULL, NULL, NULL ); goto error_return; } diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 7c58eb0baf..0d8a3114a4 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -143,7 +143,7 @@ ldbm_back_modrdn( if( (p = dn2entry_w( be, p_ndn, NULL )) == NULL) { Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0, 0, 0); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, NULL, NULL, NULL ); goto return_results; } @@ -206,7 +206,7 @@ ldbm_back_modrdn( 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, + send_ldap_result( conn, op, LDAP_OTHER, NULL, NULL, NULL, NULL ); goto return_results; } @@ -422,7 +422,7 @@ ldbm_back_modrdn( /* delete old one */ if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) { - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, NULL, NULL, NULL ); goto return_results; } @@ -440,7 +440,7 @@ ldbm_back_modrdn( /* add new one */ if ( dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) { - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, NULL, NULL, NULL ); goto return_results; } @@ -466,7 +466,7 @@ ldbm_back_modrdn( /* id2entry index */ if ( id2entry_add( be, e ) != 0 ) { entry_free( e ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, NULL, NULL, NULL ); goto return_results; } diff --git a/servers/slapd/back-ldbm/passwd.c b/servers/slapd/back-ldbm/passwd.c index 7ba0f5d9be..bafe00d6af 100644 --- a/servers/slapd/back-ldbm/passwd.c +++ b/servers/slapd/back-ldbm/passwd.c @@ -63,7 +63,7 @@ ldbm_back_exop_passwd( new = slap_passwd_generate(); if( new == NULL || new->bv_len == 0 ) { - *text = ch_strdup("password generation failed."); + *text = "password generation failed."; rc = LDAP_OPERATIONS_ERROR; goto done; } diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 353a025f16..1ad03e506d 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -592,7 +592,8 @@ int backend_check_controls( Backend *be, Connection *conn, - Operation *op ) + Operation *op, + char **text ) { LDAPControl **ctrls; ctrls = op->o_ctrls; @@ -604,6 +605,7 @@ backend_check_controls( if( (*ctrls)->ldctl_iscritical && !charray_inlist( be->be_controls, (*ctrls)->ldctl_oid ) ) { + *text = "control unavailable in NamingContext"; return LDAP_UNAVAILABLE_CRITICAL_EXTENSION; } } diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index 7f725d6df2..364f803201 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -41,6 +41,7 @@ do_bind( char *ndn; ber_tag_t tag; int rc = LDAP_SUCCESS; + char *text; struct berval cred; Backend *be; @@ -285,11 +286,11 @@ do_bind( conn->c_authz_backend = be; /* make sure this backend recongizes critical controls */ - rc = backend_check_controls( be, conn, op ) ; + rc = backend_check_controls( be, conn, op, &text ) ; if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, text, NULL, NULL ); goto cleanup; } diff --git a/servers/slapd/compare.c b/servers/slapd/compare.c index ae6d4e6ea2..1fbd5d3e38 100644 --- a/servers/slapd/compare.c +++ b/servers/slapd/compare.c @@ -43,6 +43,7 @@ do_compare( #else Ava ava; #endif + char *text; desc.bv_val = NULL; value.bv_val = NULL; @@ -140,11 +141,11 @@ do_compare( } /* make sure this backend recongizes critical controls */ - rc = backend_check_controls( be, conn, op ) ; + rc = backend_check_controls( be, conn, op, &text ) ; if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, text, NULL, NULL ); goto cleanup; } diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index b63367214a..79582c3300 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -31,7 +31,7 @@ do_delete( Operation *op ) { - char *dn, *ndn; + char *dn, *ndn, *text; Backend *be; int rc; @@ -79,11 +79,11 @@ do_delete( } /* make sure this backend recongizes critical controls */ - rc = backend_check_controls( be, conn, op ) ; + rc = backend_check_controls( be, conn, op, &text ) ; if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, text, NULL, NULL ); goto cleanup; } diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 7f953276a1..9c849cdcae 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -49,6 +49,7 @@ do_modify( Modifications *mods = NULL; Backend *be; int rc; + char *text; Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 ); @@ -180,11 +181,11 @@ do_modify( } /* make sure this backend recongizes critical controls */ - rc = backend_check_controls( be, conn, op ) ; + rc = backend_check_controls( be, conn, op, &text ) ; if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, text, NULL, NULL ); goto cleanup; } diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index c6fd2ae6cf..673af6881e 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -53,6 +53,7 @@ do_modrdn( Backend *newSuperior_be = NULL; ber_len_t length; int rc; + char *text; Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 ); @@ -108,7 +109,7 @@ do_modrdn( Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid new superior (%s)\n", newSuperior, 0, 0 ); send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL, - "invalid (new superior) DN", NULL, NULL ); + "new superior invalid", NULL, NULL ); goto cleanup; } @@ -165,11 +166,11 @@ do_modrdn( } /* make sure this backend recongizes critical controls */ - rc = backend_check_controls( be, conn, op ) ; + rc = backend_check_controls( be, conn, op, &text ) ; if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, text, NULL, NULL ); goto cleanup; } @@ -192,7 +193,7 @@ do_modrdn( rc = LDAP_AFFECTS_MULTIPLE_DSAS; send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, "cannot rename between DSAa", NULL, NULL ); goto cleanup; } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 0ade752f5b..d18feb867a 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -175,7 +175,8 @@ LIBSLAPD_F (int) backend_unbind LDAP_P((Connection *conn, Operation *op)); LIBSLAPD_F( int ) backend_check_controls LDAP_P(( Backend *be, Connection *conn, - Operation *op )); + Operation *op, + char **text )); LIBSLAPD_F (int) backend_connection_init LDAP_P((Connection *conn)); LIBSLAPD_F (int) backend_connection_destroy LDAP_P((Connection *conn)); diff --git a/servers/slapd/result.c b/servers/slapd/result.c index 6ea2c94fd6..cbd50098a9 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -650,8 +650,8 @@ send_search_entry( if ( ber == NULL ) { Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, "allocating BER error", NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "BER allocation error", NULL, NULL ); goto error_return; } @@ -661,8 +661,8 @@ send_search_entry( if ( rc == -1 ) { Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, "encoding dn error", NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "encoding DN error", NULL, NULL ); goto error_return; } @@ -719,8 +719,8 @@ send_search_entry( if (( rc = ber_printf( ber, "{s[" /*]}*/ , desc )) == -1 ) { Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, "encoding type error", NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "encoding description error", NULL, NULL ); goto error_return; } @@ -739,8 +739,8 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, "encoding value error", NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "encoding values error", NULL, NULL ); goto error_return; } } @@ -749,7 +749,7 @@ send_search_entry( if (( rc = ber_printf( ber, /*{[*/ "]}" )) == -1 ) { Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, "encode end error", NULL, NULL ); goto error_return; } @@ -806,8 +806,8 @@ send_search_entry( if (( rc = ber_printf( ber, "{s[" /*]}*/ , desc )) == -1 ) { Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, "encoding type error", NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "encoding description error", NULL, NULL ); goto error_return; } @@ -827,8 +827,8 @@ send_search_entry( Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, "encoding value error", NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "encoding values error", NULL, NULL ); goto error_return; } } @@ -837,7 +837,7 @@ send_search_entry( if (( rc = ber_printf( ber, /*{[*/ "]}" )) == -1 ) { Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, "encode end error", NULL, NULL ); goto error_return; } @@ -850,7 +850,7 @@ send_search_entry( if ( rc == -1 ) { Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, "encode entry end error", NULL, NULL ); return( 1 ); } @@ -946,7 +946,7 @@ send_search_reference( if ( ber == NULL ) { Debug( LDAP_DEBUG_ANY, "send_search_reference: ber_alloc failed\n", 0, 0, 0 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, + send_ldap_result( conn, op, LDAP_OTHER, NULL, "alloc BER error", NULL, NULL ); return -1; } @@ -958,8 +958,8 @@ send_search_reference( Debug( LDAP_DEBUG_ANY, "send_search_reference: ber_printf failed\n", 0, 0, 0 ); ber_free( ber, 1 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, "encode dn error", NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "encode DN error", NULL, NULL ); return -1; } diff --git a/servers/slapd/schema.c b/servers/slapd/schema.c index 3318ee1aa9..351e6cb2f2 100644 --- a/servers/slapd/schema.c +++ b/servers/slapd/schema.c @@ -58,8 +58,8 @@ schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly ) { /* Out of memory, do something about it */ entry_free( e ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, NULL, NULL, NULL ); + send_ldap_result( conn, op, LDAP_OTHER, + NULL, "out of memory", NULL, NULL ); return; } diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 41784771d1..590817048c 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -200,11 +200,11 @@ do_search( } /* make sure this backend recongizes critical controls */ - rc = backend_check_controls( be, conn, op ) ; + rc = backend_check_controls( be, conn, op, &text ) ; if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, - NULL, NULL, NULL, NULL ); + NULL, text, NULL, NULL ); goto return_results; }