From: Todd C. Miller Date: Sun, 11 Jul 1999 18:42:34 +0000 (+0000) Subject: combine skey/opie code into rfc1938.c X-Git-Tag: SUDO_1_6_0~246 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ad09786a1d6a345bbabf52e277a42cd9a62ace7;p=sudo combine skey/opie code into rfc1938.c --- diff --git a/auth/opie.c b/auth/opie.c deleted file mode 100644 index 74f28690c..000000000 --- a/auth/opie.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * CU sudo version 1.6 - * Copyright (c) 1999 Todd C. Miller - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 1, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Please send bugs, changes, problems to sudo-bugs@courtesan.com - */ - -#ifndef lint -static const char rcsid[] = "$Sudo$"; -#endif /* lint */ - -#include "config.h" - -#include -#ifdef STDC_HEADERS -#include -#endif /* STDC_HEADERS */ -#ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ -#ifdef HAVE_STRING_H -#include -#endif /* HAVE_STRING_H */ -#ifdef HAVE_STRINGS_H -#include -#endif /* HAVE_STRINGS_H */ -#include -#include -#include -#include - -#include "sudo.h" -#include "sudo_auth.h" - -int -opie_setup(pw, promptp, data) - struct passwd *pw; - char **promptp; - void **data; -{ - char challenge[OPIE_CHALLENGE_MAX]; - static char *orig_prompt = NULL, *new_prompt = NULL; - static int op_len, np_size; - static struct opie opie; - - /* Stash a pointer to the opie struct if we have not initialized */ - if (!*data) - *data = &opie; - - /* Save the original prompt */ - if (orig_prompt == NULL) { - orig_prompt = *promptp; - op_len = strlen(orig_prompt); - - /* Ignore trailing colon (we will add our own) */ - if (orig_prompt[op_len - 1] == ':') - op_len--; - } - - /* Get the opie part of the prompt */ - if (opiechallenge(&opie, user_name, challenge) != 0) { -#ifdef OTP_ONLY - (void) fprintf(stderr, - "%s: You do not exist in the s/key database.\n", - Argv[0]); - return(AUTH_FATAL); -#else - return(AUTH_FAILURE); -#endif /* OTP_ONLY */ - } - - /* Get space for new prompt with embedded S/Key challenge */ - if (np_size < op_len + strlen(challenge) + 7) { - np_size = op_len + strlen(challenge) + 7; - new_prompt = (char *) erealloc(new_prompt, np_size); - } - -#ifdef LONG_OTP_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_OTP_PROMPT */ - - *promptp = new_prompt; - return(AUTH_SUCCESS); -} - -int -opie_verify(pw, pass, data) - struct passwd *pw; - char *pass; - void **data; -{ - struct opie *opiep = (struct opie *) (*data); - - if (opieverify(opiep, pass) == 0) - return(AUTH_SUCCESS); - else - return(AUTH_FAILURE); -} diff --git a/auth/skey.c b/auth/rfc1938.c similarity index 74% rename from auth/skey.c rename to auth/rfc1938.c index c930a24bc..3047d9ad6 100644 --- a/auth/skey.c +++ b/auth/rfc1938.c @@ -1,6 +1,6 @@ /* * CU sudo version 1.6 - * Copyright (c) 1999 Todd C. Miller + * Copyright (c) 1994,1996,1998,1999 Todd C. Miller * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,18 @@ #include #include #include + +#if defined(HAVE_SKEY) #include +#define RFC1938 skey +#define rfc1938challenge skeychallenge +#define rfc1938verify skeyverify +#elif defined(HAVE_OPIE) +#include +#define RFC1938 opie +#define rfc1938challenge opiechallenge +#define rfc1938verify opieverify +#endif #include "sudo.h" #include "sudo_auth.h" @@ -47,7 +58,7 @@ static const char rcsid[] = "$Sudo$"; #endif /* lint */ int -skey_setup(pw, promptp, data) +rfc1938_setup(pw, promptp, data) struct passwd *pw; char **promptp; void **data; @@ -55,11 +66,11 @@ skey_setup(pw, promptp, data) char challenge[256]; static char *orig_prompt = NULL, *new_prompt = NULL; static int op_len, np_size; - static struct skey skey; + static struct RFC1938 rfc1938; - /* Stash a pointer to the skey struct if we have not initialized */ + /* Stash a pointer to the rfc1938 struct if we have not initialized */ if (!*data) - *data = &skey; + *data = &rfc1938; /* Save the original prompt */ if (orig_prompt == NULL) { @@ -71,15 +82,17 @@ skey_setup(pw, promptp, data) op_len--; } +#ifdef HAVE_SKEY /* Close old stream */ - if (skey.keyfile) - (void) fclose(skey.keyfile); + if (rfc1938.keyfile) + (void) fclose(rfc1938.keyfile); +#endif - /* Get the skey part of the prompt */ - if (skeychallenge(&skey, user_name, challenge) != 0) { + /* Get the rfc1938 part of the prompt */ + if (rfc1938challenge(&rfc1938, pw->pw_name, challenge) != 0) { #ifdef OTP_ONLY (void) fprintf(stderr, - "%s: You do not exist in the s/key database.\n", + "%s: You do not exist in the OTP database.\n", Argv[0]); return(AUTH_FATAL); #else @@ -104,14 +117,13 @@ skey_setup(pw, promptp, data) } int -skey_verify(pw, pass, data) +rfc1938_verify(pw, pass, data) struct passwd *pw; char *pass; void **data; { - struct skey *skeyp = (struct skey *) (*data); - if (skeyverify(skeyp, pass) == 0) + if (rfc1938verify((struct RFC1938 *) (*data), pass) == 0) return(AUTH_SUCCESS); else return(AUTH_FAILURE); diff --git a/auth/sudo_auth.h b/auth/sudo_auth.h index e0224eb6b..7870f8412 100644 --- a/auth/sudo_auth.h +++ b/auth/sudo_auth.h @@ -33,10 +33,8 @@ int dce_verify __P((struct passwd *pw, char *pass, void **data)); int passwd_verify __P((struct passwd *pw, char *pass, void **data)); int secureware_setup __P((struct passwd *pw, char **prompt, void **data)); int secureware_verify __P((struct passwd *pw, char *pass, void **data)); -int skey_setup __P((struct passwd *pw, char **prompt, void **data)); -int skey_verify __P((struct passwd *pw, char *pass, void **data)); -int opie_setup __P((struct passwd *pw, char **prompt, void **data)); -int opie_verify __P((struct passwd *pw, char *pass, void **data)); +int rfc1938_setup __P((struct passwd *pw, char **prompt, void **data)); +int rfc1938_verify __P((struct passwd *pw, char *pass, void **data)); int afs_verify __P((struct passwd *pw, char *pass, void **data)); int kerb4_setup __P((struct passwd *pw, char **prompt, void **data)); int kerb4_verify __P((struct passwd *pw, char *pass, void **data)); @@ -65,13 +63,9 @@ int kerb5_verify __P((struct passwd *pw, char *pass, void **data)); #elif defined(HAVE_FWTK) # define AUTH_STANDALONE \ AUTH_ENTRY(1, "fwtk", fwtk_setup, fwtk_verify, fwtk_cleanup) -#elif defined(HAVE_SKEY) && defined(OTP_ONLY) +#elif defined(OTP_ONLY) && (defined(HAVE_SKEY) || defined(HAVE_OPIE)) # define AUTH_STANDALONE \ - AUTH_ENTRY(1, "skey", skey_setup, skey_verify, NULL) -# define AUTH_STANDALONE_GETPASS -#elif defined(HAVE_OPIE) && defined(OTP_ONLY) -# define AUTH_STANDALONE \ - AUTH_ENTRY(1, "opie", opie_setup, opie_verify, NULL) + AUTH_ENTRY(1, "rfc1938", rfc1938_setup, rfc1938_verify, NULL) # define AUTH_STANDALONE_GETPASS #endif