From: Theodore Tso Date: Fri, 9 Jun 1995 03:26:30 +0000 (+0000) Subject: read_passwd.c (des_read_pw_string): Don't depend on X-Git-Tag: krb5-1.0-beta6~1812 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f8a33f0c5729b8fbc911c7f7c25c31c8e803c526;p=krb5.git read_passwd.c (des_read_pw_string): Don't depend on krb5_read_password(); this created a circular dependency in the libraries. This code is now duplicated in des_read_pw_string. util.c (des_cblock_print_file): Fix -Wall nit. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5991 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/des425/ChangeLog b/src/lib/des425/ChangeLog index 730fe4124..be5985caf 100644 --- a/src/lib/des425/ChangeLog +++ b/src/lib/des425/ChangeLog @@ -1,3 +1,12 @@ +Thu Jun 8 23:24:20 1995 + + * read_passwd.c (des_read_pw_string): Don't depend on + krb5_read_password(); this created a circular dependency + in the libraries. This code is now duplicated in + des_read_pw_string. + + * util.c (des_cblock_print_file): Fix -Wall nit. + Mon Jun 5 21:02:37 1995 Ezra Peisach (epeisach@kangaroo.mit.edu) * quad_cksum: Convert longs to KRB_INT32 for 64 bit platforms. diff --git a/src/lib/des425/read_passwd.c b/src/lib/des425/read_passwd.c index dd9f4965e..3957e4aff 100644 --- a/src/lib/des425/read_passwd.c +++ b/src/lib/des425/read_passwd.c @@ -28,10 +28,131 @@ */ #include "des.h" +#include +#include +#include +#include +#ifndef ECHO_PASSWORD +#include +#endif /* ECHO_PASSWORD */ + +static jmp_buf pwd_jump; + +static krb5_sigtype +intr_routine() +{ + longjmp(pwd_jump, 1); + /*NOTREACHED*/ +} -static krb5_context krb4_global_context = 0; /*** Routines ****************************************************** */ +krb5_error_code +des_read_pw_string/*_v4_compat_crock*/(return_pwd, bufsize, prompt, prompt2) + char *return_pwd; + int bufsize; + char *prompt; + char *prompt2; +{ + volatile char *readin_string = 0; + register char *ptr; + int scratchchar; + krb5_sigtype (*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, bufsize); + + if (fgets(return_pwd, bufsize, 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(bufsize); + if (!readin_string) { + errcode = ENOMEM; + goto cleanup; + } + (void) memset((char *)readin_string, 0, bufsize); + if (fgets((char *)readin_string, bufsize, 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, bufsize)) { + errcode = KRB5_LIBOS_BADPWDMATCH; + goto cleanup; + } + } + + 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; +} + krb5_error_code des_read_password/*_v4_compat_crock*/(k,prompt,verify) mit_des_cblock *k; @@ -39,23 +160,15 @@ des_read_password/*_v4_compat_crock*/(k,prompt,verify) int verify; { krb5_error_code ok; - krb5_error_code retval; char key_string[BUFSIZ]; char prompt2[BUFSIZ]; - int string_size = sizeof(key_string); - - if (!krb4_global_context) { - retval = krb5_init_context(&krb4_global_context); - if (retval) - return retval; - } if (verify) { strcpy(prompt2, "Verifying, please re-enter "); strncat(prompt2, prompt, sizeof(prompt2)-(strlen(prompt2)+1)); } - ok = krb5_read_password(krb4_global_context, prompt, verify ? prompt2 : 0, - key_string, &string_size); + ok = des_read_pw_string(key_string, sizeof(key_string), + prompt, verify ? prompt2 : 0); if (ok == 0) des_string_to_key(key_string, k); @@ -64,24 +177,3 @@ des_read_password/*_v4_compat_crock*/(k,prompt,verify) return ok; } -krb5_error_code -des_read_pw_string/*_v4_compat_crock*/(buf, bufsize, prompt, prompt2) - char *buf; - int bufsize; - char *prompt; - char *prompt2; -{ - krb5_error_code retval; - int i = bufsize; - - if (!krb4_global_context) { - retval = krb5_init_context(&krb4_global_context); - if (retval) - return retval; - } - - retval = krb5_read_password(krb4_global_context, prompt, prompt2, - buf, &i); - return retval; -} - diff --git a/src/lib/des425/util.c b/src/lib/des425/util.c index 5b2019bd4..1230cf009 100644 --- a/src/lib/des425/util.c +++ b/src/lib/des425/util.c @@ -21,7 +21,7 @@ static char rcsid_util_c[] = #include "k5-int.h" #include "des.h" -des_cblock_print_file(x, fp) +void des_cblock_print_file(x, fp) des_cblock *x; FILE *fp; {