summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-06-25 18:09:16 +1000
committerDamien Miller <djm@mindrot.org>2001-06-25 18:09:16 +1000
commitc8a3868ed0a9c8291c36e79180e18342acd4ed71 (patch)
treea024fd99a20726e12852e34dabaa5a4735202a80
parent2d5ac08f13a8e1f52f00c8ad67f9f03736371cc2 (diff)
- (djm) Bring in readpassphrase() from OpenBSD libc. Compiles OK on Linux and
Solaris
-rw-r--r--ChangeLog4
-rw-r--r--configure.in4
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/openbsd-compat.h3
-rw-r--r--openbsd-compat/readpassphrase.c154
-rw-r--r--openbsd-compat/readpassphrase.h48
-rw-r--r--readpass.c2
7 files changed, 211 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 932d6f757..c07672949 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -105,6 +105,8 @@
105 [ttymodes.c] 105 [ttymodes.c]
106 passing modes works fine: debug2->3 106 passing modes works fine: debug2->3
107 - (djm) -Wall fix for session.c 107 - (djm) -Wall fix for session.c
108 - (djm) Bring in readpassphrase() from OpenBSD libc. Compiles OK on Linux and
109 Solaris
108 110
10920010622 11120010622
110 - (stevesk) handle systems without pw_expire and pw_change. 112 - (stevesk) handle systems without pw_expire and pw_change.
@@ -5789,4 +5791,4 @@
5789 - Wrote replacements for strlcpy and mkdtemp 5791 - Wrote replacements for strlcpy and mkdtemp
5790 - Released 1.0pre1 5792 - Released 1.0pre1
5791 5793
5792$Id: ChangeLog,v 1.1324 2001/06/25 07:07:59 djm Exp $ 5794$Id: ChangeLog,v 1.1325 2001/06/25 08:09:16 djm Exp $
diff --git a/configure.in b/configure.in
index 69d15bb8a..199c1a694 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
1# $Id: configure.in,v 1.291 2001/06/22 21:14:19 stevesk Exp $ 1# $Id: configure.in,v 1.292 2001/06/25 08:09:17 djm Exp $
2 2
3AC_INIT(ssh.c) 3AC_INIT(ssh.c)
4 4
@@ -460,7 +460,7 @@ AC_ARG_WITH(tcp-wrappers,
460) 460)
461 461
462dnl Checks for library functions. 462dnl Checks for library functions.
463AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_sa clock dirname fchown fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent getusershell glob inet_aton inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv setegid seteuid setlogin setproctitle setresgid setreuid setrlimit setsid setvbuf sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf tcgetpgrp utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop) 463AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_sa clock dirname fchown fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent getusershell glob inet_aton inet_ntoa inet_ntop innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty readpassphrase realpath rresvport_af setdtablesize setenv setegid seteuid setlogin setproctitle setresgid setreuid setrlimit setsid setvbuf sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf tcgetpgrp utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop)
464dnl Checks for time functions 464dnl Checks for time functions
465AC_CHECK_FUNCS(gettimeofday time) 465AC_CHECK_FUNCS(gettimeofday time)
466dnl Checks for libutil functions 466dnl Checks for libutil functions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 2cf2774f2..64a089321 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.11 2001/06/10 17:24:52 mouring Exp $ 1# $Id: Makefile.in,v 1.12 2001/06/25 08:09:17 djm Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
16INSTALL=@INSTALL@ 16INSTALL=@INSTALL@
17LDFLAGS=-L. @LDFLAGS@ 17LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getusershell.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtok.o vis.o 19OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getusershell.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtok.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o 21COMPAT=bsd-arc4random.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o
22 22
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 64d8fc5b7..9b8bf35fa 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.7 2001/06/10 17:24:53 mouring Exp $ */ 1/* $Id: openbsd-compat.h,v 1.8 2001/06/25 08:09:17 djm Exp $ */
2 2
3#ifndef _OPENBSD_H 3#ifndef _OPENBSD_H
4#define _OPENBSD_H 4#define _OPENBSD_H
@@ -28,6 +28,7 @@
28#include "getgrouplist.h" 28#include "getgrouplist.h"
29#include "glob.h" 29#include "glob.h"
30#include "getusershell.h" 30#include "getusershell.h"
31#include "readpassphrase.h"
31 32
32/* Home grown routines */ 33/* Home grown routines */
33#include "bsd-arc4random.h" 34#include "bsd-arc4random.h"
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c
new file mode 100644
index 000000000..308e7cc5f
--- /dev/null
+++ b/openbsd-compat/readpassphrase.c
@@ -0,0 +1,154 @@
1/*
2 * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#if defined(LIBC_SCCS) && !defined(lint)
29static char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.4 2001/06/18 17:41:39 millert Exp $";
30#endif /* LIBC_SCCS and not lint */
31
32#include "includes.h"
33
34#ifndef HAVE_READPASSPHRASE
35
36#include <termios.h>
37#include <readpassphrase.h>
38
39#ifdef TCSASOFT
40# define _T_FLUSH (TCSAFLUSH|TCSASOFT)
41#else
42# define _T_FLUSH (TCSAFLUSH)
43#endif
44
45char *
46readpassphrase(prompt, buf, bufsiz, flags)
47 const char *prompt;
48 char *buf;
49 size_t bufsiz;
50 int flags;
51{
52 struct termios term;
53 char ch, *p, *end;
54 u_char status;
55 int echo, input, output;
56 sigset_t oset, nset;
57
58 /* I suppose we could alloc on demand in this case (XXX). */
59 if (bufsiz == 0) {
60 errno = EINVAL;
61 return(NULL);
62 }
63
64 /*
65 * Read and write to /dev/tty if available. If not, read from
66 * stdin and write to stderr unless a tty is required.
67 */
68 if ((input = output = open(_PATH_TTY, O_RDWR)) == -1) {
69 if (flags & RPP_REQUIRE_TTY) {
70 errno = ENOTTY;
71 return(NULL);
72 }
73 input = STDIN_FILENO;
74 output = STDERR_FILENO;
75 }
76
77 /*
78 * We block SIGINT and SIGTSTP so the terminal is not left
79 * in an inconsistent state (ie: no echo). It would probably
80 * be better to simply catch these though.
81 */
82 sigemptyset(&nset);
83 sigaddset(&nset, SIGINT);
84 sigaddset(&nset, SIGTSTP);
85 (void)sigprocmask(SIG_BLOCK, &nset, &oset);
86
87 /* Turn off echo if possible. */
88 echo = 0;
89 status = _POSIX_VDISABLE;
90 if (tcgetattr(input, &term) == 0) {
91 if (!(flags & RPP_ECHO_ON) && (term.c_lflag & ECHO)) {
92 echo = 1;
93 term.c_lflag &= ~ECHO;
94 }
95#ifdef VSTATUS
96 if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) {
97 status = term.c_cc[VSTATUS];
98 term.c_cc[VSTATUS] = _POSIX_VDISABLE;
99 }
100#endif
101 (void)tcsetattr(input, _T_FLUSH, &term);
102 }
103 if (!(flags & RPP_ECHO_ON)) {
104 if (tcgetattr(input, &term) == 0 && (term.c_lflag & ECHO)) {
105 echo = 1;
106 term.c_lflag &= ~ECHO;
107 (void)tcsetattr(input, _T_FLUSH, &term);
108 }
109 }
110
111 (void)write(output, prompt, strlen(prompt));
112 end = buf + bufsiz - 1;
113 for (p = buf; read(input, &ch, 1) == 1 && ch != '\n' && ch != '\r';) {
114 if (p < end) {
115 if ((flags & RPP_SEVENBIT))
116 ch = ch &= 0x7f;
117 if (isalpha(ch)) {
118 if ((flags & RPP_FORCELOWER))
119 ch = tolower(ch);
120 if ((flags & RPP_FORCEUPPER))
121 ch = toupper(ch);
122 }
123 *p++ = ch;
124 }
125 }
126 *p = '\0';
127 if (echo || status != _POSIX_VDISABLE) {
128 if (echo) {
129 (void)write(output, "\n", 1);
130 term.c_lflag |= ECHO;
131 }
132#ifdef VSTATUS
133 if (status != _POSIX_VDISABLE)
134 term.c_cc[VSTATUS] = status;
135#endif
136 (void)tcsetattr(input, _T_FLUSH, &term);
137 }
138 (void)sigprocmask(SIG_SETMASK, &oset, NULL);
139 if (input != STDIN_FILENO)
140 (void)close(input);
141 return(buf);
142}
143#endif /* HAVE_READPASSPHRASE */
144
145#if 0
146char *
147getpass(prompt)
148 const char *prompt;
149{
150 static char buf[_PASSWORD_LEN + 1];
151
152 return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF));
153}
154#endif
diff --git a/openbsd-compat/readpassphrase.h b/openbsd-compat/readpassphrase.h
new file mode 100644
index 000000000..9077b6e08
--- /dev/null
+++ b/openbsd-compat/readpassphrase.h
@@ -0,0 +1,48 @@
1/* $OpenBSD: readpassphrase.h,v 1.1 2000/11/21 00:48:38 millert Exp $ */
2
3/*
4 * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef _READPASSPHRASE_H_
31#define _READPASSPHRASE_H_
32
33#include "includes.h"
34
35#ifndef HAVE_READPASSPHRASE
36
37#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */
38#define RPP_ECHO_ON 0x01 /* Leave echo on. */
39#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */
40#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
41#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
42#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
43
44char *readpassphrase(const char *, char *, size_t, int);
45
46#endif /* HAVE_READPASSPHRASE */
47
48#endif /* !_READPASSPHRASE_H_ */
diff --git a/readpass.c b/readpass.c
index 3b6ed72ba..10171cf67 100644
--- a/readpass.c
+++ b/readpass.c
@@ -34,8 +34,6 @@
34#include "includes.h" 34#include "includes.h"
35RCSID("$OpenBSD: readpass.c,v 1.19 2001/06/24 05:35:33 markus Exp $"); 35RCSID("$OpenBSD: readpass.c,v 1.19 2001/06/24 05:35:33 markus Exp $");
36 36
37#include <readpassphrase.h>
38
39#include "xmalloc.h" 37#include "xmalloc.h"
40#include "readpass.h" 38#include "readpass.h"
41#include "pathnames.h" 39#include "pathnames.h"