-
-static int
-parse_page_control(
- LDAP *ld,
- LDAPMessage *result,
- struct berval *cookie )
-{
- int rc;
- int err;
- LDAPControl **ctrl = NULL;
- LDAPControl *ctrlp = NULL;
- BerElement *ber;
- ber_tag_t tag;
-
- rc = ldap_parse_result( ld, result,
- &err, NULL, NULL, NULL, &ctrl, 0 );
-
- if ( rc != LDAP_SUCCESS ) {
- tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
- }
-
- if ( err != LDAP_SUCCESS ) {
- fprintf( stderr, "%s (%d)\n", ldap_err2string(err), err );
- }
-
- if ( ctrl ) {
- /* There might be others, e.g. ppolicy... */
- ctrlp = ldap_find_control( LDAP_CONTROL_PAGEDRESULTS, ctrl );
- }
-
- if ( ctrlp ) {
- /* Parse the control value
- * searchResult ::= SEQUENCE {
- * size INTEGER (0..maxInt),
- * -- result set size estimate from server - unused
- * cookie OCTET STRING
- * }
- */
- ctrlp = *ctrl;
- ber = ber_init( &ctrlp->ldctl_value );
- if ( ber == NULL ) {
- fprintf( stderr, _("Internal error.\n") );
- return EXIT_FAILURE;
- }
-
- tag = ber_scanf( ber, "{io}", &entriesLeft, cookie );
- (void) ber_free( ber, 1 );
-
- if( tag == LBER_ERROR ) {
- fprintf( stderr,
- _("Paged results response control could not be decoded.\n") );
- return EXIT_FAILURE;
- }
-
- if( entriesLeft < 0 ) {
- fprintf( stderr,
- _("Invalid entries estimate in paged results response.\n") );
- return EXIT_FAILURE;
- }
-
- if ( cookie->bv_len == 0 ) {
- morePagedResults = 0;
- }
-
- ldap_controls_free( ctrl );
-
- } else {
- morePagedResults = 0;
- }
-
- return err;
-}