summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Makefile.in4
-rw-r--r--cli.c233
-rw-r--r--cli.h42
4 files changed, 4 insertions, 278 deletions
diff --git a/ChangeLog b/ChangeLog
index 51d777517..2ad013f0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
4 - (bal) Updated zlib's home. Thanks to David Howe <DaveHowe@gmx.co.uk>. 4 - (bal) Updated zlib's home. Thanks to David Howe <DaveHowe@gmx.co.uk>.
5 - (stevesk) remove _REENTRANT #define 5 - (stevesk) remove _REENTRANT #define
6 - (stevesk) session.c: use u_int for envsize 6 - (stevesk) session.c: use u_int for envsize
7 - (stevesk) remove cli.[ch]
7 8
820010628 920010628
9 - (djm) Sync openbsd-compat with -current libc 10 - (djm) Sync openbsd-compat with -current libc
@@ -5823,4 +5824,4 @@
5823 - Wrote replacements for strlcpy and mkdtemp 5824 - Wrote replacements for strlcpy and mkdtemp
5824 - Released 1.0pre1 5825 - Released 1.0pre1
5825 5826
5826$Id: ChangeLog,v 1.1343 2001/06/29 17:52:18 stevesk Exp $ 5827$Id: ChangeLog,v 1.1344 2001/06/29 19:51:48 stevesk Exp $
diff --git a/Makefile.in b/Makefile.in
index ac8b94a4e..1ec12691e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.179 2001/06/28 10:23:15 djm Exp $ 1# $Id: Makefile.in,v 1.180 2001/06/29 19:51:49 stevesk Exp $
2 2
3prefix=@prefix@ 3prefix=@prefix@
4exec_prefix=@exec_prefix@ 4exec_prefix=@exec_prefix@
@@ -45,7 +45,7 @@ INSTALL_SSH_PRNG_CMDS=@INSTALL_SSH_PRNG_CMDS@
45 45
46TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) $(SFTP_PROGS) 46TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) $(SFTP_PROGS)
47 47
48LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o deattack.o dh.o dispatch.o mac.o hostfile.o key.o kex.o kexdh.o kexgex.o log.o match.o misc.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o uuencode.o xmalloc.o 48LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o compat.o compress.o crc32.o deattack.o dh.o dispatch.o mac.o hostfile.o key.o kex.o kexdh.o kexgex.o log.o match.o misc.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o uuencode.o xmalloc.o
49 49
50SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o sshtty.o readconf.o clientloop.o 50SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o sshtty.o readconf.o clientloop.o
51 51
diff --git a/cli.c b/cli.c
deleted file mode 100644
index 6a5825690..000000000
--- a/cli.c
+++ /dev/null
@@ -1,233 +0,0 @@
1/* $OpenBSD: cli.c,v 1.13 2001/05/06 21:23:31 markus Exp $ */
2
3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "includes.h"
28RCSID("$OpenBSD: cli.c,v 1.13 2001/05/06 21:23:31 markus Exp $");
29
30#include "xmalloc.h"
31#include "log.h"
32#include "cli.h"
33
34static int cli_input = -1;
35static int cli_output = -1;
36static int cli_from_stdin = 0;
37
38sigset_t oset;
39sigset_t nset;
40struct sigaction nsa;
41struct sigaction osa;
42struct termios ntio;
43struct termios otio;
44int echo_modified;
45
46volatile int intr;
47
48static int
49cli_open(int from_stdin)
50{
51 if (cli_input >= 0 && cli_output >= 0 && cli_from_stdin == from_stdin)
52 return 1;
53
54 if (from_stdin) {
55 if (!cli_from_stdin && cli_input >= 0) {
56 (void)close(cli_input);
57 }
58 cli_input = STDIN_FILENO;
59 cli_output = STDERR_FILENO;
60 } else {
61 cli_input = cli_output = open(_PATH_TTY, O_RDWR);
62 if (cli_input < 0)
63 fatal("You have no controlling tty. Cannot read passphrase.");
64 }
65
66 cli_from_stdin = from_stdin;
67
68 return cli_input >= 0 && cli_output >= 0 && cli_from_stdin == from_stdin;
69}
70
71static void
72cli_close(void)
73{
74 if (!cli_from_stdin && cli_input >= 0)
75 close(cli_input);
76 cli_input = -1;
77 cli_output = -1;
78 cli_from_stdin = 0;
79 return;
80}
81
82void
83intrcatch(int sig)
84{
85 intr = 1;
86}
87
88static void
89cli_echo_disable(void)
90{
91 sigemptyset(&nset);
92 sigaddset(&nset, SIGTSTP);
93 (void) sigprocmask(SIG_BLOCK, &nset, &oset);
94
95 intr = 0;
96
97 memset(&nsa, 0, sizeof(nsa));
98 nsa.sa_handler = intrcatch;
99 (void) sigaction(SIGINT, &nsa, &osa);
100
101 echo_modified = 0;
102 if (tcgetattr(cli_input, &otio) == 0 && (otio.c_lflag & ECHO)) {
103 echo_modified = 1;
104 ntio = otio;
105 ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
106 (void) tcsetattr(cli_input, TCSANOW, &ntio);
107 }
108 return;
109}
110
111static void
112cli_echo_restore(void)
113{
114 if (echo_modified != 0) {
115 tcsetattr(cli_input, TCSANOW, &otio);
116 echo_modified = 0;
117 }
118
119 (void) sigprocmask(SIG_SETMASK, &oset, NULL);
120 (void) sigaction(SIGINT, &osa, NULL);
121
122 if (intr != 0) {
123 kill(getpid(), SIGINT);
124 sigemptyset(&nset);
125 /* XXX tty has not neccessarily drained by now? */
126 sigsuspend(&nset);
127 intr = 0;
128 }
129 return;
130}
131
132static int
133cli_read(char* buf, int size, int echo)
134{
135 char ch = 0;
136 int i = 0;
137 int n;
138
139 if (!echo)
140 cli_echo_disable();
141
142 while (ch != '\n') {
143 n = read(cli_input, &ch, 1);
144 if (intr)
145 break;
146 if (n == -1 && (errno == EAGAIN || errno == EINTR))
147 continue;
148 if (n != 1)
149 break;
150 if (ch == '\n')
151 break;
152 if (i < size - 1)
153 buf[i++] = ch;
154 }
155 if (intr)
156 i = 0;
157 buf[i] = '\0';
158
159 if (!echo)
160 cli_echo_restore();
161 if (!intr && !echo)
162 (void) write(cli_output, "\n", 1);
163 return i;
164}
165
166static int
167cli_write(const char* buf, int size)
168{
169 int i, len, pos, ret = 0;
170 char *output, *p;
171
172 output = xmalloc(4*size);
173 for (p = output, i = 0; i < size; i++) {
174 if (buf[i] == '\n' || buf[i] == '\r')
175 *p++ = buf[i];
176 else
177 p = vis(p, buf[i], 0, 0);
178 }
179 len = p - output;
180
181 for (pos = 0; pos < len; pos += ret) {
182 ret = write(cli_output, output + pos, len - pos);
183 if (ret == -1) {
184 xfree(output);
185 return -1;
186 }
187 }
188 xfree(output);
189 return 0;
190}
191
192/*
193 * Presents a prompt and returns the response allocated with xmalloc().
194 * Uses /dev/tty or stdin/out depending on arg. Optionally disables echo
195 * of response depending on arg. Tries to ensure that no other userland
196 * buffer is storing the response.
197 */
198char*
199cli_read_passphrase(const char* prompt, int from_stdin, int echo_enable)
200{
201 char buf[BUFSIZ];
202 char* p;
203
204 if (!cli_open(from_stdin))
205 fatal("Cannot read passphrase.");
206
207 fflush(stdout);
208
209 cli_write(prompt, strlen(prompt));
210 cli_read(buf, sizeof buf, echo_enable);
211
212 cli_close();
213
214 p = xstrdup(buf);
215 memset(buf, 0, sizeof(buf));
216 return (p);
217}
218
219char*
220cli_prompt(char* prompt, int echo_enable)
221{
222 return cli_read_passphrase(prompt, 0, echo_enable);
223}
224
225void
226cli_mesg(char* mesg)
227{
228 cli_open(0);
229 cli_write(mesg, strlen(mesg));
230 cli_write("\n", strlen("\n"));
231 cli_close();
232 return;
233}
diff --git a/cli.h b/cli.h
deleted file mode 100644
index e8f92e900..000000000
--- a/cli.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/* $OpenBSD: cli.h,v 1.5 2001/05/06 17:52:07 mouring Exp $ */
2
3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27/* $OpenBSD: cli.h,v 1.5 2001/05/06 17:52:07 mouring Exp $ */
28
29#ifndef CLI_H
30#define CLI_H
31
32/*
33 * Presents a prompt and returns the response allocated with xmalloc().
34 * Uses /dev/tty or stdin/out depending on arg. Optionally disables echo
35 * of response depending on arg. Tries to ensure that no other userland
36 * buffer is storing the response.
37 */
38char* cli_read_passphrase(const char* prompt, int from_stdin, int echo_enable);
39char* cli_prompt(char* prompt, int echo_enable);
40void cli_mesg(char* mesg);
41
42#endif /* CLI_H */