Add common -o nettimeout option to specify network timeout

This commit is contained in:
Luke Howard 2006-12-18 03:17:43 +00:00
parent 44dfc63877
commit b7c41e655f
10 changed files with 65 additions and 8 deletions

View File

@ -125,6 +125,9 @@ static int chainingResolve = -1;
static int chainingContinuation = -1;
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
/* options */
struct timeval nettimeout = { -1 , 0 };
typedef int (*print_ctrl_fn)( LDAP *ld, LDAPControl *ctrl );
static int print_preread( LDAP *ld, LDAPControl *ctrl );
@ -220,6 +223,8 @@ N_(" -K like -k, but do only step 1 of the Kerberos bind\n"),
N_(" -M enable Manage DSA IT control (-MM to make critical)\n"),
N_(" -n show what would be done but don't actually do it\n"),
N_(" -O props SASL security properties\n"),
N_(" -o <opt>[=<optparam] general options\n"),
N_(" nettimeout=<timeout> (in seconds, or \"none\" or \"max\")\n"),
N_(" -p port port on LDAP server\n"),
N_(" -P version procotol version (default: 3)\n"),
N_(" -Q use SASL Quiet mode\n"),
@ -590,6 +595,45 @@ tool_args( int argc, char **argv )
case 'n': /* print operations, don't actually do them */
dont++;
break;
case 'o':
control = ber_strdup( optarg );
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
if ( strcasecmp( control, "nettimeout" ) == 0 ) {
if( nettimeout.tv_sec != -1 ) {
fprintf( stderr, "nettimeout option previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue == NULL || cvalue[0] == '\0' ) {
fprintf( stderr, "nettimeout: option value expected\n" );
usage();
}
if ( strcasecmp( cvalue, "none" ) == 0 ) {
nettimeout.tv_sec = 0;
} else if ( strcasecmp( cvalue, "max" ) == 0 ) {
nettimeout.tv_sec = LDAP_MAXINT;
} else {
ival = strtol( cvalue, &next, 10 );
if ( next == NULL || next[0] != '\0' ) {
fprintf( stderr,
_("Unable to parse network timeout \"%s\"\n"), cvalue );
exit( EXIT_FAILURE );
}
nettimeout.tv_sec = ival;
}
if( nettimeout.tv_sec < 0 || nettimeout.tv_sec > LDAP_MAXINT ) {
fprintf( stderr, _("%s: invalid network timeout (%d) specified\n"),
prog, nettimeout.tv_sec );
exit( EXIT_FAILURE );
}
} else {
fprintf( stderr, "Invalid general option name: %s\n",
control );
usage();
}
break;
case 'O':
#ifdef HAVE_CYRUS_SASL
if( sasl_secprops != NULL ) {
@ -989,6 +1033,16 @@ tool_conn_setup( int dont, void (*private_setup)( LDAP * ) )
}
}
}
if ( nettimeout.tv_sec > 0 ) {
if ( ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, (void *) &nettimeout )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LDAP_OPT_NETWORK_TIMEOUT %d\n",
nettimeout.tv_sec );
exit( EXIT_FAILURE );
}
}
}
return ld;

View File

@ -94,6 +94,9 @@ extern struct berval pr_cookie;
extern int chaining;
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
/* options */
extern struct timeval nettimeout;
/* Defined in common.c, set in main() */
extern const char __Version[];

View File

@ -102,7 +102,7 @@ static int docompare LDAP_P((
const char options[] = "z"
"Cd:D:e:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
"Cd:D:e:h:H:IkKMnO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
#ifdef LDAP_CONTROL_DONTUSECOPY
int dontUseCopy = 0;

View File

@ -76,7 +76,7 @@ usage( void )
const char options[] = "r"
"cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
"cd:D:e:f:h:H:IkKMnO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )

View File

@ -49,7 +49,7 @@ usage( void )
const char options[] = ""
"d:D:e:h:H:InO:p:QR:U:vVw:WxX:y:Y:Z";
"d:D:e:h:H:InO:o:p:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )

View File

@ -154,7 +154,7 @@ usage( void )
const char options[] = "aE:FrS:"
"cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
"cd:D:e:f:h:H:IkKMnO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )

View File

@ -91,7 +91,7 @@ usage( void )
const char options[] = "rs:"
"cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
"cd:D:e:f:h:H:IkKMnO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )

View File

@ -81,7 +81,7 @@ usage( void )
const char options[] = "a:As:St:T:"
"d:D:e:h:H:InO:p:QR:U:vVw:WxX:y:Y:Z";
"d:D:e:h:H:InO:o:p:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )

View File

@ -249,7 +249,7 @@ urlize(char *url)
const char options[] = "a:Ab:cE:F:l:Ls:S:tT:uz:"
"Cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
"Cd:D:e:f:h:H:IkKMnO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )

View File

@ -62,7 +62,7 @@ usage( void )
const char options[] = ""
"d:D:e:h:H:InO:p:QR:U:vVw:WxX:y:Y:Z";
"d:D:e:h:H:InO:o:p:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )