X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Frequest.c;h=5c018ca7b88e4bcdff6b2c8c8e60ddbc7e617035;hb=4a2b9b21951cb9966f98cd49064e856f6ff7e6a4;hp=6a707ec466ac947973f351eb8a9d546af82e34a0;hpb=b08f7e8bce4f006ce32ef7b45734668947e32ea6;p=openldap diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index 6a707ec466..5c018ca7b8 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -1,6 +1,6 @@ /* $OpenLDAP$ */ /* - * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ /* Portions @@ -83,7 +83,11 @@ ldap_send_initial_request( LDAPURLDesc *servers; int rc; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ENTRY, "ldap_send_initial_request\n" )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_send_initial_request\n", 0, 0, 0 ); +#endif if ( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) { /* not connected yet */ @@ -94,9 +98,14 @@ ldap_send_initial_request( return( -1 ); } +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_send_initial_request: ldap_open_defconn: successful\n" )); +#else Debug( LDAP_DEBUG_TRACE, - "ldap_delayed_open successful, ld_host is %s\n", - ( ld->ld_host == NULL ) ? "(null)" : ld->ld_host, 0, 0 ); + "ldap_open_defconn: successful\n", + 0, 0, 0 ); +#endif } { @@ -107,6 +116,18 @@ ldap_send_initial_request( servers = NULL; } +#ifdef LDAP_CONNECTIONLESS + if (LDAP_IS_UDP(ld)) { + if (msgtype == LDAP_REQ_BIND) { + if (ld->ld_options.ldo_cldapdn) + ldap_memfree(ld->ld_options.ldo_cldapdn); + ld->ld_options.ldo_cldapdn = ldap_strdup(dn); + return 0; + } + if (msgtype != LDAP_REQ_ABANDON && msgtype != LDAP_REQ_SEARCH) + return LDAP_PARAM_ERROR; + } +#endif rc = ldap_send_server_request( ld, ber, ld->ld_msgid, NULL, servers, NULL, NULL ); if (servers) @@ -129,7 +150,11 @@ ldap_send_server_request( LDAPRequest *lr; int incparent; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ENTRY, "ldap_send_server_request\n" )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_send_server_request\n", 0, 0, 0 ); +#endif incparent = 0; ld->ld_errno = LDAP_SUCCESS; /* optimistic */ @@ -187,8 +212,8 @@ ldap_send_server_request( lr->lr_origid = parentreq->lr_origid; lr->lr_parentcnt = parentreq->lr_parentcnt + 1; lr->lr_parent = parentreq; - lr->lr_refnext = parentreq->lr_refnext; - parentreq->lr_refnext = lr; + lr->lr_refnext = parentreq->lr_child; + parentreq->lr_child = lr; } else { /* original request */ lr->lr_origid = lr->lr_msgid; } @@ -237,7 +262,11 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, LDAPURLDesc *srv; Sockbuf *sb = NULL; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ENTRY, "ldap_new_connection\n" )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_new_connection\n", 0, 0, 0 ); +#endif /* * make a new LDAP server connection * XXX open connection synchronously for now @@ -289,7 +318,7 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, */ lc->lconn_rebind_inprogress = 1; /* V3 rebind function */ - if ( ld->ld_rebindproc != NULL) { + if ( ld->ld_rebind_proc != NULL) { LDAPURLDesc *srvfunc; if( ( srvfunc = ldap_url_dup( srvlist)) == NULL) { ld->ld_errno = LDAP_NO_MEMORY; @@ -299,8 +328,15 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, ++lc->lconn_refcnt; /* avoid premature free */ ld->ld_defconn = lc; - Debug( LDAP_DEBUG_TRACE, "Call application rebindproc\n", 0, 0, 0); - err = (*ld->ld_rebindproc)( ld, bind->ri_url, bind->ri_request, bind->ri_msgid); +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_new_connection: Call application rebind_proc\n" )); +#else + Debug( LDAP_DEBUG_TRACE, "Call application rebind_proc\n", 0, 0, 0); +#endif + err = (*ld->ld_rebind_proc)( ld, + bind->ri_url, bind->ri_request, bind->ri_msgid, + ld->ld_rebind_params ); ld->ld_defconn = savedefconn; --lc->lconn_refcnt; @@ -317,7 +353,12 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, ++lc->lconn_refcnt; /* avoid premature free */ ld->ld_defconn = lc; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_new_connection: anonymous rebind via ldap_bind_s\n" )); +#else Debug( LDAP_DEBUG_TRACE, "anonymous rebind via ldap_bind_s\n", 0, 0, 0); +#endif if ( ldap_bind_s( ld, "", "", LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) { err = -1; } @@ -380,7 +421,11 @@ ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind ) { LDAPConn *tmplc, *prevlc; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ENTRY, "ldap_free_connection\n" )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_free_connection\n", 0, 0, 0 ); +#endif if ( force || --lc->lconn_refcnt <= 0 ) { if ( lc->lconn_status == LDAP_CONNST_CONNECTED ) { @@ -426,12 +471,22 @@ ldap_free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind ) LDAP_FREE( lc->lconn_rebind_queue); } LDAP_FREE( lc ); +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_RESULTS, + "ldap_free_connection: actually freed\n" )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_free_connection: actually freed\n", 0, 0, 0 ); +#endif } else { lc->lconn_lastused = time( NULL ); +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_RESULTS, + "ldap_free_connection: refcnt %d\n", lc->lconn_refcnt )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_free_connection: refcnt %d\n", lc->lconn_refcnt, 0, 0 ); +#endif } } @@ -523,25 +578,9 @@ ldap_dump_requests_and_responses( LDAP *ld ) } #endif /* LDAP_DEBUG */ - void -ldap_free_request( LDAP *ld, LDAPRequest *lr ) +ldap_free_request_int( LDAP *ld, LDAPRequest *lr ) { - LDAPRequest *tmplr, *nextlr; - - Debug( LDAP_DEBUG_TRACE, "ldap_free_request (origid %d, msgid %d)\n", - lr->lr_origid, lr->lr_msgid, 0 ); - - if ( lr->lr_parent != NULL ) { - --lr->lr_parent->lr_outrefcnt; - } else { - /* free all referrals (child requests) */ - for ( tmplr = lr->lr_refnext; tmplr != NULL; tmplr = nextlr ) { - nextlr = tmplr->lr_refnext; - ldap_free_request( ld, tmplr ); - } - } - if ( lr->lr_prev == NULL ) { ld->ld_requests = lr->lr_next; } else { @@ -567,6 +606,34 @@ ldap_free_request( LDAP *ld, LDAPRequest *lr ) LDAP_FREE( lr ); } +void +ldap_free_request( LDAP *ld, LDAPRequest *lr ) +{ + LDAPRequest **ttmplr; + +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ARGS, + "ldap_free_request (origid %d, msgid %d)\n", + lr->lr_origid, lr->lr_msgid )); +#else + Debug( LDAP_DEBUG_TRACE, "ldap_free_request (origid %d, msgid %d)\n", + lr->lr_origid, lr->lr_msgid, 0 ); +#endif + + if ( lr->lr_parent != NULL ) { + --lr->lr_parent->lr_outrefcnt; + for ( ttmplr = &lr->lr_parent->lr_child; *ttmplr && *ttmplr != lr; ttmplr = &(*ttmplr)->lr_refnext ); + if ( *ttmplr == lr ) + *ttmplr = lr->lr_refnext; + } else { + /* free all referrals (child requests) */ + while ( lr->lr_child ) + ldap_free_request( ld, lr->lr_child ); + } + ldap_free_request_int( ld, lr ); +} + + /* * Chase v3 referrals * @@ -597,7 +664,11 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * ld->ld_errno = LDAP_SUCCESS; /* optimistic */ *hadrefp = 0; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ENTRY, "ldap_chase_v3referrals\n" )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_chase_v3referrals\n", 0, 0, 0 ); +#endif unfollowed = NULL; rc = count = 0; @@ -610,8 +681,14 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * /* Check for hop limit exceeded */ if ( lr->lr_parentcnt >= ld->ld_refhoplimit ) { +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_chase_v3referrals: more than %d referral hops (dropping)\n", + ld->ld_refhoplimit )); +#else Debug( LDAP_DEBUG_ANY, "more than %d referral hops (dropping)\n", ld->ld_refhoplimit, 0, 0 ); +#endif ld->ld_errno = LDAP_REFERRAL_LIMIT_EXCEEDED; rc = -1; goto done; @@ -659,9 +736,15 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * * if two search references come in one behind the other * for the same server with different contexts. */ +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_chase_v3referrals: queue referral \"%s\"\n", + refarray[i] )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_chase_v3referrals: queue referral \"%s\"\n", refarray[i], 0, 0); +#endif if( lc->lconn_rebind_queue == NULL ) { /* Create a referral list */ lc->lconn_rebind_queue = @@ -723,9 +806,15 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * goto done; } +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_chase_v3referrals: msgid %d, url \"%s\"\n", + lr->lr_msgid, refarray[i] )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_chase_v3referral: msgid %d, url \"%s\"\n", lr->lr_msgid, refarray[i], 0); +#endif /* Send the new request to the server - may require a bind */ rinfo.ri_msgid = origreq->lr_origid; @@ -733,8 +822,14 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * if ( (rc = ldap_send_server_request( ld, ber, ld->ld_msgid, origreq, srv, NULL, &rinfo )) < 0 ) { /* Failure, try next referral in the list */ +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ERR, + "ldap_chase_v3referrals: Unable to chase referral \"%s\" (%s)\n", + refarray[i], ldap_err2string( ld->ld_errno ) )); +#else Debug( LDAP_DEBUG_ANY, "Unable to chase referral \"%s\" (%s)\n", refarray[i], ldap_err2string( ld->ld_errno ), 0); +#endif unfollowedcnt += ldap_append_referral( ld, &unfollowed, refarray[i]); ldap_free_urllist(srv); srv = NULL; @@ -811,7 +906,11 @@ ldap_chase_referrals( LDAP *ld, BerElement *ber; LDAPreqinfo rinfo; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ENTRY, "ldap_chase_referrals\n" )); +#else Debug( LDAP_DEBUG_TRACE, "ldap_chase_referrals\n", 0, 0, 0 ); +#endif ld->ld_errno = LDAP_SUCCESS; /* optimistic */ *hadrefp = 0; @@ -834,9 +933,15 @@ ldap_chase_referrals( LDAP *ld, } if ( lr->lr_parentcnt >= ld->ld_refhoplimit ) { +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ENTRY, + "ldap_chase_referrals: more than %d referral hops (dropping)\n", + ld->ld_refhoplimit )); +#else Debug( LDAP_DEBUG_ANY, "more than %d referral hops (dropping)\n", ld->ld_refhoplimit, 0, 0 ); +#endif /* XXX report as error in ld->ld_errno? */ return( 0 ); } @@ -861,8 +966,14 @@ ldap_chase_referrals( LDAP *ld, rc = ldap_url_parse_ext( ref, &srv ); if ( rc != LDAP_URL_SUCCESS ) { +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_chase_referrals: ignoring unknown referral <%s>\n", + ref )); +#else Debug( LDAP_DEBUG_TRACE, "ignoring unknown referral <%s>\n", ref, 0, 0 ); +#endif rc = ldap_append_referral( ld, &unfollowed, ref ); *hadrefp = 1; continue; @@ -873,8 +984,13 @@ ldap_chase_referrals( LDAP *ld, srv->lud_dn = NULL; } +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "ldap_chase_referrals: chasing LDAP referral <%s>\n", ref )); +#else Debug( LDAP_DEBUG_TRACE, "chasing LDAP referral: <%s>\n", ref, 0, 0 ); +#endif *hadrefp = 1; @@ -898,9 +1014,15 @@ ldap_chase_referrals( LDAP *ld, if( rc >= 0 ) { ++count; } else { +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ERR, + "ldap_chase_referrals: Unable to chase referral <%s>\n", + ldap_err2string( ld->ld_errno) )); +#else Debug( LDAP_DEBUG_ANY, "Unable to chase referral (%s)\n", ldap_err2string( ld->ld_errno ), 0, 0 ); +#endif rc = ldap_append_referral( ld, &unfollowed, ref ); } @@ -959,6 +1081,7 @@ re_encode_request( LDAP *ld, */ ber_int_t along; ber_tag_t tag; + ber_tag_t rtag; ber_int_t ver; ber_int_t scope; int rc; @@ -966,10 +1089,17 @@ re_encode_request( LDAP *ld, char *orig_dn; char *dn; +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_ARGS, + "re_encode_request: new msgid %ld, new dn <%s>\n", + (long) msgid, + ( srv == NULL || srv->lud_dn == NULL ) ? "NONE" : srv->lud_dn )); +#else Debug( LDAP_DEBUG_TRACE, "re_encode_request: new msgid %ld, new dn <%s>\n", (long) msgid, ( srv == NULL || srv->lud_dn == NULL) ? "NONE" : srv->lud_dn, 0 ); +#endif tmpber = *origber; @@ -979,9 +1109,9 @@ re_encode_request( LDAP *ld, * tagged with the operation code. For delete, the provided DN * is not wrapped by a sequence. */ - rc = ber_scanf( &tmpber, "{it", /*}*/ &along, &tag ); + rtag = ber_scanf( &tmpber, "{it", /*}*/ &along, &tag ); - if ( rc == LBER_ERROR ) { + if ( rtag == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; return( NULL ); } @@ -989,15 +1119,15 @@ re_encode_request( LDAP *ld, assert( tag != 0); if ( tag == LDAP_REQ_BIND ) { /* bind requests have a version number before the DN & other stuff */ - rc = ber_scanf( &tmpber, "{ia" /*}*/, &ver, &orig_dn ); + rtag = ber_scanf( &tmpber, "{ia" /*}*/, &ver, &orig_dn ); } else if ( tag == LDAP_REQ_DELETE ) { /* delete requests don't have a DN wrapping sequence */ - rc = ber_scanf( &tmpber, "a", &orig_dn ); + rtag = ber_scanf( &tmpber, "a", &orig_dn ); } else if ( tag == LDAP_REQ_SEARCH ) { /* search requests need to be re-scope-ed */ - rc = ber_scanf( &tmpber, "{ae" /*"}"*/, &orig_dn, &scope ); + rtag = ber_scanf( &tmpber, "{ae" /*"}"*/, &orig_dn, &scope ); if( srv->lud_scope != LDAP_SCOPE_DEFAULT ) { /* use the scope provided in reference */ @@ -1012,10 +1142,10 @@ re_encode_request( LDAP *ld, } } else { - rc = ber_scanf( &tmpber, "{a" /*}*/, &orig_dn ); + rtag = ber_scanf( &tmpber, "{a" /*}*/, &orig_dn ); } - if( rc == LBER_ERROR ) { + if( rtag == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; return NULL; } @@ -1060,8 +1190,13 @@ re_encode_request( LDAP *ld, #ifdef LDAP_DEBUG if ( ldap_debug & LDAP_DEBUG_PACKETS ) { +#ifdef NEW_LOGGING + LDAP_LOG (( "request", LDAP_LEVEL_DETAIL1, + "re_encode_request: new request is:\n" )); +#else Debug( LDAP_DEBUG_ANY, "re_encode_request new request is:\n", 0, 0, 0 ); +#endif ber_log_dump( LDAP_DEBUG_BER, ldap_debug, ber, 0 ); } #endif /* LDAP_DEBUG */