2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)read_password.c 8.3 (Berkeley) 5/30/95
30 * $FreeBSD: src/crypto/telnet/libtelnet/read_password.c,v 1.1.1.1.8.2 2002/04/13 10:59:07 markm Exp $
34 * $Source: /mit/kerberos/src/lib/des/RCS/read_password.c,v $
37 * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
40 * For copying and distribution information, please see the file
43 * This routine prints the supplied string to standard
44 * output as a prompt, and reads a password string without
48 #if defined(RSA_ENCPWD) || defined(KRB4_ENCPWD)
52 #include <sys/ioctl.h>
58 /*** Routines ****************************************************** */
60 * This version just returns the string, doesn't map to key.
62 * Returns 0 on success, non-zero on failure.
66 local_des_read_pw_string(s
,max
,prompt
,verify
)
76 struct sgttyb tty_state
;
77 char key_string
[BUFSIZ
];
83 /* XXX assume jmp_buf is typedef'ed to an array */
84 memmove((char *)env
, (char *)old_env
, sizeof(env
));
88 /* save terminal state*/
89 if (ioctl(0,TIOCGETP
,(char *)&tty_state
) == -1)
95 tty_state
.sg_flags
&= ~ECHO
;
96 if (ioctl(0,TIOCSETP
,(char *)&tty_state
) == -1)
99 (void) printf("%s", prompt
);
100 (void) fflush(stdout
);
101 while (!fgets(s
, max
, stdin
));
103 if ((ptr
= strchr(s
, '\n')))
106 printf("\nVerifying, please re-enter %s",prompt
);
107 (void) fflush(stdout
);
108 if (!fgets(key_string
, sizeof(key_string
), stdin
)) {
112 if ((ptr
= strchr(key_string
, '\n')))
114 if (strcmp(s
,key_string
)) {
115 printf("\n\07\07Mismatch - try again\n");
116 (void) fflush(stdout
);
127 /* turn echo back on */
128 tty_state
.sg_flags
|= ECHO
;
129 if (ioctl(0,TIOCSETP
,(char *)&tty_state
))
134 memmove((char *)old_env
, (char *)env
, sizeof(env
));
136 memset(key_string
, 0, sizeof (key_string
));
137 s
[max
-1] = 0; /* force termination */
138 return !ok
; /* return nonzero if not okay */
140 #endif /* defined(RSA_ENCPWD) || defined(KRB4_ENCPWD) */