From: Andrew Deason Date: Wed, 7 Jul 2010 17:52:10 +0000 (-0500) Subject: klog: refactor klog_prompter X-Git-Tag: openafs-devel-1_5_76~171 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=a064446cf6987744ef614cbf37f43231bc207c7e klog: refactor klog_prompter The ifdefs in klog_prompter were getting a bit confusing. Split out some logic into a separate "is this prompt a password prompt" function. As a result, we can build without KRB5_PROMPT_TYPE_PASSWORD defined, which happens to be the case on hp_ux11i. Change-Id: I1d5f794bfc33017f699478e367cde91a3e77d33c Reviewed-on: http://gerrit.openafs.org/2353 Tested-by: Andrew Deason Reviewed-by: Simon Wilkinson Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/aklog/klog.c b/src/aklog/klog.c index 0ad432c..fa037d6 100644 --- a/src/aklog/klog.c +++ b/src/aklog/klog.c @@ -286,6 +286,53 @@ k5_to_k4_name(krb5_context k5context, } } +#if defined(USING_HEIMDAL) || defined(HAVE_KRB5_PROMPT_TYPE) +static int +klog_is_pass_prompt(int index, krb5_context context, krb5_prompt prompts[]) +{ + switch (prompts[index].type) { + case KRB5_PROMPT_TYPE_PASSWORD: + case KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN: + return 1; + default: + return 0; + } +} +#elif defined(HAVE_KRB5_GET_PROMPT_TYPES) +static int +klog_is_pass_prompt(int index, krb5_context context, krb5_prompt prompts[]) +{ + /* this isn't thread-safe or anything obviously; it just should be good + * enough to work with klog */ + static krb5_prompt_type *types = NULL; + if (index == 0) { + types = NULL; + } + if (!types) { + types = krb5_get_prompt_types(context); + } + if (!types) { + return 0; + } + switch (types[index]) { + case KRB5_PROMPT_TYPE_PASSWORD: + case KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN: + return 1; + default: + return 0; + } +} +#else +static int +klog_is_pass_prompt(int index, krb5_context context, krb5_prompt prompts[]) +{ + /* AIX 5.3 doesn't have krb5_get_prompt_types. Neither does HP-UX, which + * also doesn't even define KRB5_PROMPT_TYPE_PASSWORD &co. We have no way + * of determining the the prompt type, so just assume it's a password */ + return 1; +} +#endif + /* save and reuse password. This is necessary to make * "direct to service" authentication work with most * flavors of kerberos, when the afs principal has no instance. @@ -303,39 +350,14 @@ klog_prompter(krb5_context context, krb5_prompt prompts[]) { krb5_error_code code; - int i, type; -#if !defined(USING_HEIMDAL) && defined(HAVE_KRB5_GET_PROMPT_TYPES) - krb5_prompt_type *types; -#endif + int i; struct kp_arg *kparg = (struct kp_arg *) a; size_t length; code = krb5_prompter_posix(context, a, name, banner, num_prompts, prompts); if (code) return code; -#if !defined(USING_HEIMDAL) && defined(HAVE_KRB5_GET_PROMPT_TYPES) - if ((types = krb5_get_prompt_types(context))) -#endif for (i = 0; i < num_prompts; ++i) { -#if !defined(USING_HEIMDAL) -#if defined(HAVE_KRB5_GET_PROMPT_TYPES) - type = types[i]; -#elif defined(HAVE_KRB5_PROMPT_TYPE) - type = prompts[i].type; -#else - /* AIX 5.3 krb5_get_prompt_types is missing. Um... */ - type = ((i == 1)&&(num_prompts == 2)) ? - KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN : KRB5_PROMPT_TYPE_PASSWORD; -#endif -#else - type = prompts[i].type; -#endif -#if 0 - printf ("i%d t%d <%.*s>\n", i, type, prompts[i].reply->length, - prompts[i].reply->data); -#endif - switch(type) { - case KRB5_PROMPT_TYPE_PASSWORD: - case KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN: + if (klog_is_pass_prompt(i, context, prompts)) { length = prompts[i].reply->length; if (length > kparg->allocated - 1) length = kparg->allocated - 1;