summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1999-12-06 20:15:39 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1999-12-06 20:15:39 +0000
commit89a8fda5c250e1bd4af3c903ea59254c515fc537 (patch)
treef433d31ed590e4e10bafa7385ebc4a1ab61f13e6
parentcbd4eb763a28ef99d702989aeb0d801be74c89a6 (diff)
move atomicio into it's own file. wrap all socket write()s which were doing
write(sock, buf, len) != len, with atomicio() calls.
-rw-r--r--usr.bin/ssh/atomicio.c57
-rw-r--r--usr.bin/ssh/authfd.c24
-rw-r--r--usr.bin/ssh/clientloop.c20
-rw-r--r--usr.bin/ssh/scp.c28
-rw-r--r--usr.bin/ssh/scp/Makefile2
-rw-r--r--usr.bin/ssh/serverloop.c6
-rw-r--r--usr.bin/ssh/ssh-add/Makefile2
-rw-r--r--usr.bin/ssh/ssh.h9
-rw-r--r--usr.bin/ssh/ssh/Makefile2
-rw-r--r--usr.bin/ssh/sshconnect.c19
-rw-r--r--usr.bin/ssh/sshd.c16
-rw-r--r--usr.bin/ssh/sshd/Makefile2
12 files changed, 113 insertions, 74 deletions
diff --git a/usr.bin/ssh/atomicio.c b/usr.bin/ssh/atomicio.c
new file mode 100644
index 00000000000..1a6d116d835
--- /dev/null
+++ b/usr.bin/ssh/atomicio.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1999 Theo de Raadt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "includes.h"
+RCSID("$Id: atomicio.c,v 1.1 1999/12/06 20:15:25 deraadt Exp $");
+
+#include "xmalloc.h"
+#include "ssh.h"
+
+/*
+ * ensure all of data on socket comes through. f==read || f==write
+ */
+int
+atomicio(f, fd, s, n)
+ int (*f) ();
+ int fd;
+ void *s;
+ size_t n;
+{
+ int res, pos = 0;
+
+ while (n > pos) {
+ res = (f) (fd, s + pos, n - pos);
+ switch (res) {
+ case -1:
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ case 0:
+ return (res);
+ default:
+ pos += res;
+ }
+ }
+ return (pos);
+}
diff --git a/usr.bin/ssh/authfd.c b/usr.bin/ssh/authfd.c
index 0e65f50e3cd..ae7e47c9dd5 100644
--- a/usr.bin/ssh/authfd.c
+++ b/usr.bin/ssh/authfd.c
@@ -14,7 +14,7 @@
*/
#include "includes.h"
-RCSID("$Id: authfd.c,v 1.14 1999/11/24 19:53:44 markus Exp $");
+RCSID("$Id: authfd.c,v 1.15 1999/12/06 20:15:26 deraadt Exp $");
#include "ssh.h"
#include "rsa.h"
@@ -140,7 +140,7 @@ ssh_get_first_identity(AuthenticationConnection *auth,
msg[2] = 0;
msg[3] = 1;
msg[4] = SSH_AGENTC_REQUEST_RSA_IDENTITIES;
- if (write(auth->fd, msg, 5) != 5) {
+ if (atomicio(write, auth->fd, msg, 5) != 5) {
error("write auth->fd: %.100s", strerror(errno));
return 0;
}
@@ -265,9 +265,9 @@ ssh_decrypt_challenge(AuthenticationConnection *auth,
PUT_32BIT(buf, len);
/* Send the length and then the packet to the agent. */
- if (write(auth->fd, buf, 4) != 4 ||
- write(auth->fd, buffer_ptr(&buffer), buffer_len(&buffer)) !=
- buffer_len(&buffer)) {
+ if (atomicio(write, auth->fd, buf, 4) != 4 ||
+ atomicio(write, auth->fd, buffer_ptr(&buffer),
+ buffer_len(&buffer)) != buffer_len(&buffer)) {
error("Error writing to authentication socket.");
error_cleanup:
buffer_free(&buffer);
@@ -364,9 +364,9 @@ ssh_add_identity(AuthenticationConnection *auth,
PUT_32BIT(buf, len);
/* Send the length and then the packet to the agent. */
- if (write(auth->fd, buf, 4) != 4 ||
- write(auth->fd, buffer_ptr(&buffer), buffer_len(&buffer)) !=
- buffer_len(&buffer)) {
+ if (atomicio(write, auth->fd, buf, 4) != 4 ||
+ atomicio(write, auth->fd, buffer_ptr(&buffer),
+ buffer_len(&buffer)) != buffer_len(&buffer)) {
error("Error writing to authentication socket.");
error_cleanup:
buffer_free(&buffer);
@@ -445,9 +445,9 @@ ssh_remove_identity(AuthenticationConnection *auth, RSA *key)
PUT_32BIT(buf, len);
/* Send the length and then the packet to the agent. */
- if (write(auth->fd, buf, 4) != 4 ||
- write(auth->fd, buffer_ptr(&buffer), buffer_len(&buffer)) !=
- buffer_len(&buffer)) {
+ if (atomicio(write, auth->fd, buf, 4) != 4 ||
+ atomicio(write, auth->fd, buffer_ptr(&buffer),
+ buffer_len(&buffer)) != buffer_len(&buffer)) {
error("Error writing to authentication socket.");
error_cleanup:
buffer_free(&buffer);
@@ -521,7 +521,7 @@ ssh_remove_all_identities(AuthenticationConnection *auth)
buf[4] = SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES;
/* Send the length and then the packet to the agent. */
- if (write(auth->fd, buf, 5) != 5) {
+ if (atomicio(write, auth->fd, buf, 5) != 5) {
error("Error writing to authentication socket.");
return 0;
}
diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c
index e12110daf38..59dad3d7d30 100644
--- a/usr.bin/ssh/clientloop.c
+++ b/usr.bin/ssh/clientloop.c
@@ -15,7 +15,7 @@
*/
#include "includes.h"
-RCSID("$Id: clientloop.c,v 1.13 1999/11/24 19:53:46 markus Exp $");
+RCSID("$Id: clientloop.c,v 1.14 1999/12/06 20:15:26 deraadt Exp $");
#include "xmalloc.h"
#include "ssh.h"
@@ -466,13 +466,11 @@ client_suspend_self()
/* Flush stdout and stderr buffers. */
if (buffer_len(&stdout_buffer) > 0)
- write(fileno(stdout),
- buffer_ptr(&stdout_buffer),
- buffer_len(&stdout_buffer));
+ atomicio(write, fileno(stdout), buffer_ptr(&stdout_buffer),
+ buffer_len(&stdout_buffer));
if (buffer_len(&stderr_buffer) > 0)
- write(fileno(stderr),
- buffer_ptr(&stderr_buffer),
- buffer_len(&stderr_buffer));
+ atomicio(write, fileno(stderr), buffer_ptr(&stderr_buffer),
+ buffer_len(&stderr_buffer));
leave_raw_mode();
@@ -739,7 +737,7 @@ client_process_output(fd_set * writeset)
if (FD_ISSET(fileno(stdout), writeset)) {
/* Write as much data as possible. */
len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
- buffer_len(&stdout_buffer));
+ buffer_len(&stdout_buffer));
if (len <= 0) {
if (errno == EAGAIN)
len = 0;
@@ -762,7 +760,7 @@ client_process_output(fd_set * writeset)
if (FD_ISSET(fileno(stderr), writeset)) {
/* Write as much data as possible. */
len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
- buffer_len(&stderr_buffer));
+ buffer_len(&stderr_buffer));
if (len <= 0) {
if (errno == EAGAIN)
len = 0;
@@ -911,7 +909,7 @@ client_loop(int have_pty, int escape_char_arg)
/* Output any buffered data for stdout. */
while (buffer_len(&stdout_buffer) > 0) {
len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
- buffer_len(&stdout_buffer));
+ buffer_len(&stdout_buffer));
if (len <= 0) {
error("Write failed flushing stdout buffer.");
break;
@@ -922,7 +920,7 @@ client_loop(int have_pty, int escape_char_arg)
/* Output any buffered data for stderr. */
while (buffer_len(&stderr_buffer) > 0) {
len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
- buffer_len(&stderr_buffer));
+ buffer_len(&stderr_buffer));
if (len <= 0) {
error("Write failed flushing stderr buffer.");
break;
diff --git a/usr.bin/ssh/scp.c b/usr.bin/ssh/scp.c
index 39a371dfcfc..51cb2eb5409 100644
--- a/usr.bin/ssh/scp.c
+++ b/usr.bin/ssh/scp.c
@@ -45,7 +45,7 @@
*/
#include "includes.h"
-RCSID("$Id: scp.c,v 1.21 1999/11/24 20:26:35 markus Exp $");
+RCSID("$Id: scp.c,v 1.22 1999/12/06 20:15:28 deraadt Exp $");
#include "ssh.h"
#include "xmalloc.h"
@@ -974,7 +974,7 @@ run_err(const char *fmt,...)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: scp.c,v 1.21 1999/11/24 20:26:35 markus Exp $
+ * $Id: scp.c,v 1.22 1999/12/06 20:15:28 deraadt Exp $
*/
char *
@@ -1065,30 +1065,6 @@ lostconn(signo)
exit(1);
}
-/*
- * ensure all of data on socket comes through. f==read || f==write
- */
-int
-atomicio(f, fd, s, n)
- int (*f) ();
- char *s;
-{
- int res, pos = 0;
-
- while (n > pos) {
- res = (f) (fd, s + pos, n - pos);
- switch (res) {
- case -1:
- if (errno == EINTR || errno == EAGAIN)
- continue;
- case 0:
- return (res);
- default:
- pos += res;
- }
- }
- return (pos);
-}
void
alarmtimer(int wait)
diff --git a/usr.bin/ssh/scp/Makefile b/usr.bin/ssh/scp/Makefile
index 3f59a9fd153..a34681a129a 100644
--- a/usr.bin/ssh/scp/Makefile
+++ b/usr.bin/ssh/scp/Makefile
@@ -13,6 +13,6 @@ BINMODE?=555
BINDIR= /usr/bin
MAN= scp.1
-SRCS= scp.c
+SRCS= scp.c atomicio.c
.include <bsd.prog.mk>
diff --git a/usr.bin/ssh/serverloop.c b/usr.bin/ssh/serverloop.c
index 94c2115710d..a5ecfe97d5d 100644
--- a/usr.bin/ssh/serverloop.c
+++ b/usr.bin/ssh/serverloop.c
@@ -170,7 +170,7 @@ make_packets_from_stderr_data()
/* Send buffered stderr data to the client. */
while (buffer_len(&stderr_buffer) > 0 &&
- packet_not_very_much_data_to_write()) {
+ packet_not_very_much_data_to_write()) {
len = buffer_len(&stderr_buffer);
if (packet_is_interactive()) {
if (len > 512)
@@ -199,7 +199,7 @@ make_packets_from_stdout_data()
/* Send buffered stdout data to the client. */
while (buffer_len(&stdout_buffer) > 0 &&
- packet_not_very_much_data_to_write()) {
+ packet_not_very_much_data_to_write()) {
len = buffer_len(&stdout_buffer);
if (packet_is_interactive()) {
if (len > 512)
@@ -364,7 +364,7 @@ process_output(fd_set * writeset)
/* Write buffered data to program stdin. */
if (fdin != -1 && FD_ISSET(fdin, writeset)) {
len = write(fdin, buffer_ptr(&stdin_buffer),
- buffer_len(&stdin_buffer));
+ buffer_len(&stdin_buffer));
if (len <= 0) {
#ifdef USE_PIPES
close(fdin);
diff --git a/usr.bin/ssh/ssh-add/Makefile b/usr.bin/ssh/ssh-add/Makefile
index 5451e7d31b9..2647867fafd 100644
--- a/usr.bin/ssh/ssh-add/Makefile
+++ b/usr.bin/ssh/ssh-add/Makefile
@@ -13,7 +13,7 @@ BINMODE?=555
BINDIR= /usr/bin
MAN= ssh-add.1
-SRCS= ssh-add.c log-client.c
+SRCS= ssh-add.c log-client.c atomicio.c
.include <bsd.prog.mk>
diff --git a/usr.bin/ssh/ssh.h b/usr.bin/ssh/ssh.h
index ba7de195013..241f0b930ff 100644
--- a/usr.bin/ssh/ssh.h
+++ b/usr.bin/ssh/ssh.h
@@ -13,7 +13,7 @@
*
*/
-/* RCSID("$Id: ssh.h,v 1.29 1999/12/02 20:05:40 markus Exp $"); */
+/* RCSID("$Id: ssh.h,v 1.30 1999/12/06 20:15:29 deraadt Exp $"); */
#ifndef SSH_H
#define SSH_H
@@ -681,9 +681,14 @@ struct envstring {
struct envstring *next;
char *s;
};
+
+/*
+ * Ensure all of data on socket comes through. f==read || f==write
+ */
+int atomicio(int (*f)(), int fd, void *s, size_t n);
+
#ifdef KRB4
#include <krb.h>
-
/*
* Performs Kerberos v4 mutual authentication with the client. This returns 0
* if the client could not be authenticated, and 1 if authentication was
diff --git a/usr.bin/ssh/ssh/Makefile b/usr.bin/ssh/ssh/Makefile
index 61a38add711..989e92eaa7d 100644
--- a/usr.bin/ssh/ssh/Makefile
+++ b/usr.bin/ssh/ssh/Makefile
@@ -15,7 +15,7 @@ MAN= ssh.1
LINKS= ${BINDIR}/ssh ${BINDIR}/slogin
MLINKS= ssh.1 slogin.1
-SRCS= ssh.c sshconnect.c log-client.c readconf.c clientloop.c
+SRCS= ssh.c sshconnect.c log-client.c readconf.c clientloop.c atomicio.c
.include <bsd.own.mk> # for AFS
diff --git a/usr.bin/ssh/sshconnect.c b/usr.bin/ssh/sshconnect.c
index abf4d1fc16d..e7c78843250 100644
--- a/usr.bin/ssh/sshconnect.c
+++ b/usr.bin/ssh/sshconnect.c
@@ -8,7 +8,7 @@
*/
#include "includes.h"
-RCSID("$Id: sshconnect.c,v 1.44 1999/12/01 16:51:19 markus Exp $");
+RCSID("$Id: sshconnect.c,v 1.45 1999/12/06 20:15:30 deraadt Exp $");
#include <ssl/bn.h>
#include "xmalloc.h"
@@ -531,7 +531,7 @@ try_rsa_authentication(const char *authfile)
if (!load_private_key(authfile, "", private_key, NULL)) {
char buf[300];
snprintf(buf, sizeof buf, "Enter passphrase for RSA key '%.100s': ",
- comment);
+ comment);
if (!options.batch_mode)
passphrase = read_passphrase(buf, 0);
else {
@@ -1030,8 +1030,8 @@ ssh_exchange_identification()
/* Send our own protocol version identification. */
snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n",
- PROTOCOL_MAJOR, PROTOCOL_MINOR, SSH_VERSION);
- if (write(connection_out, buf, strlen(buf)) != strlen(buf))
+ PROTOCOL_MAJOR, PROTOCOL_MINOR, SSH_VERSION);
+ if (atomicio(write, connection_out, buf, strlen(buf)) != strlen(buf))
fatal("write: %.100s", strerror(errno));
}
@@ -1286,10 +1286,10 @@ ssh_login(int host_key_valid,
char prompt[1024];
char *fp = fingerprint(host_key->e, host_key->n);
snprintf(prompt, sizeof(prompt),
- "The authenticity of host '%.200s' can't be established.\n"
- "Key fingerprint is %d %s.\n"
- "Are you sure you want to continue connecting (yes/no)? ",
- host, BN_num_bits(host_key->n), fp);
+ "The authenticity of host '%.200s' can't be established.\n"
+ "Key fingerprint is %d %s.\n"
+ "Are you sure you want to continue connecting (yes/no)? ",
+ host, BN_num_bits(host_key->n), fp);
if (!read_yes_or_no(prompt, -1))
fatal("Aborted by user!\n");
}
@@ -1593,8 +1593,9 @@ ssh_login(int host_key_valid,
if ((supported_authentications & (1 << SSH_AUTH_PASSWORD)) &&
options.password_authentication && !options.batch_mode) {
char prompt[80];
+
snprintf(prompt, sizeof(prompt), "%.30s@%.40s's password: ",
- server_user, host);
+ server_user, host);
if (try_password_authentication(prompt))
return;
}
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index 90a3a8c7105..9c933d4422e 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -11,7 +11,7 @@
*/
#include "includes.h"
-RCSID("$Id: sshd.c,v 1.67 1999/12/06 12:10:12 deraadt Exp $");
+RCSID("$Id: sshd.c,v 1.68 1999/12/06 20:15:30 deraadt Exp $");
#include "xmalloc.h"
#include "rsa.h"
@@ -684,7 +684,7 @@ main(int ac, char **av)
/* Send our protocol version identification. */
snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n",
PROTOCOL_MAJOR, PROTOCOL_MINOR, SSH_VERSION);
- if (write(sock_out, buf, strlen(buf)) != strlen(buf))
+ if (atomicio(write, sock_out, buf, strlen(buf)) != strlen(buf))
fatal("Could not write ident string to %s.", get_remote_ipaddr());
/* Read other side\'s version identification. */
@@ -710,9 +710,10 @@ main(int ac, char **av)
* several versions and set appropriate flags to handle them.
*/
if (sscanf(buf, "SSH-%d.%d-%[^\n]\n", &remote_major, &remote_minor,
- remote_version) != 3) {
- const char *s = "Protocol mismatch.\n";
- (void) write(sock_out, s, strlen(s));
+ remote_version) != 3) {
+ char *s = "Protocol mismatch.\n";
+
+ (void) atomicio(write, sock_out, s, strlen(s));
close(sock_in);
close(sock_out);
fatal("Bad protocol version identification '%.100s' from %s",
@@ -721,8 +722,9 @@ main(int ac, char **av)
debug("Client protocol version %d.%d; client software version %.100s",
remote_major, remote_minor, remote_version);
if (remote_major != PROTOCOL_MAJOR) {
- const char *s = "Protocol major versions differ.\n";
- (void) write(sock_out, s, strlen(s));
+ char *s = "Protocol major versions differ.\n";
+
+ (void) atomicio(write, sock_out, s, strlen(s));
close(sock_in);
close(sock_out);
fatal("Protocol major versions differ for %s: %d vs. %d",
diff --git a/usr.bin/ssh/sshd/Makefile b/usr.bin/ssh/sshd/Makefile
index 15d6eec2554..aa4580b84a3 100644
--- a/usr.bin/ssh/sshd/Makefile
+++ b/usr.bin/ssh/sshd/Makefile
@@ -7,7 +7,7 @@ BINDIR= /usr/sbin
MAN= sshd.8
SRCS= sshd.c auth-rhosts.c auth-passwd.c auth-rsa.c auth-rh-rsa.c \
- pty.c log-server.c login.c servconf.c serverloop.c
+ pty.c log-server.c login.c servconf.c serverloop.c atomicio.c
.include <bsd.own.mk> # for KERBEROS and AFS