#include <krb5.h>
#include "krb.h"
#include "krb4int.h"
#include "krb_err.h"
#include "prot.h"
#include <string.h>
#ifndef NULL
#define NULL 0
#endif
#ifndef INTK_PW_NULL
#define INTK_PW_NULL KRBET_GT_PW_NULL
#endif
static int
passwd_to_key(user,instance,realm,passwd,key)
char *user, *instance, *realm, *passwd;
C_Block key;
{
#if defined(_WIN32)
string_to_key(passwd, key);
#else
#ifdef NOENCRYPTION
if (!passwd)
placebo_read_password(key, "Password: ", 0);
#else
if (passwd)
string_to_key(passwd, key);
else {
des_read_password((des_cblock *)key, "Password", 0);
}
#endif
#endif
return (0);
}
int KRB5_CALLCONV
krb_get_pw_in_tkt(user,instance,realm,service,sinstance,life,password)
char *user, *instance, *realm, *service, *sinstance;
int life;
char *password;
{
#if defined(_WIN32) || (defined(USE_LOGIN_LIBRARY) && USE_LOGIN_LIBRARY)
if (password == 0)
return INTK_PW_NULL;
#endif
return(krb_get_in_tkt(user,instance,realm,service,sinstance,life,
(key_proc_type)NULL,
(decrypt_tkt_type)NULL, password));
}
int KRB5_CALLCONV
krb_get_pw_in_tkt_creds(
char *user, char *instance, char *realm, char *service, char *sinstance,
int life, char *password, CREDENTIALS *creds)
{
return krb_get_in_tkt_creds(user, instance, realm,
service, sinstance, life,
(key_proc_type)NULL,
NULL, password, creds);
}
static C_Block old_key;
static int stub_key(user,instance,realm,passwd,key)
char *user, *instance, *realm, *passwd;
C_Block key;
{
(void) memcpy((char *) key, (char *) old_key, sizeof(old_key));
return 0;
}
int KRB5_CALLCONV
krb_get_pw_in_tkt_preauth(user,instance,realm,service,sinstance,life,password)
char *user, *instance, *realm, *service, *sinstance;
int life;
char *password;
{
char *preauth_p;
int preauth_len;
int ret_st;
key_proc_type *keyprocs = krb_get_keyprocs (NULL);
int i = 0;
#if defined(_WIN32) || (defined(USE_LOGIN_LIBRARY) && USE_LOGIN_LIBRARY)
if (password == 0)
return INTK_PW_NULL;
#endif
do {
krb_mk_preauth(&preauth_p, &preauth_len, keyprocs[i],
user, instance, realm, password, old_key);
ret_st = krb_get_in_tkt_preauth(user,instance,realm,service,sinstance,life,
(key_proc_type) stub_key,
(decrypt_tkt_type) NULL, password,
preauth_p, preauth_len);
krb_free_preauth(preauth_p, preauth_len);
} while ((keyprocs[++i] != NULL) && (ret_st == INTK_BADPW));
return ret_st;
}
#ifdef NOENCRYPTION
#include <stdio.h>
#ifdef BSDUNIX
#include <string.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <setjmp.h>
#else
int strcmp();
#endif
#if defined(__svr4__) || defined(__SVR4)
#include <sgtty.h>
#endif
#ifdef BSDUNIX
static jmp_buf env;
#endif
#ifdef BSDUNIX
static void sig_restore();
static push_signals(), pop_signals();
int placebo_read_pw_string();
#endif
int
placebo_read_password(k,prompt,verify)
des_cblock *k;
char *prompt;
int verify;
{
int ok;
char key_string[BUFSIZ];
#ifdef BSDUNIX
if (setjmp(env)) {
ok = -1;
goto lose;
}
#endif
ok = placebo_read_pw_string(key_string, BUFSIZ, prompt, verify);
if (ok == 0)
memset(k, 0, sizeof(C_Block));
lose:
memset(key_string, 0, sizeof (key_string));
return ok;
}
int
placebo_read_pw_string(s,max,prompt,verify)
char *s;
int max;
char *prompt;
int verify;
{
int ok = 0;
char *ptr;
#ifdef BSDUNIX
jmp_buf old_env;
struct sgttyb tty_state;
#endif
char key_string[BUFSIZ];
if (max > BUFSIZ) {
return -1;
}
#ifdef BSDUNIX
memcpy(env, old_env, sizeof(env));
if (setjmp(env))
goto lose;
if (ioctl(0,TIOCGETP,&tty_state) == -1)
return -1;
push_signals();
tty_state.sg_flags &= ~ECHO;
if (ioctl(0,TIOCSETP,&tty_state) == -1)
return -1;
#endif
while (!ok) {
printf(prompt);
fflush(stdout);
#ifdef CROSSMSDOS
h19line(s,sizeof(s),0);
if (!strlen(s))
continue;
#else
if (!fgets(s, max, stdin)) {
clearerr(stdin);
continue;
}
if ((ptr = strchr(s, '\n')))
*ptr = '\0';
#endif
if (verify) {
printf("\nVerifying, please re-enter %s",prompt);
fflush(stdout);
#ifdef CROSSMSDOS
h19line(key_string,sizeof(key_string),0);
if (!strlen(key_string))
continue;
#else
if (!fgets(key_string, sizeof(key_string), stdin)) {
clearerr(stdin);
continue;
}
if ((ptr = strchr(key_string, '\n')))
*ptr = '\0';
#endif
if (strcmp(s,key_string)) {
printf("\n\07\07Mismatch - try again\n");
fflush(stdout);
continue;
}
}
ok = 1;
}
#ifdef BSDUNIX
lose:
if (!ok)
memset(s, 0, max);
printf("\n");
tty_state.sg_flags |= ECHO;
if (ioctl(0,TIOCSETP,&tty_state))
ok = 0;
pop_signals();
memcpy(old_env, env, sizeof(env));
#endif
if (verify)
memset(key_string, 0, sizeof (key_string));
s[max-1] = 0;
return !ok;
}
#ifdef BSDUNIX
static sigtype (*old_sigfunc[NSIG])();
static push_signals()
{
register i;
for (i = 0; i < NSIG; i++)
old_sigfunc[i] = signal(i,sig_restore);
}
static pop_signals()
{
register i;
for (i = 0; i < NSIG; i++)
signal(i,old_sigfunc[i]);
}
static void sig_restore(sig,code,scp)
int sig,code;
struct sigcontext *scp;
{
longjmp(env,1);
}
#endif
#endif