Commit 9697ad21 authored by Dave Storey's avatar Dave Storey
Browse files

Added support for password prompting. (-W switch)

parent add79ef9
......@@ -30,16 +30,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
......@@ -89,6 +89,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 );
......@@ -112,6 +115,9 @@ main( int argc, char **argv )
ldap_set_option( ld, LDAP_OPT_DEREF, &deref );
}
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 );
......
......@@ -68,8 +68,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 ];
......@@ -79,10 +79,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;
......@@ -142,6 +142,9 @@ main( int argc, char **argv )
case 'v': /* verbose mode */
verbose++;
break;
case 'W':
want_bindpw++;
break;
default:
fprintf( stderr, usage, prog );
exit( 1 );
......@@ -172,6 +175,9 @@ main( int argc, char **argv )
/* this seems prudent */
ldap_set_option( ld, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
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 );
......
......@@ -32,18 +32,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
......@@ -93,6 +93,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 );
......@@ -133,6 +136,9 @@ main(int argc, char **argv)
/* this seems prudent */
ldap_set_option( ld, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
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 );
......
......@@ -43,6 +43,7 @@ usage( char *s )
fprintf( stderr, " -z size lim\tsize limit (in entries) for search\n" );
fprintf( stderr, " -D binddn\tbind dn\n" );
fprintf( stderr, " -w passwd\tbind passwd (for simple authentication)\n" );
fprintf( stderr, " -W\t\tprompt for bind passwd\n" );
#ifdef HAVE_KERBEROS
fprintf( stderr, " -k\t\tuse Kerberos instead of Simple Password authentication\n" );
#endif
......@@ -86,18 +87,18 @@ main( int argc, char **argv )
char *infile, *filtpattern, **attrs, line[ BUFSIZ ];
FILE *fp;
int rc, i, first, scope, deref, attrsonly;
int referrals, timelimit, sizelimit, authmethod;
int referrals, timelimit, sizelimit, authmethod, want_bindpw;
LDAP *ld;
infile = NULL;
deref = verbose = allow_binary = not = vals2tmp =
attrsonly = ldif = 0;
attrsonly = ldif = want_bindpw = 0;
referrals = (int) LDAP_OPT_ON;
sizelimit = timelimit = 0;
scope = LDAP_SCOPE_SUBTREE;
authmethod = LDAP_AUTH_SIMPLE;
while (( i = getopt( argc, argv, "KknuvtRABLD:s:f:h:b:d:p:F:a:w:l:z:S:")) != EOF ) {
while (( i = getopt( argc, argv, "WKknuvtRABLD:s:f:h:b:d:p:F:a:w:l:z:S:")) != EOF ) {
switch( i ) {
case 'n': /* do Not do any searches */
++not;
......@@ -202,6 +203,9 @@ main( int argc, char **argv )
case 'S': /* sort attribute */
sortattr = strdup( optarg );
break;
case 'W':
want_bindpw++;
break;
default:
usage( argv[0] );
}
......@@ -261,6 +265,9 @@ main( int argc, char **argv )
/* set option error */
}
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 );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment