+2002-10-10 Sam Hartman <hartmans@mit.edu>
+
+ * read_passwd.c : Implement in terms of krb5_prompter_posix
+
2002-09-26 Tom Yu <tlyu@mit.edu>
* cksum.c (des_cbc_cksum): Update API for KfM merge.
#include "des.h"
#include <stdio.h>
#include <errno.h>
-#include <signal.h>
-#include <setjmp.h>
-#ifndef ECHO_PASSWORD
-#include <termios.h>
-#endif /* ECHO_PASSWORD */
-
-static jmp_buf pwd_jump;
-
-static krb5_sigtype intr_routine (int);
-
-static krb5_sigtype
-intr_routine(signo)
- int signo;
-{
- longjmp(pwd_jump, 1);
- /*NOTREACHED*/
-}
-
+#include <krb5.h>
/* This is re-declared here because des.h might not declare it. */
int KRB5_CALLCONV des_read_pw_string(char *, int, char *, int);
static int des_rd_pwstr_2prompt(char *, int, char *, char *);
+
/*** Routines ****************************************************** */
static int
des_rd_pwstr_2prompt(return_pwd, bufsize_in, prompt, prompt2)
char *prompt;
char *prompt2;
{
- char *volatile readin_string = 0;
- register char *ptr;
- int scratchchar;
- krb5_sigtype (*volatile ointrfunc)();
- int errcode;
- size_t bufsize = bufsize_in;
-#ifndef ECHO_PASSWORD
- struct termios echo_control, save_control;
- int fd;
-
- /* get the file descriptor associated with stdin */
- fd=fileno(stdin);
-
- if (tcgetattr(fd, &echo_control) == -1)
- return errno;
-
- save_control = echo_control;
- echo_control.c_lflag &= ~(ECHO|ECHONL);
-
- if (tcsetattr(fd, TCSANOW, &echo_control) == -1)
- return errno;
-#endif /* ECHO_PASSWORD */
-
- if (setjmp(pwd_jump)) {
- errcode = -1; /* we were interrupted... */
- goto cleanup;
- }
- /* save intrfunc */
- ointrfunc = signal(SIGINT, intr_routine);
-
- /* put out the prompt */
- (void) fputs(prompt,stdout);
- (void) fflush(stdout);
- (void) memset(return_pwd, 0, bufsize);
-
- if (fgets(return_pwd, bufsize_in, stdin) == NULL) {
- (void) putchar('\n');
- errcode = -1;
- goto cleanup;
- }
- (void) putchar('\n');
- /* fgets always null-terminates the returned string */
-
- /* replace newline with null */
- if ((ptr = strchr(return_pwd, '\n')))
- *ptr = '\0';
- else /* flush rest of input line */
- do {
- scratchchar = getchar();
- } while (scratchchar != EOF && scratchchar != '\n');
-
- if (prompt2) {
- /* put out the prompt */
- (void) fputs(prompt2,stdout);
- (void) fflush(stdout);
- readin_string = malloc(bufsize);
- if (!readin_string) {
- errcode = ENOMEM;
- goto cleanup;
- }
- (void) memset((char *)readin_string, 0, bufsize);
- if (fgets((char *)readin_string, bufsize_in, stdin) == NULL) {
- (void) putchar('\n');
- errcode = -1;
- goto cleanup;
- }
- (void) putchar('\n');
-
- if ((ptr = strchr((char *)readin_string, '\n')))
- *ptr = '\0';
- else /* need to flush */
- do {
- scratchchar = getchar();
- } while (scratchchar != EOF && scratchchar != '\n');
-
- /* compare */
- if (strncmp(return_pwd, (char *)readin_string, bufsize)) {
- errcode = -1;
- goto cleanup;
+ krb5_data reply_data;
+ krb5_prompt k5prompt;
+ krb5_error_code retval;
+ reply_data.length = bufsize_in;
+ reply_data.data = return_pwd;
+ k5prompt.prompt = prompt;
+ k5prompt.hidden = 1;
+ k5prompt.reply = &reply_data;
+ retval = krb5_prompter_posix(NULL,
+ NULL, NULL, NULL, 1, &k5prompt);
+
+ if ((retval==0) && prompt2) {
+ krb5_data verify_data;
+ verify_data.data = malloc(bufsize_in);
+ verify_data.length = bufsize_in;
+ k5prompt.prompt = prompt2;
+ k5prompt.reply = &verify_data;
+ if (!verify_data.data)
+ return ENOMEM;
+ retval = krb5_prompter_posix(NULL,
+ NULL,NULL, NULL, 1, &k5prompt);
+ if (retval) {
+ free(verify_data.data);
+ } else {
+ /* compare */
+ if (strncmp(return_pwd, (char *)verify_data.data, bufsize_in)) {
+ retval = KRB5_LIBOS_BADPWDMATCH;
+ free(verify_data.data);
+ }
}
}
-
- errcode = 0;
-
-cleanup:
- (void) signal(SIGINT, ointrfunc);
-#ifndef ECHO_PASSWORD
- if ((tcsetattr(fd, TCSANOW, &save_control) == -1) &&
- errcode == 0)
- return errno;
-#endif
- if (readin_string) {
- memset((char *)readin_string, 0, bufsize);
- krb5_xfree(readin_string);
- }
- if (errcode)
- memset(return_pwd, 0, bufsize);
- return errcode;
+ return retval;
}
+
int KRB5_CALLCONV
des_read_password(k,prompt,verify)
mit_des_cblock *k;
+2002-10-10 Sam Hartman <hartmans@mit.edu>
+
+ * read_pwd.c (krb5_read_password): Reimplement in terms of krb5_prompter_posix for unix
+
+
2002-09-26 Ken Raeburn <raeburn@mit.edu>
* sendto_kdc.c (krb5int_cm_call_select): Fix last change.
+
2002-09-19 Ken Raeburn <raeburn@mit.edu>
* sendto_kdc.c (krb5int_cm_call_select): If timeout value has
#include <termios.h>
#endif /* ECHO_PASSWORD */
-static jmp_buf pwd_jump;
-
-static krb5_sigtype
-intr_routine(int signo)
-{
- longjmp(pwd_jump, 1);
- /*NOTREACHED*/
-}
-
krb5_error_code
-krb5_read_password(krb5_context context, const char *prompt, const char *prompt2, char *return_pwd, unsigned int *size_return)
+krb5_read_password(krb5_context context, const char *prompt, const char *prompt2, char *return_pwd, unsigned int *bufsize_in)
{
- /* adapted from Kerberos v4 des/read_password.c */
- /* readin_string is used after a longjmp, so must be volatile */
- char *volatile readin_string = 0;
- register char *ptr;
- int scratchchar;
- krb5_sigtype (*volatile ointrfunc)();
- krb5_error_code errcode;
-#ifndef ECHO_PASSWORD
- struct termios echo_control, save_control;
- int fd;
-
- /* get the file descriptor associated with stdin */
- fd=fileno(stdin);
-
- if (tcgetattr(fd, &echo_control) == -1)
- return errno;
-
- save_control = echo_control;
- echo_control.c_lflag &= ~(ECHO|ECHONL);
-
- if (tcsetattr(fd, TCSANOW, &echo_control) == -1)
- return errno;
-#endif /* ECHO_PASSWORD */
-
- if (setjmp(pwd_jump)) {
- errcode = KRB5_LIBOS_PWDINTR; /* we were interrupted... */
- goto cleanup;
- }
- /* save intrfunc */
- ointrfunc = signal(SIGINT, intr_routine);
-
- /* put out the prompt */
- (void) fputs(prompt,stdout);
- (void) fflush(stdout);
- (void) memset(return_pwd, 0, *size_return);
-
- if (fgets(return_pwd, (int) *size_return, stdin) == NULL) {
- (void) putchar('\n');
- errcode = KRB5_LIBOS_CANTREADPWD;
- goto cleanup;
- }
- (void) putchar('\n');
- /* fgets always null-terminates the returned string */
-
- /* replace newline with null */
- if ((ptr = strchr(return_pwd, '\n')))
- *ptr = '\0';
- else /* flush rest of input line */
- do {
- scratchchar = getchar();
- } while (scratchchar != EOF && scratchchar != '\n');
-
- if (prompt2) {
- /* put out the prompt */
- (void) fputs(prompt2,stdout);
- (void) fflush(stdout);
- readin_string = malloc(*size_return);
- if (!readin_string) {
- errcode = ENOMEM;
- goto cleanup;
- }
- (void) memset((char *)readin_string, 0, *size_return);
- if (fgets((char *)readin_string, (int) *size_return, stdin) == NULL) {
- (void) putchar('\n');
- errcode = KRB5_LIBOS_CANTREADPWD;
- goto cleanup;
- }
- (void) putchar('\n');
-
- if ((ptr = strchr((char *)readin_string, '\n')))
- *ptr = '\0';
- else /* need to flush */
- do {
- scratchchar = getchar();
- } while (scratchchar != EOF && scratchchar != '\n');
-
- /* compare */
- if (strncmp(return_pwd, (char *)readin_string, *size_return)) {
- errcode = KRB5_LIBOS_BADPWDMATCH;
- goto cleanup;
+ krb5_data reply_data;
+ krb5_prompt k5prompt;
+ krb5_error_code retval;
+ reply_data.length = *bufsize_in;
+ reply_data.data = return_pwd;
+ k5prompt.prompt = (const char *) prompt;
+ k5prompt.hidden = 1;
+ k5prompt.reply = &reply_data;
+ retval = krb5_prompter_posix(NULL,
+ NULL, NULL, NULL, 1, &k5prompt);
+
+ if ((retval==0) && prompt2) {
+ krb5_data verify_data;
+ verify_data.data = malloc(*bufsize_in);
+ verify_data.length = *bufsize_in;
+ k5prompt.prompt = (const char *) prompt2;
+ k5prompt.reply = &verify_data;
+ if (!verify_data.data)
+ return ENOMEM;
+ retval = krb5_prompter_posix(NULL,
+ NULL,NULL, NULL, 1, &k5prompt);
+ if (retval) {
+ free(verify_data.data);
+ } else {
+ /* compare */
+ if (strncmp(return_pwd, (char *)verify_data.data, *bufsize_in)) {
+ retval = KRB5_LIBOS_BADPWDMATCH;
+ free(verify_data.data);
+ }
}
}
-
- errcode = 0;
-
-cleanup:
- (void) signal(SIGINT, ointrfunc);
-#ifndef ECHO_PASSWORD
- if ((tcsetattr(fd, TCSANOW, &save_control) == -1) &&
- errcode == 0)
- return errno;
-#endif
- if (readin_string) {
- memset((char *)readin_string, 0, *size_return);
- krb5_xfree(readin_string);
- }
- if (errcode)
- memset(return_pwd, 0, *size_return);
- else
- *size_return = strlen(return_pwd);
- return errcode;
+ return retval;
}
#endif