From d8090dea55e8bcfdfb19a621a5789622539aadd3 Mon Sep 17 00:00:00 2001 From: Dave Storey Date: Mon, 14 Dec 1998 20:39:02 +0000 Subject: [PATCH] Streamlined Kerberos Code. --- clients/tools/ldapdelete.c | 24 +++++++++++++----------- clients/tools/ldapmodify.c | 24 +++++++++++++----------- clients/tools/ldapmodrdn.c | 24 +++++++++++++----------- clients/tools/ldapsearch.c | 34 ++++++++++++++-------------------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index 6638fee629..078eca2d48 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -33,18 +33,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; @@ -103,13 +112,6 @@ main( int argc, char **argv ) ldap_set_option( ld, LDAP_OPT_DEREF, &deref ); } - 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 88756ada24..5e124e53ce 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -68,7 +68,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 ) { @@ -79,7 +79,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 ) { @@ -96,10 +97,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; @@ -163,13 +172,6 @@ main( int argc, char **argv ) /* this seems prudent */ ldap_set_option( ld, LDAP_OPT_DEREF, LDAP_DEREF_NEVER); - 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 4697b283cd..c023c70c92 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -35,20 +35,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; @@ -124,13 +133,6 @@ main(int argc, char **argv) /* this seems prudent */ ldap_set_option( ld, LDAP_OPT_DEREF, LDAP_DEREF_NEVER); - 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 7ae964cd76..2e03071f42 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -85,24 +85,19 @@ 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 referrals, timelimit, sizelimit, authmethod; LDAP *ld; infile = NULL; - deref = verbose = allow_binary = not = kerberos = vals2tmp = + deref = verbose = allow_binary = not = vals2tmp = attrsonly = ldif = 0; referrals = (int) LDAP_OPT_ON; sizelimit = timelimit = 0; 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; @@ -117,14 +112,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; @@ -260,13 +261,6 @@ main( int argc, char **argv ) /* set option error */ } - 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.39.5