#ifdef LDAP_CONTROL_PAGEDRESULTS
 static int pageSize = 0;
 static ber_int_t searchControlSize = 0;
+static ber_int_t entriesLeft = 0;
 static ber_int_t morePagedResults = 1;
 static struct berval cookie = { 0, NULL };
 static int npagedresponses;
                /* Loop to get the next pages when 
                 * enter is pressed on the terminal.
                 */
+               if ( entriesLeft > 0 ) {
+                       printf( "Estimate entries: %d\n", entriesLeft );
+               }
                printf( "Press [size] Enter for the next {%d|size} entries.\n",
                        (int)searchControlSize ); 
                i = 0;
        LDAPControl *ctrlp = NULL;
        BerElement *ber;
        ber_tag_t tag;
-       ber_int_t entriesLeft;
        struct berval servercookie = { 0, NULL };
 
 
 
        Connection      *conn,
        Operation *op,
        ID  lastid,
-       int nentries );                 
+       int nentries,
+       int tentries );                 
 #endif /* LDAP_CONTROL_PAGEDRESULTS */
 
 int
        int             manageDSAit;
 #ifdef LDAP_CONTROL_PAGEDRESULTS
        int             pagedresults;
+       int             tentries = 0;
        ID              lastid = NOID;
 #endif /* LDAP_CONTROL_PAGEDRESULTS */
 
                
                /* if no limit is required, use soft limit */
                if ( slimit <= 0 ) {
-                       slimit = limit->lms_s_soft;
+#ifdef LDAP_CONTROL_PAGEDRESULTS
+                       if ( pagedresults && limit->lms_s_pr != 0 ) {
+                               slimit = limit->lms_s_pr;
+                       } else {
+#endif /* LDAP_CONTROL_PAGEDRESULTS */
+                               slimit = limit->lms_s_soft;
+#ifdef LDAP_CONTROL_PAGEDRESULTS
+                       }
+#endif /* LDAP_CONTROL_PAGEDRESULTS */
 
                /* if requested limit higher than hard limit, abort */
                } else if ( slimit > limit->lms_s_hard ) {
                }
        }
 
+#ifdef LDAP_CONTROL_PAGEDRESULTS
+       if ( isroot || !limit->lms_s_pr_hide ) {
+               tentries = BDB_IDL_N(candidates);
+       }
+#endif /* LDAP_CONTROL_PAGEDRESULTS */
+
 #ifdef LDAP_CONTROL_PAGEDRESULTS
        if ( pagedresults ) {
                if ( op->o_pagedresults_state.ps_cookie == 0 ) {
                                "bdb_search: no paged results candidates\n",
                                0, 0, 0 );
 #endif
-                       send_pagerequest_response( conn, op, lastid, 0 );
+                       send_pagerequest_response( conn, op, lastid, 0, 0 );
 
                        rc = 1;
                        goto done;
 #ifdef LDAP_CONTROL_PAGEDRESULTS
                                if ( pagedresults ) {
                                        if ( nentries >= op->o_pagedresults_size ) {
-                                               send_pagerequest_response( conn, op, lastid, nentries );
+                                               send_pagerequest_response( conn, op, lastid, nentries, tentries );
                                                goto done;
                                        }
                                        lastid = id;
        Connection      *conn,
        Operation       *op,
        ID              lastid,
-       int             nentries )
+       int             nentries,
+       int             tentries )
 {
        LDAPControl     ctrl, *ctrls[2];
        BerElement      *ber;
         * FIXME: we should consider sending an estimate of the entries
         * left, after appropriate security check is done
         */
-       ber_printf( ber, "{iO}", 0, &cookie ); 
+       ber_printf( ber, "{iO}", tentries, &cookie ); 
 
        if ( ber_flatten( ber, &bvalp ) == LBER_ERROR ) {
                goto done;
 
                                                return( 1 );
                                        }
                                }
+
+#ifdef LDAP_CONTROL_PAGEDRESULTS
+                       } else if ( strncasecmp( arg, "pr", sizeof( "pr" ) - 1 ) == 0 ) {
+                               arg += sizeof( "pr" ) - 1;
+                               if ( arg[0] != '=' ) {
+                                       return( 1 );
+                               }
+                               arg++;
+                               if ( strcasecmp( arg, "noEntriesLeft" ) == 0 ) {
+                                       limit->lms_s_pr_hide = 1;
+                               } else {
+                                       char    *next = NULL;
+
+                                       limit->lms_s_pr = 
+                                               strtol( arg, &next, 10 );
+                                       if ( next == arg || limit->lms_s_pr < -1 ) {
+                                               return( 1 );
+                                       }
+                               }
+#endif /* LDAP_CONTROL_PAGEDRESULTS */
                                
                        } else {
                                return( 1 );