From b26ecba01a671af6528e2888835a6f80eff4462e Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 21 Nov 2002 03:36:37 +0000 Subject: [PATCH] - allow interactive pagedResults size change - implement pagedResults abandon by setting size=0 - misc code cleanup --- clients/tools/ldapsearch.c | 42 ++++++++++++++++++++++++++------- servers/slapd/back-bdb/search.c | 21 ++++++++--------- servers/slapd/controls.c | 2 +- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 241e9c8071..753a426bd6 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -181,7 +181,7 @@ static int use_tls = 0; static char *sortattr = NULL; static int verbose, not, includeufn, vals2tmp, ldif; #ifdef LDAP_CONTROL_PAGEDRESULTS -static int pageSize; +static int pageSize = 0; static ber_int_t searchControlSize = 0; static ber_int_t morePagedResults = 1; static struct berval cookie = { 0, NULL }; @@ -222,7 +222,7 @@ main( int argc, char **argv ) #ifdef LDAP_CONTROL_PAGEDRESULTS BerElement *pageber = NULL; struct berval *bvalptr = NULL; - int num = 0, moreEntries, searchControlCrit = 0; + int num = 0, searchControlCrit = 0; #endif /* LDAP_CONTROL_PAGEDRESULTS */ @@ -336,7 +336,7 @@ main( int argc, char **argv ) #ifdef LDAP_CONTROL_PAGEDRESULTS } else if ( strcasecmp( control, "pr" ) == 0 ) { /* PagedResults control */ - if ( searchControlSize !=0 ) { + if ( pageSize != 0 ) { fprintf( stderr, "PagedResultsControl previously specified" ); return EXIT_FAILURE; } @@ -1025,7 +1025,7 @@ main( int argc, char **argv ) #ifdef LDAP_CONTROL_PAGEDRESULTS getNextPage: - if ( manageDSAit || noop || valuesReturnFilter || searchControlSize ) { + if ( manageDSAit || noop || valuesReturnFilter || pageSize ) { int critical = 0; #else /* !LDAP_CONTROL_PAGEDRESULTS */ if ( manageDSAit || noop || valuesReturnFilter ) { @@ -1119,7 +1119,7 @@ getNextPage: } #ifdef LDAP_CONTROL_PAGEDRESULTS - if ( searchControlSize ) { + if ( pageSize ) { if (( pageber = ber_alloc_t(LBER_USE_DER)) == NULL ) { return EXIT_FAILURE; } @@ -1227,6 +1227,11 @@ getNextPage: printf("\n# with valuesReturnFilter %scontrol: %s", valuesReturnFilter > 1 ? "critical " : "", vrFilter ); } + if ( pageSize ) { + printf("\n# with pagedResults %scontrol: size=%d", + searchControlCrit ? "critical " : "", + searchControlSize ); + } printf( "\n#\n\n" ); } @@ -1254,16 +1259,35 @@ getNextPage: } #ifdef LDAP_CONTROL_PAGEDRESULTS - if ( ( searchControlSize != 0 ) && ( morePagedResults != 0 ) ) { + if ( ( pageSize != 0 ) && ( morePagedResults != 0 ) ) { + char buf[6]; + int i, moreEntries, tmpSize; + /* Loop to get the next pages when * enter is pressed on the terminal. */ - printf( "Press Enter for the next %d entries.\n", + printf( "Press [size] Enter for the next {%d|size} entries.\n", (int)searchControlSize ); + i = 0; moreEntries = getchar(); while ( moreEntries != EOF && moreEntries != '\n' ) { + if ( i < sizeof(buf) - 1 ) { + buf[i] = moreEntries; + i++; + } moreEntries = getchar(); } + buf[i] = '\0'; + + if ( i > 0 && isdigit( buf[0] ) ) { + num = sscanf( buf, "%d", &tmpSize ); + if ( num != 1 ) { + fprintf( stderr, "Invalid value for PagedResultsControl, %s.\n", buf); + return EXIT_FAILURE; + + } + searchControlSize = (ber_int_t)tmpSize; + } goto getNextPage; } @@ -1383,7 +1407,7 @@ static int dosearch( case LDAP_RES_SEARCH_RESULT: rc = print_result( ld, msg, 1 ); #ifdef LDAP_CONTROL_PAGEDRESULTS - if ( searchControlSize != 0 ) { + if ( pageSize != 0 ) { rc = parse_page_control( ld, msg, &cookie ); } #endif /* LDAP_CONTROL_PAGEDRESULTS */ @@ -1401,7 +1425,7 @@ static int dosearch( done: #ifdef LDAP_CONTROL_PAGEDRESULTS - if ( searchControlSize == 0 ) { + if ( pageSize == 0 ) { if ( ldif < 2 ) { printf( "\n# numResponses: %d\n", nresponses ); if( nentries ) printf( "# numEntries: %d\n", nentries ); diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 3f87c6ec7b..dddadbf45a 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -358,6 +358,12 @@ dn2entry_retry: if ( op->o_pagedresults_state.ps_cookie == 0 ) { id = 0; } else { + if ( op->o_pagedresults_size == 0 ) { + send_search_result( conn, op, LDAP_SUCCESS, + NULL, "search abandoned by pagedResult size=0", + NULL, NULL, 0); + goto done; + } for ( id = bdb_idl_first( candidates, &cursor ); id != NOID && id <= (ID)( op->o_pagedresults_state.ps_cookie ); id = bdb_idl_next( candidates, &cursor ) ); @@ -1114,20 +1120,13 @@ send_pagerequest_response( respcookie = ( PagedResultsCookie )lastid; conn->c_pagedresults_state.ps_cookie = respcookie; cookie.bv_len = sizeof( respcookie ); -#if 0 - cookie.bv_val = ber_memalloc( sizeof( respcookie ) ); - AC_MEMCPY( cookie.bv_val, &respcookie, sizeof( respcookie ) ); -#else cookie.bv_val = (char *)&respcookie; -#endif -/* - conn->c_pagedresults_state.ps_cookie = cookie.bv_val; -*/ + /* + * FIXME: we should consider sending an estimate of the entries + * left, after appropriate security check is done + */ ber_printf( ber, "{iO}", 0, &cookie ); -#if 0 - ber_memfree( cookie.bv_val ); -#endif if ( ber_flatten( ber, &bvalp ) == LBER_ERROR ) { goto done; diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index b8a2011112..f32a4a41a0 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -518,7 +518,7 @@ static int parsePagedResults ( return LDAP_PROTOCOL_ERROR; } - if( size <= 0 ) { + if( size < 0 ) { *text = "paged results control size invalid"; return LDAP_PROTOCOL_ERROR; } -- 2.39.5