Index: ldapsearch.c =================================================================== RCS file: /repo/OpenLDAP/pkg/ldap/clients/tools/ldapsearch.c,v retrieving revision 1.242 diff -u -r1.242 ldapsearch.c --- ldapsearch.c 10 Nov 2006 09:39:54 -0000 1.242 +++ ldapsearch.c 12 Dec 2006 00:56:46 -0000 @@ -94,6 +94,7 @@ static int attrsonly; static int timelimit = -1; static int sizelimit = -1; +static struct timeval network_timeout = { -1, 0 }; static char *def_tmpdir; static char *def_urlpre; @@ -121,6 +122,7 @@ fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n")); fprintf( stderr, _(" -A retrieve attribute names only (no values)\n")); fprintf( stderr, _(" -b basedn base dn for search\n")); + fprintf( stderr, _(" -B seconds network timeout (in seconds, or \"none\" or \"max\")\n")); fprintf( stderr, _(" -E [!][=] search extensions (! indicates criticality)\n")); fprintf( stderr, _(" [!]domainScope (domain scope)\n")); fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n")); @@ -248,7 +250,7 @@ } -const char options[] = "a:Ab:cE:F:l:Ls:S:tT:uz:" +const char options[] = "a:Ab:B:cE:F:l:Ls:S:tT:uz:" "Cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z"; int @@ -278,6 +280,28 @@ case 'b': /* search base */ base = ber_strdup( optarg ); break; + case 'B': /* network timeout */ + if ( strcasecmp( optarg, "none" ) == 0 ) { + network_timeout.tv_sec = 0; + + } else if ( strcasecmp( optarg, "max" ) == 0 ) { + network_timeout.tv_sec = LDAP_MAXINT; + + } else { + ival = strtol( optarg, &next, 10 ); + if ( next == NULL || next[0] != '\0' ) { + fprintf( stderr, + _("Unable to parse network timeout \"%s\"\n"), optarg ); + exit( EXIT_FAILURE ); + } + network_timeout.tv_sec = ival; + } + if( network_timeout.tv_sec < 0 || network_timeout.tv_sec > LDAP_MAXINT ) { + fprintf( stderr, _("%s: invalid network timeout (%d) specified\n"), + prog, network_timeout ); + exit( EXIT_FAILURE ); + } + break; case 'E': /* search extensions */ if( protocol == LDAP_VERSION2 ) { fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"), @@ -616,6 +640,14 @@ _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit ); exit( EXIT_FAILURE ); } + if (network_timeout.tv_sec > 0 && + ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, (void *) &network_timeout ) + != LDAP_OPT_SUCCESS ) + { + fprintf( stderr, + _("Could not set LDAP_OPT_NETWORK_TIMEOUT %d\n"), network_timeout ); + exit( EXIT_FAILURE ); + } } int