]> git.sur5r.net Git - openldap/commitdiff
First cut at -V (version) argument. Needs work.
authorKurt Zeilenga <kurt@openldap.org>
Mon, 20 Jan 2003 20:11:57 +0000 (20:11 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 20 Jan 2003 20:11:57 +0000 (20:11 +0000)
16 files changed:
clients/tools/common.c
clients/tools/common.h
clients/tools/ldapcompare.c
clients/tools/ldapcompare.dsp
clients/tools/ldapdelete.c
clients/tools/ldapdelete.dsp
clients/tools/ldapmodify.c
clients/tools/ldapmodify.dsp
clients/tools/ldapmodrdn.c
clients/tools/ldapmodrdn.dsp
clients/tools/ldappasswd.c
clients/tools/ldappasswd.dsp
clients/tools/ldapsearch.c
clients/tools/ldapsearch.dsp
clients/tools/ldapwhoami.c
clients/tools/ldapwhoami.dsp

index 107d1df9660820c36f1006dac2827c179b7dd263..5b5278f944527e33254be6c6a8c175fbf2db8b24 100644 (file)
@@ -49,12 +49,13 @@ int   want_bindpw = 0;
 struct berval passwd = { 0, NULL };
 char *pw_file = NULL;
 int   referrals = 0;
+int   protocol = -1;
 int   verbose = 0;
-int   version = -1;
-
+int   version = 0;
 
 /* Set in main() */
-char *prog;
+char *prog = NULL;
+char *version_string = NULL;
 
 
 void
@@ -84,6 +85,7 @@ tool_common_usage( void )
 "  -R realm   SASL realm\n",
 "  -U authcid SASL authentication identity\n",
 "  -v         run in verbose mode (diagnostics to standard output)\n",
+"  -V         print version info (-VV only)\n",
 "  -w passwd  bind passwd (for simple authentication)\n",
 "  -W         prompt for bind passwd\n",
 "  -x         Simple authentication\n",
@@ -93,12 +95,14 @@ tool_common_usage( void )
 "  -Z         Start TLS request (-ZZ to require successful response)\n",
 NULL
        };
-       const char *const *cpp, *cp;
+       const char *const *cpp;
 
        fputs( "Common options:\n", stderr );
-       for( cpp = descriptions; (cp = *cpp) != NULL; cpp++ )
-               if( strchr( options, cp[3] ) )
-                       fputs( cp, stderr );
+       for( cpp = descriptions; *cpp != NULL; cpp++ ) {
+               if( strchr( options, (*cpp)[3] ) ) {
+                       fputs( *cpp, stderr );
+               }
+       }
 }
 
 
@@ -292,20 +296,20 @@ tool_args( int argc, char **argv )
                case 'P':
                        switch( atoi(optarg) ) {
                        case 2:
-                               if( version == LDAP_VERSION3 ) {
+                               if( protocol == LDAP_VERSION3 ) {
                                        fprintf( stderr, "%s: -P 2 incompatible with version %d\n",
-                                                        prog, version );
+                                                        prog, protocol );
                                        exit( EXIT_FAILURE );
                                }
-                               version = LDAP_VERSION2;
+                               protocol = LDAP_VERSION2;
                                break;
                        case 3:
-                               if( version == LDAP_VERSION2 ) {
+                               if( protocol == LDAP_VERSION2 ) {
                                        fprintf( stderr, "%s: -P 2 incompatible with version %d\n",
-                                                        prog, version );
+                                                        prog, protocol );
                                        exit( EXIT_FAILURE );
                                }
-                               version = LDAP_VERSION3;
+                               protocol = LDAP_VERSION3;
                                break;
                        default:
                                fprintf( stderr, "%s: protocol version should be 2 or 3\n",
@@ -372,6 +376,9 @@ tool_args( int argc, char **argv )
                case 'v':       /* verbose mode */
                        verbose = 1;
                        break;
+               case 'V':       /* version */
+                       version++;
+                       break;
                case 'w':       /* password */
                        passwd.bv_val = ber_strdup( optarg );
                        {
@@ -450,10 +457,16 @@ tool_args( int argc, char **argv )
                }
     }
 
-       if (version == -1)
-               version = LDAP_VERSION3;
+       if (version) {
+               fprintf( stderr, "%s: %s\n", prog,
+                       version_string ? version_string : "version unknown" );
+               if (version > 1) exit( EXIT_SUCCESS );
+       }
+
+       if (protocol == -1)
+               protocol = LDAP_VERSION3;
 
-       if (authmethod == -1 && version > LDAP_VERSION2) {
+       if (authmethod == -1 && protocol > LDAP_VERSION2) {
 #ifdef HAVE_CYRUS_SASL
                authmethod = LDAP_AUTH_SASL;
 #else
@@ -471,7 +484,7 @@ tool_args( int argc, char **argv )
                        exit( EXIT_FAILURE );
                }
        }
-       if( version == LDAP_VERSION2 ) {
+       if( protocol == LDAP_VERSION2 ) {
                if( authzid || manageDSAit || noop ) {
                        fprintf( stderr, "%s: -e/-M incompatible with LDAPv2\n", prog );
                        exit( EXIT_FAILURE );
@@ -493,7 +506,7 @@ tool_args( int argc, char **argv )
 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
                if ( authmethod = LDAP_AUTH_KRBV4 || authmethod == LDAP_AUTH_KRBV41 ) {
                        fprintf( stderr, "%s: -k/-K incompatible with LDAPv%d\n",
-                                prog, version );
+                                prog, protocol );
                        exit( EXIT_FAILURE );
                }
 #endif
@@ -565,11 +578,11 @@ tool_conn_setup( int not, void (*private_setup)( LDAP * ) )
                        exit( EXIT_FAILURE );
                }
 
-               if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version )
+               if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &protocol )
                    != LDAP_OPT_SUCCESS )
                {
                        fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n",
-                                version );
+                                protocol );
                        exit( EXIT_FAILURE );
                }
 
index ed9c4bdf150e40627436ca2d9de2e9b5986319c3..f8cb32e89c2cc69b3133083f7d2a1f2dbd8b2f57 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef _COMMON_H_
 #define _COMMON_H_
 
+LDAP_BEGIN_DECL
+
 /* Defined and set in common.c */
 extern int   authmethod;
 extern char *binddn;
@@ -36,11 +38,12 @@ extern int   want_bindpw;
 extern struct berval passwd;
 extern char *pw_file;
 extern int   referrals;
+extern int   protocol;
 extern int   verbose;
 extern int   version;
 
 /* Defined in common.c, set in main() */
-char *prog;
+extern char *prog;
 
 /* Defined in main program */
 extern const char options[];
@@ -54,4 +57,6 @@ LDAP *tool_conn_setup LDAP_P(( int dont, void (*private_setup)( LDAP * ) ));
 void tool_bind LDAP_P(( LDAP * ));
 void tool_server_controls LDAP_P(( LDAP *, LDAPControl *, int ));
 
+LDAP_END_DECL
+
 #endif /* _COMMON_H_ */
index b357c6d09a2c7a8f9bf23b4d01d115ffe3622146..18ea6efee7efa535efd181589a801297dab23932 100644 (file)
@@ -67,7 +67,8 @@ static int docompare LDAP_P((
        LDAPControl **cctrls));
 
 
-const char options[] = "z" "Cd:D:e:h:H:IkKMnO:p:P:QR:U:vw:WxX:y:Y:Z";
+const char options[] = "z"
+       "Cd:D:e:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
 
 int
 handle_private_option( int i )
@@ -77,9 +78,9 @@ handle_private_option( int i )
                char    *control, *cvalue;
                int             crit;
        case 'E': /* compare controls */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
-                               prog, version );
+                               prog, protocol );
                        exit( EXIT_FAILURE );
                }
 
index 83566ba62bbebf707ed83aec189a2b30419f6617..ab31707cdc08a276a693a4c5c7d431a6275367b8 100644 (file)
@@ -143,6 +143,10 @@ LINK32=link.exe
 # Name "ldapcompare - Win32 Release"
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ldapcompare.c
 # End Source File
 # End Target
index 77ed1397f0e5b2e8d63ede76570d177f6e9035c5..d3638404a58bacfb3552ee9f3ef538e9c1759000 100644 (file)
@@ -49,7 +49,8 @@ usage( void )
 }
 
 
-const char options[] = "r" "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vw:WxX:y:Y:Z";
+const char options[] = "r"
+       "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
 
 int
 handle_private_option( int i )
@@ -59,9 +60,9 @@ handle_private_option( int i )
                int crit;
                char *control, *cvalue;
        case 'E': /* delete controls */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
-                               prog, version );
+                               prog, protocol );
                        exit( EXIT_FAILURE );
                }
 
index af7b4be03002883879b64449ba92b8ecce95c829..c136d67c8a08be01b2ea034e5000c1b87ae01b84 100644 (file)
@@ -143,6 +143,10 @@ LINK32=link.exe
 # Name "ldapdelete - Win32 Release"
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ldapdelete.c
 # End Source File
 # End Target
index b0b5fb0e05726a0947bcb172fc1dd97150ae637f..d4f452b95ed450a920f492b333ed114954dcfa3e 100644 (file)
@@ -104,7 +104,8 @@ usage( void )
 }
 
 
-const char options[] = "aFrS:" "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vw:WxX:y:Y:Z";
+const char options[] = "aFrS:"
+       "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
 
 int
 handle_private_option( int i )
@@ -114,9 +115,9 @@ handle_private_option( int i )
                char    *control, *cvalue;
                int             crit;
        case 'E': /* modify controls */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
-                               prog, version );
+                               prog, protocol );
                        exit( EXIT_FAILURE );
                }
 
index 9a58a7060f509224b7d1709f9546f422b6f449ed..ffa4e68df826bf48d4ab0091b99a58d5206b3444 100644 (file)
@@ -143,6 +143,10 @@ LINK32=link.exe
 # Name "ldapmodify - Win32 Release"
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ldapmodify.c
 # End Source File
 # End Target
index 4ac93c0325d576d6b99d706627d69659740eb2c0..225e536657547214e7e48d97090ce025c06e4f53 100644 (file)
@@ -64,7 +64,8 @@ usage( void )
 }
 
 
-const char options[] = "rs:" "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vw:WxX:y:Y:Z";
+const char options[] = "rs:"
+       "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
 
 int
 handle_private_option( int i )
@@ -74,7 +75,7 @@ handle_private_option( int i )
                int crit;
                char *control, *cvalue;
        case 'E': /* modrdn controls */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
                                prog, version );
                        exit( EXIT_FAILURE );
@@ -104,13 +105,13 @@ handle_private_option( int i )
            break;
 
        case 's':       /* newSuperior */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -X incompatible with LDAPv%d\n",
-                               prog, version );
+                               prog, protocol );
                        exit( EXIT_FAILURE );
                }
            newSuperior = strdup( optarg );
-           version = LDAP_VERSION3;
+           protocol = LDAP_VERSION3;
            break;
 
        default:
index bcf0cc01cc1f9e58aa4bd72b91f9cc356477b062..d1304ce84cad6127c3781bae6e0cb3e1af1b1459 100644 (file)
@@ -143,6 +143,10 @@ LINK32=link.exe
 # Name "ldapmodrdn - Win32 Release"
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ldapmodrdn.c
 # End Source File
 # End Target
index fa627523e5131ee5c23c980ff5d2f6dcacbeb15f..a0265f4ebdc5fa9b8e7dbc0b48898c7fe9c20d0a 100644 (file)
@@ -48,7 +48,8 @@ usage( void )
 }
 
 
-const char options[] = "a:As:S" "Cd:D:e:h:H:InO:p:QR:U:vw:WxX:Y:Z";
+const char options[] = "a:As:S"
+       "Cd:D:e:h:H:InO:p:QR:U:vVw:WxX:Y:Z";
 
 int
 handle_private_option( int i )
@@ -58,9 +59,9 @@ handle_private_option( int i )
                int             crit;
                char    *control, *cvalue;
        case 'E': /* passwd controls */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
-                                prog, version );
+                                prog, protocol );
                        exit( EXIT_FAILURE );
                }
 
@@ -138,7 +139,7 @@ main( int argc, char *argv[] )
        prog = lutil_progname( "ldappasswd", argc, argv );
 
        /* LDAPv3 only */
-       version = LDAP_VERSION3;
+       protocol = LDAP_VERSION3;
 
        tool_args( argc, argv );
 
index df406dfe5f9f01be14940b264b4d057de0b22500..7aa142c7d4dd224d1743db149348ff92e13fe6aa 100644 (file)
@@ -139,6 +139,10 @@ LINK32=link.exe
 # Name "ldappasswd - Win32 Single Release"
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ldappasswd.c
 # End Source File
 # End Target
index 0b73cd2ab79dd1e543524c4d9c78cc18d3ff0320..ec86820b88d90a0cf2322af1bc8bfbc8c7d95a77 100644 (file)
@@ -185,7 +185,7 @@ urlize(char *url)
 
 
 const char options[] = "a:Ab:E:F:l:Ls:S:tT:uz:"
-                       "Cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vw:WxX:y:Y:Z";
+       "Cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
 
 int
 handle_private_option( int i )
@@ -214,9 +214,9 @@ handle_private_option( int i )
                base = strdup( optarg );
                break;
        case 'E': /* search controls */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
-                               prog, version );
+                               prog, protocol );
                        exit( EXIT_FAILURE );
                }
 
@@ -251,7 +251,7 @@ handle_private_option( int i )
                        }
 
                        vrFilter = cvalue;
-                       version = LDAP_VERSION3;
+                       protocol = LDAP_VERSION3;
 
                } else if ( strcasecmp( control, "pr" ) == 0 ) {
                        int num, tmp;
@@ -652,7 +652,7 @@ getNextPage:
                        "# base <%s> with scope %s\n"
                        "# filter%s: %s\n"
                        "# requesting: ",
-                       version,
+                       protocol,
                        base ? base : "", (scope == LDAP_SCOPE_BASE) ? "base"
                                : ((scope == LDAP_SCOPE_ONELEVEL) ? "one" : "sub"),
                        infile != NULL ? " pattern" : "",
index d3918c8e458e4e947617f76f112d47e02e9a51c3..de7f3e97234e4b8a859477450dc54ec60fa2d9a2 100644 (file)
@@ -143,6 +143,10 @@ LINK32=link.exe
 # Name "ldapsearch - Win32 Debug"
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ldapsearch.c
 # End Source File
 # End Target
index 29d7e520d478aea61f294a286cc0364f929fd1e6..4ccb11aea27992cfcc230538ecd3970cb0968e99 100644 (file)
@@ -36,7 +36,8 @@ usage( void )
 }
 
 
-const char options[] = "Cd:D:e:h:H:InO:p:QR:U:vw:WxX:y:Y:Z";
+const char options[] = ""
+       "Cd:D:e:h:H:InO:p:QR:U:vVw:WxX:y:Y:Z";
 
 int
 handle_private_option( int i )
@@ -46,9 +47,9 @@ handle_private_option( int i )
                char    *control, *cvalue;
                int             crit;
        case 'E': /* whoami controls */
-               if( version == LDAP_VERSION2 ) {
+               if( protocol == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
-                               prog, version );
+                               prog, protocol );
                        exit( EXIT_FAILURE );
                }
 
@@ -93,7 +94,7 @@ main( int argc, char *argv[] )
        prog = lutil_progname( "ldapwhoami", argc, argv );
 
        /* LDAPv3 only */
-       version = LDAP_VERSION3;
+       protocol = LDAP_VERSION3;
 
        tool_args( argc, argv );
 
index 5e44a4fc7c976bc1654c58aca8ec8aed87e3f803..c4bdaa014a9db5b18059ec48115808238347932b 100644 (file)
@@ -139,6 +139,10 @@ LINK32=link.exe
 # Name "ldapwhoami - Win32 Single Release"
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\ldapwhoami.c
 # End Source File
 # End Target