From 32f2aa45baabed12adad938290343068b051bc90 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 26 Jun 2004 03:45:46 +0000 Subject: [PATCH] sizelimit, pageresults, and misc fixes from HEAD --- clients/tools/common.c | 25 ++++++++++--- clients/tools/ldapsearch.c | 74 +++++++++++++++++++++++++++++++------- 2 files changed, 81 insertions(+), 18 deletions(-) diff --git a/clients/tools/common.c b/clients/tools/common.c index c44092493a..3c67c918c5 100644 --- a/clients/tools/common.c +++ b/clients/tools/common.c @@ -147,8 +147,8 @@ tool_args( int argc, char **argv ) int i; while (( i = getopt( argc, argv, options )) != EOF ) { - int crit; - char *control, *cvalue; + int crit, ival; + char *control, *cvalue, *next; switch( i ) { case 'c': /* continuous operation mode */ contoper++; @@ -157,7 +157,12 @@ tool_args( int argc, char **argv ) referrals++; break; case 'd': - debug |= atoi( optarg ); + ival = strtol( optarg, &next, 10 ); + if (next == NULL || next[0] != '\0') { + fprintf( stderr, "%s: unable to parse debug value \"%s\"\n", prog, optarg); + exit(EXIT_FAILURE); + } + debug |= ival; break; case 'D': /* bind DN */ if( binddn != NULL ) { @@ -358,10 +363,20 @@ tool_args( int argc, char **argv ) fprintf( stderr, "%s: -p previously specified\n", prog ); exit( EXIT_FAILURE ); } - ldapport = atoi( optarg ); + ival = strtol( optarg, &next, 10 ); + if ( next == NULL || next[0] != '\0' ) { + fprintf( stderr, "%s: unable to parse port number \"%s\"\n", prog, optarg ); + exit( EXIT_FAILURE ); + } + ldapport = ival; break; case 'P': - switch( atoi(optarg) ) { + ival = strtol( optarg, &next, 10 ); + if ( next == NULL || next[0] != '\0' ) { + fprintf( stderr, "%s: unabel to parse protocol version \"%s\"\n", prog, optarg ); + exit( EXIT_FAILURE ); + } + switch( ival ) { case 2: if( protocol == LDAP_VERSION3 ) { fprintf( stderr, "%s: -P 2 incompatible with version %d\n", diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 6f5f5ec664..5adbde0416 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -116,7 +116,7 @@ usage( void ) fprintf( stderr, _(" [!]sync=ro[/] (LDAP Sync refreshOnly)\n")); fprintf( stderr, _(" rp[/][/] (LDAP Sync refreshAndPersist)\n")); fprintf( stderr, _(" -F prefix URL prefix for files (default: %s)\n"), def_urlpre); - fprintf( stderr, _(" -l limit time limit (in seconds) for search\n")); + fprintf( stderr, _(" -l limit time limit (in seconds, or \"none\" or \"max\") for search\n")); fprintf( stderr, _(" -L print responses in LDIFv1 format\n")); fprintf( stderr, _(" -LL print responses in LDIF format without comments\n")); fprintf( stderr, _(" -LLL print responses in LDIF format without comments\n")); @@ -127,7 +127,7 @@ usage( void ) fprintf( stderr, _(" -tt write all values to files in temporary directory\n")); fprintf( stderr, _(" -T path write files to directory specified by path (default: %s)\n"), def_tmpdir); fprintf( stderr, _(" -u include User Friendly entry names in the output\n")); - fprintf( stderr, _(" -z limit size limit (in entries) for search\n")); + fprintf( stderr, _(" -z limit size limit (in entries, or \"none\" or \"max\") for search\n")); tool_common_usage(); exit( EXIT_FAILURE ); } @@ -232,8 +232,8 @@ const char options[] = "a:Ab:E:F:l:Ls:S:tT:uz:" int handle_private_option( int i ) { - int crit; - char *control, *cvalue; + int crit, ival; + char *control, *cvalue, *next; switch ( i ) { case 'a': /* set alias deref option */ if ( strcasecmp( optarg, "never" ) == 0 ) { @@ -408,8 +408,14 @@ handle_private_option( int i ) } if ( cookiep != NULL && *cookiep != '\0' ) ber_str2bv( cookiep, 0, 0, &sync_cookie ); - if ( slimitp != NULL && *slimitp != '\0' ) - sync_slimit = atoi( slimitp ); + if ( slimitp != NULL && *slimitp != '\0' ) { + ival = strtol( slimitp, &next, 10 ); + if ( next == NULL || next[0] != '\0' ) { + fprintf( stderr, _("Unable to parse sync control value \"%s\"\n"), slimitp ); + exit( EXIT_FAILURE ); + } + sync_slimit = ival; + } } else { fprintf( stderr, _("sync control value \"%s\" invalid\n"), cvalue ); @@ -428,8 +434,22 @@ handle_private_option( int i ) urlpre = strdup( optarg ); break; case 'l': /* time limit */ - timelimit = atoi( optarg ); - if( timelimit < 0 ) { + if ( strcasecmp( optarg, "none" ) == 0 ) { + timelimit = 0; + + } else if ( strcasecmp( optarg, "max" ) == 0 ) { + timelimit = LDAP_MAXINT; + + } else { + ival = strtol( optarg, &next, 10 ); + if ( next == NULL || next[0] != '\0' ) { + fprintf( stderr, + _("Unable to parse time limit \"%s\"\n"), optarg ); + exit( EXIT_FAILURE ); + } + timelimit = ival; + } + if( timelimit < 0 || timelimit > LDAP_MAXINT ) { fprintf( stderr, _("%s: invalid timelimit (%d) specified\n"), prog, timelimit ); exit( EXIT_FAILURE ); @@ -464,7 +484,31 @@ handle_private_option( int i ) ++includeufn; break; case 'z': /* size limit */ - sizelimit = atoi( optarg ); + if ( strcasecmp( optarg, "none" ) == 0 ) { + sizelimit = 0; + + } else if ( strcasecmp( optarg, "max" ) == 0 ) { + sizelimit = LDAP_MAXINT; + + } else { + ival = strtol( optarg, &next, 10 ); + if ( next == NULL || next[0] != '\0' ) { + fprintf( stderr, + _("Unable to parse size limit \"%s\"\n"), optarg ); + exit( EXIT_FAILURE ); + } + sizelimit = ival; + } + if( sizelimit < 0 || sizelimit > LDAP_MAXINT ) { + fprintf( stderr, _("%s: invalid sizelimit (%d) specified\n"), + prog, sizelimit ); + exit( EXIT_FAILURE ); + } + if( sizelimit < 0 ) { + fprintf( stderr, _("%s: invalid sizelimit (%d) specified\n"), + prog, timelimit ); + exit( EXIT_FAILURE ); + } break; default: return 0; @@ -483,7 +527,7 @@ private_conn_setup( LDAP *ld ) fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref ); exit( EXIT_FAILURE ); } - if (timelimit != -1 && + if (timelimit > 0 && ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit ) != LDAP_OPT_SUCCESS ) { @@ -491,7 +535,7 @@ private_conn_setup( LDAP *ld ) _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit ); exit( EXIT_FAILURE ); } - if (sizelimit != -1 && + if (sizelimit > 0 && ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit ) != LDAP_OPT_SUCCESS ) { @@ -990,8 +1034,12 @@ static int dosearch( case LDAP_RES_SEARCH_RESULT: rc = print_result( ld, msg, 1 ); #ifdef LDAP_CONTROL_PAGEDRESULTS - if ( pageSize != 0 ) { - rc = parse_page_control( ld, msg, &cookie ); + if ( pageSize != 0 ) { + if ( rc == LDAP_SUCCESS ) { + rc = parse_page_control( ld, msg, &cookie ); + } else { + morePagedResults = 0; + } } #endif -- 2.39.5