]> git.sur5r.net Git - openldap/commitdiff
Add common -o nettimeout option to specify network timeout
authorLuke Howard <lukeh@openldap.org>
Mon, 18 Dec 2006 03:17:43 +0000 (03:17 +0000)
committerLuke Howard <lukeh@openldap.org>
Mon, 18 Dec 2006 03:17:43 +0000 (03:17 +0000)
clients/tools/common.c
clients/tools/common.h
clients/tools/ldapcompare.c
clients/tools/ldapdelete.c
clients/tools/ldapexop.c
clients/tools/ldapmodify.c
clients/tools/ldapmodrdn.c
clients/tools/ldappasswd.c
clients/tools/ldapsearch.c
clients/tools/ldapwhoami.c

index c6fc018af3ccd401576446b6be89d2706dddf8c9..9347c396c8db29e12e317afb6105abefed488260 100644 (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;
index 9f917843f55f19ce5b7ffc96c4189b1371fdbc8f..4b4967bd7c7b92d80d54e542575a0156703d64b1 100644 (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[];
 
index 317224acfc626fe04197f0d78b8ca2643ac43dbd..5cc9664bc6bcdcd6ca6d2b8784e302354f485d31 100644 (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;
index 741c52dcdc0e26c14f2eb9fc255b80b34c0c219c..71f13cebe82c6999d7bee226f509ba6f8d53c25f 100644 (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 )
index 0ffe42dd5ee2733673d422e5c38e419300458008..03ec8fae01977b2cb3544c5d632fc26fb2e76e2c 100644 (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 )
index aa66c161eeca53eb7ea2b210f8d111ef6782c1b4..608400c3c0fd639591ebc39240f1a9956bcb3317 100644 (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 )
index 2841d7e087534a9f1dbcd6bd27df94f7585f02db..74ac903af0addc85d4efb213e403bebc94095e90 100644 (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 )
index b8ce5e899a6862e58097077686ff8f86ca857132..a73ddbd77351d6857a8843ae7ed53a1a66355854 100644 (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 )
index 50053514c92935064e389746bdf36902fdf0b67f..07ed389b9e3473692bc841b32cb4a35e14f8254e 100644 (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 )
index 17d48b28e3981ac4abd6dd5867afc192778a3959..a294f51144e31cb8f374927b1f3cdb134c8e489a 100644 (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 )