From 5640f6313afec3b9b31e3ffb71614b346a3d0bcb Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sun, 8 Jan 2006 22:49:24 +0000 Subject: [PATCH] use new paged results control client API (ITS#4314) --- clients/tools/common.c | 15 +++++---------- clients/tools/ldapsearch.c | 9 ++------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/clients/tools/common.c b/clients/tools/common.c index 42186ff699..317340229d 100644 --- a/clients/tools/common.c +++ b/clients/tools/common.c @@ -1406,24 +1406,23 @@ print_postread( LDAP *ld, LDAPControl *ctrl ) static int print_paged_results( LDAP *ld, LDAPControl *ctrl ) { - BerElement *ber; - ber_int_t estimate; - - ber = ber_init( &ctrl->ldctl_value ); + unsigned long estimate; + /* note: pr_cookie is being malloced; it's freed * the next time the control is sent, but the last * time it's not; we don't care too much, because * the last time an empty value is returned... */ - if ( ber_scanf( ber, "{io}", &estimate, &pr_cookie ) == LBER_ERROR ) { + if ( ldap_parse_pageresponse_control( ld, ctrl, &estimate, &pr_cookie ) != LDAP_SUCCESS ) { /* error? */ return 1; } else { + /* FIXME: check buffer overflow */ char buf[ BUFSIZ ], *ptr = buf; if ( estimate > 0 ) { ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), - "estimate=%d", estimate ); + "estimate=%lu", estimate ); } if ( pr_cookie.bv_len > 0 ) { @@ -1455,10 +1454,6 @@ print_paged_results( LDAP *ld, LDAPControl *ctrl ) "pagedresults", buf, ptr - buf ); } - if ( ber != NULL ) { - ber_free( ber, 1 ); - } - return 0; } diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index a229b56391..409138a340 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -627,7 +627,7 @@ main( int argc, char **argv ) FILE *fp = NULL; int rc, i, first; LDAP *ld = NULL; - BerElement *seber = NULL, *vrber = NULL, *prber = NULL; + BerElement *seber = NULL, *vrber = NULL; BerElement *syncber = NULL; struct berval *syncbvalp = NULL; @@ -851,14 +851,10 @@ getNextPage: return EXIT_FAILURE; } - if (( prber = ber_alloc_t(LBER_USE_DER)) == NULL ) { + if ( ldap_create_page_control_value( ld, pageSize, &pr_cookie, &c[i].ldctl_value ) ) { return EXIT_FAILURE; } - ber_printf( prber, "{iO}", pageSize, &pr_cookie ); - if ( ber_flatten2( prber, &c[i].ldctl_value, 0 ) == -1 ) { - return EXIT_FAILURE; - } if ( pr_cookie.bv_val != NULL ) { ber_memfree( pr_cookie.bv_val ); pr_cookie.bv_val = NULL; @@ -878,7 +874,6 @@ getNextPage: ber_free( seber, 1 ); ber_free( vrber, 1 ); - ber_free( prber, 1 ); } if ( verbose ) { -- 2.39.5