|
|
1.1 ! root 1: /* ! 2: * $Source: /usr/src/kerberosIV/des/RCS/read_password.c,v $ ! 3: * $Author: kfall $ ! 4: * ! 5: * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute ! 6: * of Technology. ! 7: * ! 8: * For copying and distribution information, please see the file ! 9: * <mit-copyright.h>. ! 10: * ! 11: * This routine prints the supplied string to standard ! 12: * output as a prompt, and reads a password string without ! 13: * echoing. ! 14: */ ! 15: ! 16: #ifndef lint ! 17: static char rcsid_read_password_c[] = ! 18: "$Header: /usr/src/kerberosIV/des/RCS/read_password.c,v 4.13 90/06/23 03:09:35 kfall Exp $"; ! 19: #endif lint ! 20: ! 21: #include <sys/param.h> ! 22: #include <stdio.h> ! 23: #include <string.h> ! 24: #include <setjmp.h> ! 25: #include <pwd.h> ! 26: #include <mit-copyright.h> ! 27: #include <des.h> ! 28: #include "conf.h" ! 29: ! 30: extern char *getpass(); ! 31: ! 32: #ifdef BSDUNIX ! 33: static jmp_buf env; ! 34: #endif ! 35: ! 36: int ! 37: des_read_password(k, prompt, verify) ! 38: des_cblock *k; ! 39: char *prompt; ! 40: int verify; ! 41: { ! 42: int ok; ! 43: char key_string[_PASSWORD_LEN]; ! 44: ! 45: #ifdef BSDUNIX ! 46: if (setjmp(env)) { ! 47: ok = -1; ! 48: goto lose; ! 49: } ! 50: #endif ! 51: ! 52: ok = des_read_pw_string(key_string, _PASSWORD_LEN, prompt, verify); ! 53: if (ok == 0) ! 54: des_string_to_key(key_string, k); ! 55: ! 56: lose: ! 57: bzero(key_string, sizeof (key_string)); ! 58: return ok; ! 59: } ! 60: ! 61: /* ! 62: * This version just returns the string, doesn't map to key. ! 63: * ! 64: * Returns 0 on success, non-zero on failure. ! 65: */ ! 66: ! 67: int ! 68: des_read_pw_string(s, max, prompt, verify) ! 69: char *s; ! 70: int max; ! 71: char *prompt; ! 72: int verify; ! 73: { ! 74: register int len = MIN(_PASSWORD_LEN, max); ! 75: char *ptr = getpass(prompt); ! 76: ! 77: (void)strncpy(s, ptr, len); ! 78: if (verify) { ! 79: while (strncmp(getpass(prompt), s, len) != 0) { ! 80: printf("\n\07\07Mismatch - try again\n"); ! 81: (void)fflush(stdout); ! 82: continue; ! 83: } ! 84: } ! 85: s[len-1] = '\0'; /* just in case */ ! 86: return 0; ! 87: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.