]> git.sur5r.net Git - openldap/blobdiff - clients/tools/common.c
(blind) fix type format
[openldap] / clients / tools / common.c
index 84f73e91443731dfd0ec52101faa4b8eff39bb44..9f51f49ebd25d063076424912ce1b5cfbfa0e529 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 );
@@ -187,12 +190,12 @@ N_("  -C         chase referrals (anonymously)\n"),
 N_("  -d level   set LDAP debugging level to `level'\n"),
 N_("  -D binddn  bind DN\n"),
 N_("  -e [!]<ext>[=<extparam>] general extensions (! indicates criticality)\n")
-N_("             [!]assert=<filter>     (an RFC 2254 Filter)\n")
+N_("             [!]assert=<filter>     (a RFC 4515 Filter string)\n")
 N_("             [!]authzid=<authzid>   (\"dn:<dn>\" or \"u:<user>\")\n")
 #ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
 #if 0
                  /* non-advertized support for proxyDN */
-N_("             [!]proxydn=<dn>        (an RFC 2253 DN)\n")
+N_("             [!]proxydn=<dn>        (a RFC 4514 DN string)\n")
 #endif
 #endif
 #ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
@@ -200,17 +203,17 @@ N_("             [!]chaining[=<resolveBehavior>[/<continuationBehavior>]]\n")
 N_("                     one of \"chainingPreferred\", \"chainingRequired\",\n")
 N_("                     \"referralsPreferred\", \"referralsRequired\"\n")
 #endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
-#ifdef LDAP_DEVEL
-N_("             [!]manageDIT\n")
-#endif
 N_("             [!]manageDSAit\n")
 N_("             [!]noop\n")
 #ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
 N_("             ppolicy\n")
 #endif
 N_("             [!]postread[=<attrs>]  (a comma-separated attribute list)\n")
-N_("             [!]preread[=<attrs>]   (a comma-separated attribute list)\n"),
-N_("             abandon, cancel (SIGINT sends abandon/cancel; not really controls)\n")
+N_("             [!]preread[=<attrs>]   (a comma-separated attribute list)\n")
+#ifdef LDAP_DEVEL
+N_("             [!]relax\n")
+#endif
+N_("             abandon, cancel (SIGINT sends abandon/cancel; not really controls)\n"),
 N_("  -f file    read operations from `file'\n"),
 N_("  -h host    LDAP server\n"),
 N_("  -H URI     LDAP Uniform Resource Indentifier(s)\n"),
@@ -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"),
@@ -383,15 +388,17 @@ tool_args( int argc, char **argv )
                                proxydn = cvalue;
 #endif /* LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ */
 
-                       } else if ( strcasecmp( control, "manageDIT" ) == 0 ) {
+                       } else if ( ( strcasecmp( control, "relax" ) == 0 ) ||
+                               ( strcasecmp( control, "manageDIT" ) == 0 ) )
+                       {
                                if( manageDIT ) {
                                        fprintf( stderr,
-                                               "manageDIT control previously specified\n");
+                                               "relax control previously specified\n");
                                        exit( EXIT_FAILURE );
                                }
                                if( cvalue != NULL ) {
                                        fprintf( stderr,
-                                               "manageDIT: no control value expected\n" );
+                                               "relax: no control value expected\n" );
                                        usage();
                                }
 
@@ -588,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 (%ld) specified\n"),
+                                               prog, (long)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 ) {
@@ -987,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 %ld\n",
+                                       (long)nettimeout.tv_sec );
+                               exit( EXIT_FAILURE );
+                       }
+               }
        }
 
        return ld;
@@ -996,19 +1052,28 @@ tool_conn_setup( int dont, void (*private_setup)( LDAP * ) )
 void
 tool_bind( LDAP *ld )
 {
+       LDAPControl     **sctrlsp = NULL;
+       LDAPControl     *sctrls[2];
+       int             nsctrls = 0;
+
 #ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
-       LDAPControl *sctrls[2] = { NULL };
+       LDAPControl c;
        if ( ppolicy ) {
-               LDAPControl c;
                c.ldctl_oid = LDAP_CONTROL_PASSWORDPOLICYREQUEST;
                c.ldctl_value.bv_val = NULL;
                c.ldctl_value.bv_len = 0;
                c.ldctl_iscritical = 0;
-               sctrls[0] = &c;
-               sctrls[1] = NULL;
+               sctrls[nsctrls] = &c;
+               sctrls[++nsctrls] = NULL;
        }
 #endif
 
+       if ( nsctrls ) {
+               sctrlsp = sctrls;
+       }
+
+       assert( nsctrls < sizeof(sctrls)/sizeof(sctrls[0]) );
+
        if ( authmethod == LDAP_AUTH_SASL ) {
 #ifdef HAVE_CYRUS_SASL
                void *defaults;
@@ -1034,11 +1099,7 @@ tool_bind( LDAP *ld )
                        sasl_authz_id );
 
                rc = ldap_sasl_interactive_bind_s( ld, binddn, sasl_mech,
-#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
-                       sctrls,
-#else
-                       NULL,
-#endif
+                       sctrlsp,
                        NULL, sasl_flags, lutil_sasl_interact, defaults );
 
                lutil_sasl_freedefs( defaults );
@@ -1074,12 +1135,7 @@ tool_bind( LDAP *ld )
                {
                        /* simple bind */
                        rc = ldap_sasl_bind( ld, binddn, LDAP_SASL_SIMPLE, &passwd,
-#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
-                               sctrls,
-#else
-                               NULL,
-#endif
-                               NULL, &msgid );
+                               sctrlsp, NULL, &msgid );
                        if ( msgid == -1 ) {
                                tool_perror( "ldap_sasl_bind(SIMPLE)", rc,
                                        NULL, NULL, NULL, NULL );
@@ -1686,7 +1742,7 @@ tool_is_oid( const char *s )
 {
        int             first = 1;
 
-       if ( !isdigit( s[ 0 ] ) ) {
+       if ( !isdigit( (unsigned char) s[ 0 ] ) ) {
                return 0;
        }
 
@@ -1699,7 +1755,7 @@ tool_is_oid( const char *s )
                        continue;
                }
 
-               if ( !isdigit( s[ 0 ] ) ) {
+               if ( !isdigit( (unsigned char) s[ 0 ] ) ) {
                        return 0;
                }