From dab6bdaaada7f7599c7fd58733ae183fefc33431 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 20 Jan 2003 20:11:57 +0000 Subject: [PATCH] First cut at -V (version) argument. Needs work. --- clients/tools/common.c | 53 ++++++++++++++++++++++------------- clients/tools/common.h | 7 ++++- clients/tools/ldapcompare.c | 7 +++-- clients/tools/ldapcompare.dsp | 4 +++ clients/tools/ldapdelete.c | 7 +++-- clients/tools/ldapdelete.dsp | 4 +++ clients/tools/ldapmodify.c | 7 +++-- clients/tools/ldapmodify.dsp | 4 +++ clients/tools/ldapmodrdn.c | 11 ++++---- clients/tools/ldapmodrdn.dsp | 4 +++ clients/tools/ldappasswd.c | 9 +++--- clients/tools/ldappasswd.dsp | 4 +++ clients/tools/ldapsearch.c | 10 +++---- clients/tools/ldapsearch.dsp | 4 +++ clients/tools/ldapwhoami.c | 9 +++--- clients/tools/ldapwhoami.dsp | 4 +++ 16 files changed, 100 insertions(+), 48 deletions(-) diff --git a/clients/tools/common.c b/clients/tools/common.c index 107d1df966..5b5278f944 100644 --- a/clients/tools/common.c +++ b/clients/tools/common.c @@ -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 ); } diff --git a/clients/tools/common.h b/clients/tools/common.h index ed9c4bdf15..f8cb32e89c 100644 --- a/clients/tools/common.h +++ b/clients/tools/common.h @@ -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_ */ diff --git a/clients/tools/ldapcompare.c b/clients/tools/ldapcompare.c index b357c6d09a..18ea6efee7 100644 --- a/clients/tools/ldapcompare.c +++ b/clients/tools/ldapcompare.c @@ -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 ); } diff --git a/clients/tools/ldapcompare.dsp b/clients/tools/ldapcompare.dsp index 83566ba62b..ab31707cdc 100644 --- a/clients/tools/ldapcompare.dsp +++ b/clients/tools/ldapcompare.dsp @@ -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 diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index 77ed1397f0..d3638404a5 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -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 ); } diff --git a/clients/tools/ldapdelete.dsp b/clients/tools/ldapdelete.dsp index af7b4be030..c136d67c8a 100644 --- a/clients/tools/ldapdelete.dsp +++ b/clients/tools/ldapdelete.dsp @@ -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 diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index b0b5fb0e05..d4f452b95e 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -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 ); } diff --git a/clients/tools/ldapmodify.dsp b/clients/tools/ldapmodify.dsp index 9a58a7060f..ffa4e68df8 100644 --- a/clients/tools/ldapmodify.dsp +++ b/clients/tools/ldapmodify.dsp @@ -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 diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c index 4ac93c0325..225e536657 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -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: diff --git a/clients/tools/ldapmodrdn.dsp b/clients/tools/ldapmodrdn.dsp index bcf0cc01cc..d1304ce84c 100644 --- a/clients/tools/ldapmodrdn.dsp +++ b/clients/tools/ldapmodrdn.dsp @@ -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 diff --git a/clients/tools/ldappasswd.c b/clients/tools/ldappasswd.c index fa627523e5..a0265f4ebd 100644 --- a/clients/tools/ldappasswd.c +++ b/clients/tools/ldappasswd.c @@ -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 ); diff --git a/clients/tools/ldappasswd.dsp b/clients/tools/ldappasswd.dsp index df406dfe5f..7aa142c7d4 100644 --- a/clients/tools/ldappasswd.dsp +++ b/clients/tools/ldappasswd.dsp @@ -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 diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 0b73cd2ab7..ec86820b88 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -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" : "", diff --git a/clients/tools/ldapsearch.dsp b/clients/tools/ldapsearch.dsp index d3918c8e45..de7f3e9723 100644 --- a/clients/tools/ldapsearch.dsp +++ b/clients/tools/ldapsearch.dsp @@ -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 diff --git a/clients/tools/ldapwhoami.c b/clients/tools/ldapwhoami.c index 29d7e520d4..4ccb11aea2 100644 --- a/clients/tools/ldapwhoami.c +++ b/clients/tools/ldapwhoami.c @@ -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 ); diff --git a/clients/tools/ldapwhoami.dsp b/clients/tools/ldapwhoami.dsp index 5e44a4fc7c..c4bdaa014a 100644 --- a/clients/tools/ldapwhoami.dsp +++ b/clients/tools/ldapwhoami.dsp @@ -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 -- 2.39.5