From f4f2eb66b1039f770dd3495d6cce68cb9bcedac7 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 3 Oct 1996 23:43:17 +0000 Subject: [PATCH] now call skeychallenge() to get challenge instead of making one up ourselves. this way, we get extra goodies in the prompt. --- check.c | 99 +++++++++++++++++++++++++-------------------------------- 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/check.c b/check.c index 6923697e7..260b67096 100644 --- a/check.c +++ b/check.c @@ -660,75 +660,62 @@ static char *sudo_skeyprompt(user_skey, p) struct skey *user_skey; char *p; { -#ifndef LONG_SKEY_PROMPT - char buf[32]; - char *new_prompt; - static char *old_prompt = NULL; - static int plen; -#endif /* LONG_SKEY_PROMPT */ - - /* close the key file if necesary */ - if (user_skey->keyfile != NULL) - (void) fclose(user_skey->keyfile); + char challenge[256]; + int rval; + static char *orig_prompt, *new_prompt = NULL; + static int op_len, np_size; - /* return the old prompt if we cannot get s/key info */ - if (skeylookup(user_skey, user_name)) { - if (user_skey->keyfile != NULL) { - (void) fclose(user_skey->keyfile); - user_skey->keyfile = NULL; - } + /* get the skey part of the prompt */ + if ((rval = skeychallenge(user_skey, user_name, challenge)) != 0) { #ifdef SKEY_ONLY - (void) fprintf(stderr, "%s: You do not exist in the s/key database.\n", + (void) fprintf(stderr, + "%s: You do not exist in the s/key database.\n", Argv[0]); exit(1); #else -# ifdef LONG_SKEY_PROMPT - return(p); -# else - if (old_prompt == NULL) { - return(p); - } else { - return(old_prompt); - } -# endif /* LONG_SKEY_PROMPT */ + /* return the original prompt if we cannot get s/key info */ + return(orig_prompt); #endif /* SKEY_ONLY */ } - -#ifdef LONG_SKEY_PROMPT - /* separate s/key challenge and prompt for easy snarfing */ - (void) fprintf(stderr, "key %d %s\n", user_skey->n - 1, user_skey->seed); - - /* return old prompt unmolested */ - return(p); - -#else - - /* keep a pointer to the original prompt around for future reference */ - if (old_prompt == NULL) { - old_prompt = p; - plen = strlen(p); - - /* ignore trailing colon's */ - if (p[plen - 1] == ':') - plen--; + (void) fclose(user_skey->keyfile); + + /* get space for new prompt with embedded s/key challenge */ + if (new_prompt == NULL) { + orig_prompt = p; + op_len = strlen(p); + + /* ignore trailing colon */ + if (p[op_len - 1] == ':') + op_len--; + + /* allocate space for new prompt */ + np_size = op_len + strlen(challenge) + 7; + if (!(new_prompt = (char *) malloc(np_size))) { + perror("malloc"); + (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); + exit(1); + } } else { - (void) free(p); - } - - (void) sprintf(buf, "%d", user_skey->n - 1); - if ((new_prompt = (char *) - malloc(plen + strlen(buf) + strlen(user_skey->seed) + 12)) == NULL) { - perror("malloc"); - (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); - exit(1); + /* already have space allocated, is it enough? */ + if (np_size < op_len + strlen(challenge) + 7) { + np_size = op_len + strlen(challenge) + 7; + if (!(new_prompt = (char *) realloc(new_prompt, np_size))) { + perror("malloc"); + (void) fprintf(stderr, "%s: cannot allocate memory!\n", + Argv[0]); + exit(1); + } + } } /* embed the s/key challenge into the new password prompt */ - (void) sprintf(new_prompt, "%.*s [s/key %d %s]:", plen, old_prompt, - user_skey->n - 1, user_skey->seed); +#ifdef LONG_SKEY_PROMPT + (void) sprintf(new_prompt, "%s\n%s", challenge, orig_prompt); +#else + (void) sprintf(new_prompt, "%.*s [ %s ]:", op_len, orig_prompt, challenge); +#endif /* LONG_SKEY_PROMPT */ return(new_prompt); -#endif /* LONG_SKEY_PROMPT */ } #endif /* HAVE_SKEY */ -- 2.40.0