From 5568bf8840801a0ad16cdec8b5349ad77dca5fea Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 20 Jan 1999 00:28:52 +0000 Subject: [PATCH] Import improved handling of kerberos bind option. --- clients/tools/ldapdelete.c | 24 +++++++++++++----------- clients/tools/ldapmodify.c | 24 +++++++++++++----------- clients/tools/ldapmodrdn.c | 24 +++++++++++++----------- clients/tools/ldapsearch.c | 35 +++++++++++++++-------------------- 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index e1cae1b82f..9ac662fd12 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -36,18 +36,27 @@ 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 buf[ 4096 ]; FILE *fp; - int i, rc, kerberos, authmethod; + int i, rc, authmethod; - kerberos = not = verbose = contoper = 0; + not = verbose = contoper = 0; fp = NULL; + authmethod = LDAP_AUTH_SIMPLE; while (( i = getopt( argc, argv, "nvkKch:p:D:w:d:f:" )) != EOF ) { switch( i ) { case 'k': /* kerberos bind */ - kerberos = 2; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV4; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); +#endif break; case 'K': /* kerberos bind, part one only */ - kerberos = 1; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV41; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); +#endif break; case 'c': /* continuous operation mode */ ++contoper; @@ -102,13 +111,6 @@ main( int argc, char **argv ) ld->ld_deref = LDAP_DEREF_NEVER; /* prudent, but probably unnecessary */ - 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 ); diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 01b2cbc851..2b3074ccd8 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -71,7 +71,7 @@ main( int argc, char **argv ) { char *infile, *rbuf, *start, *p, *q; FILE *fp; - int rc, i, kerberos, use_ldif, authmethod; + 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"; if (( prog = strrchr( argv[ 0 ], '/' )) == NULL ) { @@ -82,7 +82,8 @@ main( int argc, char **argv ) new = ( strcmp( prog, "ldapadd" ) == 0 ); infile = NULL; - kerberos = not = verbose = valsfromfiles = 0; + not = verbose = valsfromfiles = 0; + authmethod = LDAP_AUTH_SIMPLE; while (( i = getopt( argc, argv, "FabckKnrtvh:p:D:w:d:f:" )) != EOF ) { switch( i ) { @@ -99,10 +100,18 @@ main( int argc, char **argv ) replace = 1; break; case 'k': /* kerberos bind */ - kerberos = 2; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV4; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); +#endif break; case 'K': /* kerberos bind, part 1 only */ - kerberos = 1; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV41; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); +#endif break; case 'F': /* force all changes records to be used */ force = 1; @@ -165,13 +174,6 @@ main( int argc, char **argv ) ld->ld_deref = LDAP_DEREF_NEVER; /* this seems prudent */ - 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 ); diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c index 229468473d..332691bdd5 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -38,20 +38,29 @@ 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 *myname,*infile, *entrydn, *rdn, buf[ 4096 ]; FILE *fp; - int rc, i, kerberos, remove, havedn, authmethod; + int rc, i, remove, havedn, authmethod; infile = NULL; - kerberos = not = contoper = verbose = remove = 0; + not = contoper = verbose = remove = 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 ) { switch( i ) { case 'k': /* kerberos bind */ - kerberos = 2; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV4; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); +#endif break; case 'K': /* kerberos bind, part one only */ - kerberos = 1; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV41; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); +#endif break; case 'c': /* continuous operation mode */ ++contoper; @@ -126,13 +135,6 @@ main(int argc, char **argv) ld->ld_deref = LDAP_DEREF_NEVER; /* this seems prudent */ - 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 ); diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 065dc790de..a6ab61426d 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -89,13 +89,14 @@ main( int argc, char **argv ) { char *infile, *filtpattern, **attrs, line[ BUFSIZ ]; FILE *fp; - int rc, i, first, scope, kerberos, deref, attrsonly; + int rc, i, first, scope, deref, attrsonly; int ldap_options, timelimit, sizelimit, authmethod; LDAP *ld; infile = NULL; - verbose = allow_binary = not = kerberos = vals2tmp = + verbose = allow_binary = not = vals2tmp = attrsonly = ldif = 0; + #ifdef LDAP_REFERRALS ldap_options = LDAP_OPT_REFERRALS; #else /* LDAP_REFERRALS */ @@ -104,14 +105,9 @@ main( int argc, char **argv ) deref = sizelimit = timelimit = -1; scope = LDAP_SCOPE_SUBTREE; + authmethod = LDAP_AUTH_SIMPLE; - 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 ) { + while (( i = getopt( argc, argv, "KknuvtRABLD:s:f:h:b:d:p:F:a:w:l:z:S:")) != EOF ) { switch( i ) { case 'n': /* do Not do any searches */ ++not; @@ -126,14 +122,20 @@ main( int argc, char **argv ) fprintf( stderr, "compile with -DLDAP_DEBUG for debugging\n" ); #endif /* LDAP_DEBUG */ break; -#ifdef HAVE_KERBEROS case 'k': /* use kerberos bind */ - kerberos = 2; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV4; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); +#endif break; case 'K': /* use kerberos bind, 1st part only */ - kerberos = 1; - break; +#ifdef HAVE_KERBEROS + authmethod = LDAP_AUTH_KRBV41; +#else + fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]); #endif + break; case 'u': /* include UFN */ ++includeufn; break; @@ -272,13 +274,6 @@ 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 ); -- 2.47.2