First cut at -V (version) argument. Needs work.

This commit is contained in:
Kurt Zeilenga 2003-01-20 20:11:57 +00:00
parent fc75445270
commit dab6bdaaad
16 changed files with 100 additions and 48 deletions

View 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 (authmethod == -1 && version > LDAP_VERSION2) {
if (protocol == -1)
protocol = LDAP_VERSION3;
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 );
}

View 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_ */

View 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 );
}

View 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

View 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 );
}

View 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

View 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 );
}

View 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

View 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:

View 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

View 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 );

View 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

View 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" : "",

View 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

View 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 );

View 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