diff options
| author | John Kohl <jtkohl@mit.edu> | 1990-01-18 12:19:34 +0000 |
|---|---|---|
| committer | John Kohl <jtkohl@mit.edu> | 1990-01-18 12:19:34 +0000 |
| commit | 9de5449c25fb3a604ba2a1eddb1fb042964807ee (patch) | |
| tree | fd431283b20e746db0fd7a5120c2e9dfd463380b /src/lib | |
| parent | e1efe3707f94b3f1ec5ecbb5da338e34ca68b119 (diff) | |
| download | krb5-9de5449c25fb3a604ba2a1eddb1fb042964807ee.tar.gz krb5-9de5449c25fb3a604ba2a1eddb1fb042964807ee.tar.xz krb5-9de5449c25fb3a604ba2a1eddb1fb042964807ee.zip | |
*** empty log message ***
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@117 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/krb5/os/read_pwd.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/lib/krb5/os/read_pwd.c b/src/lib/krb5/os/read_pwd.c new file mode 100644 index 000000000..4437cfcf9 --- /dev/null +++ b/src/lib/krb5/os/read_pwd.c @@ -0,0 +1,120 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * <krb5/mit-copyright.h>. + * + * libos: krb5_read_password for BSD 4.3 + */ + +#ifndef lint +static char rcsid_read_pwd_c[] = +"$Id$"; +#endif lint + +#include <krb5/copyright.h> + +#include <krb5/krb5.h> +#include <krb5/krb5_err.h> + +#include <sys/ioctl.h> +#include <stdio.h> +#include <errno.h> + +#ifdef __STDC__ +#include <stdlib.h> +#else +char *malloc(), *index(); +#endif + +extern int errno; + +#define cleanup(errcode) ioctl(0, TIOCSETP, (char *)&tty_savestate); return errcode; + +krb5_error_code +krb5_read_password(prompt, prompt2, return_pwd, size_return) +char *prompt; +char *prompt2; +char *return_pwd; +int size_return; +{ + /* adapted from Kerberos v4 des/read_password.c */ + + struct sgttyb tty_state, tty_savestate; + char *readin_string; + register char *ptr; + int scratchchar; + + /* save terminal state */ + if (ioctl(0,TIOCGETP,(char *)&tty_savestate) == -1) + return errno; + + tty_state = tty_savestate; + + tty_state.sg_flags &= ~ECHO; + if (ioctl(0,TIOCSETP,(char *)&tty_state) == -1) + return errno; + + /* put out the prompt */ + (void) fputs(prompt,stdout); + (void) fflush(stdout); + (void) bzero(return_pwd, size_return); + + if (fgets(return_pwd, size_return, stdin) == NULL) { + /* error */ + (void) bzero(return_pwd, size_return); + cleanup(KRB5_LIBOS_CANTREADPWD); + } + /* fgets always null-terminates the returned string */ + + /* replace newline with null */ + if (ptr = index(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) putchar('\n'); + (void) fputs(prompt2,stdout); + (void) fflush(stdout); + readin_string = malloc(size_return); + if (!readin_string) { + (void) bzero(return_pwd, size_return); + cleanup(ENOMEM); + } + (void) bzero(readin_string, size_return); + if (fgets(readin_string, size_return, stdin) == NULL) { + /* error */ + (void) bzero(readin_string, size_return); + (void) bzero(return_pwd, size_return); + free(readin_string); + cleanup(KRB5_LIBOS_CANTREADPWD); + } + if (ptr = index(readin_string, '\n')) + *ptr = '\0'; + else /* need to flush */ + do { + scratchchar = getchar(); + } while (scratchchar != EOF && scratchchar != '\n'); + /* compare */ + if (strncmp(return_pwd, readin_string, size_return)) { + (void) bzero(readin_string, size_return); + (void) bzero(return_pwd, size_return); + free(readin_string); + cleanup(KRB5_LIBOS_BADPWDMATCH); + } + (void) bzero(readin_string, size_return); + free(readin_string); + } + + if (ioctl(0, TIOCSETP, (char *)&tty_savestate) == -1) + return errno; + + return 0; +} |
