From: Kurt Zeilenga Date: Wed, 20 Jan 1999 00:50:56 +0000 (+0000) Subject: Import password prompting from -devel. X-Git-Tag: OPENLDAP_REL_ENG_1_2_BETA~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a62cdf12cc876d640f22b843d5b15c9390e49a1f;p=thirdparty%2Fopenldap.git Import password prompting from -devel. --- diff --git a/CHANGES b/CHANGES index a987e4c266..2943800d8b 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,8 @@ OpenLDAP Change Log Changes included in OpenLDAP 1.2 CVS Tag: OPENLDAP_REL_ENG_1_2 Add ldappasswd() tool + Add client/tools password prompting + Update client/tools Kerberos option handling Changes included in OpenLDAP 1.1.3 CVS Tag: OPENLDAP_REL_ENG_1_1_3 diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index 9ac662fd12..a9ca7f6b0c 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -33,16 +33,16 @@ static int dodelete LDAP_P(( int main( int argc, char **argv ) { - char *usage = "usage: %s [-n] [-v] [-k] [-d debug-level] [-f file] [-h ldaphost] [-p ldapport] [-D binddn] [-w passwd] [dn]...\n"; + char *usage = "usage: %s [-n] [-v] [-k] [-W] [-d debug-level] [-f file] [-h ldaphost] [-p ldapport] [-D binddn] [-w passwd] [dn]...\n"; char buf[ 4096 ]; FILE *fp; - int i, rc, authmethod; + int i, rc, authmethod, want_bindpw; - not = verbose = contoper = 0; + not = verbose = contoper = want_bindpw = 0; fp = NULL; authmethod = LDAP_AUTH_SIMPLE; - while (( i = getopt( argc, argv, "nvkKch:p:D:w:d:f:" )) != EOF ) { + while (( i = getopt( argc, argv, "WnvkKch:p:D:w:d:f:" )) != EOF ) { switch( i ) { case 'k': /* kerberos bind */ #ifdef HAVE_KERBEROS @@ -92,6 +92,9 @@ main( int argc, char **argv ) case 'v': /* verbose mode */ verbose++; break; + case 'W': + want_bindpw++; + break; default: fprintf( stderr, usage, argv[0] ); exit( 1 ); @@ -111,6 +114,9 @@ main( int argc, char **argv ) ld->ld_deref = LDAP_DEREF_NEVER; /* prudent, but probably unnecessary */ + if (want_bindpw) + passwd = getpass("Enter LDAP Password: "); + if ( ldap_bind_s( ld, binddn, passwd, authmethod ) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_bind" ); exit( 1 ); diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 2b3074ccd8..02280642a6 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -71,8 +71,8 @@ main( int argc, char **argv ) { char *infile, *rbuf, *start, *p, *q; FILE *fp; - int rc, i, use_ldif, authmethod; - char *usage = "usage: %s [-abcknrvF] [-d debug-level] [-h ldaphost] [-p ldapport] [-D binddn] [-w passwd] [ -f file | < entryfile ]\n"; + int rc, i, use_ldif, authmethod, want_bindpw; + char *usage = "usage: %s [-abcknrvWF] [-d debug-level] [-h ldaphost] [-p ldapport] [-D binddn] [-w passwd] [ -f file | < entryfile ]\n"; if (( prog = strrchr( argv[ 0 ], '/' )) == NULL ) { prog = argv[ 0 ]; @@ -82,10 +82,10 @@ main( int argc, char **argv ) new = ( strcmp( prog, "ldapadd" ) == 0 ); infile = NULL; - not = verbose = valsfromfiles = 0; + not = verbose = valsfromfiles = want_bindpw = 0; authmethod = LDAP_AUTH_SIMPLE; - while (( i = getopt( argc, argv, "FabckKnrtvh:p:D:w:d:f:" )) != EOF ) { + while (( i = getopt( argc, argv, "WFabckKnrtvh:p:D:w:d:f:" )) != EOF ) { switch( i ) { case 'a': /* add */ new = 1; @@ -145,6 +145,9 @@ main( int argc, char **argv ) case 'v': /* verbose mode */ verbose++; break; + case 'W': + want_bindpw++; + break; default: fprintf( stderr, usage, prog ); exit( 1 ); @@ -174,6 +177,9 @@ main( int argc, char **argv ) ld->ld_deref = LDAP_DEREF_NEVER; /* this seems prudent */ + if (want_bindpw) + passwd = getpass("Enter LDAP Password: "); + if ( ldap_bind_s( ld, binddn, passwd, authmethod ) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_bind" ); exit( 1 ); diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c index 332691bdd5..d3fa7db564 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -35,18 +35,18 @@ static int domodrdn LDAP_P(( int main(int argc, char **argv) { - char *usage = "usage: %s [-nvkc] [-d debug-level] [-h ldaphost] [-p ldapport] [-D binddn] [-w passwd] [ -f file | < entryfile | dn newrdn ]\n"; + char *usage = "usage: %s [-nvkWc] [-d debug-level] [-h ldaphost] [-p ldapport] [-D binddn] [-w passwd] [ -f file | < entryfile | dn newrdn ]\n"; char *myname,*infile, *entrydn, *rdn, buf[ 4096 ]; FILE *fp; - int rc, i, remove, havedn, authmethod; + int rc, i, remove, havedn, authmethod, want_bindpw; infile = NULL; - not = contoper = verbose = remove = 0; + not = contoper = verbose = remove = want_bindpw = 0; authmethod = LDAP_AUTH_SIMPLE; myname = (myname = strrchr(argv[0], '/')) == NULL ? argv[0] : ++myname; - while (( i = getopt( argc, argv, "kKcnvrh:p:D:w:d:f:" )) != EOF ) { + while (( i = getopt( argc, argv, "WkKcnvrh:p:D:w:d:f:" )) != EOF ) { switch( i ) { case 'k': /* kerberos bind */ #ifdef HAVE_KERBEROS @@ -96,6 +96,9 @@ main(int argc, char **argv) case 'r': /* remove old RDN */ remove++; break; + case 'W': + want_bindpw++; + break; default: fprintf( stderr, usage, argv[0] ); exit( 1 ); @@ -135,6 +138,9 @@ main(int argc, char **argv) ld->ld_deref = LDAP_DEREF_NEVER; /* this seems prudent */ + if (want_bindpw) + passwd = getpass("Enter LDAP Password: "); + if ( ldap_bind_s( ld, binddn, passwd, authmethod ) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_bind" ); exit( 1 ); diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index a6ab61426d..79e63c33ba 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -17,9 +17,8 @@ #define DEFSEP "=" - -static void -usage( char *s ) +static void usage( s ) +char *s; { fprintf( stderr, "usage: %s [options] filter [attributes...]\nwhere:\n", s ); fprintf( stderr, " filter\tRFC-1558 compliant LDAP search filter\n" ); @@ -85,16 +84,18 @@ static int skipsortattr = 0; static int verbose, not, includeufn, allow_binary, vals2tmp, ldif; int -main( int argc, char **argv ) +main( argc, argv ) +int argc; +char **argv; { char *infile, *filtpattern, **attrs, line[ BUFSIZ ]; FILE *fp; - int rc, i, first, scope, deref, attrsonly; + int rc, i, first, scope, kerberos, deref, attrsonly; int ldap_options, timelimit, sizelimit, authmethod; LDAP *ld; infile = NULL; - verbose = allow_binary = not = vals2tmp = + deref = verbose = allow_binary = not = kerberos = vals2tmp = attrsonly = ldif = 0; #ifdef LDAP_REFERRALS @@ -106,8 +107,15 @@ main( int argc, char **argv ) deref = sizelimit = timelimit = -1; scope = LDAP_SCOPE_SUBTREE; authmethod = LDAP_AUTH_SIMPLE; + scope = LDAP_SCOPE_SUBTREE; - while (( i = getopt( argc, argv, "KknuvtRABLD:s:f:h:b:d:p:F:a:w:l:z:S:")) != EOF ) { + while (( i = getopt( argc, argv, +#ifdef HAVE_KERBEROS + "KknuvtRABLD:s:f:h:b:d:p:F:a:w:l:z:S:" +#else + "nuvtRABLD:s:f:h:b:d:p:F:a:w:l:z:S:" +#endif + )) != EOF ) { switch( i ) { case 'n': /* do Not do any searches */ ++not; @@ -122,20 +130,14 @@ main( int argc, char **argv ) fprintf( stderr, "compile with -DLDAP_DEBUG for debugging\n" ); #endif /* LDAP_DEBUG */ break; - case 'k': /* use kerberos bind */ #ifdef HAVE_KERBEROS - authmethod = LDAP_AUTH_KRBV4; -#else - fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); -#endif + case 'k': /* use kerberos bind */ + kerberos = 2; break; case 'K': /* use kerberos bind, 1st part only */ -#ifdef HAVE_KERBEROS - authmethod = LDAP_AUTH_KRBV41; -#else - fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); -#endif + kerberos = 1; break; +#endif case 'u': /* include UFN */ ++includeufn; break; @@ -274,6 +276,13 @@ main( int argc, char **argv ) } ld->ld_options = ldap_options; + if ( !kerberos ) { + authmethod = LDAP_AUTH_SIMPLE; + } else if ( kerberos == 1 ) { + authmethod = LDAP_AUTH_KRBV41; + } else { + authmethod = LDAP_AUTH_KRBV4; + } if ( ldap_bind_s( ld, binddn, passwd, authmethod ) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_bind" ); exit( 1 ); @@ -313,9 +322,6 @@ main( int argc, char **argv ) ldap_unbind( ld ); exit( rc ); - - /* UNREACHABLE */ - return(0); }