summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/Makefile.inc4
-rw-r--r--usr.bin/ssh/auth-krb5.c11
-rw-r--r--usr.bin/ssh/auth.c10
-rw-r--r--usr.bin/ssh/auth.h11
-rw-r--r--usr.bin/ssh/auth1.c10
-rw-r--r--usr.bin/ssh/auth2.c22
-rw-r--r--usr.bin/ssh/canohost.c8
-rw-r--r--usr.bin/ssh/cleanup.c26
-rw-r--r--usr.bin/ssh/clientloop.c11
-rw-r--r--usr.bin/ssh/fatal.c4
-rw-r--r--usr.bin/ssh/gss-serv.c8
-rw-r--r--usr.bin/ssh/lib/Makefile4
-rw-r--r--usr.bin/ssh/log.c79
-rw-r--r--usr.bin/ssh/log.h9
-rw-r--r--usr.bin/ssh/monitor.c17
-rw-r--r--usr.bin/ssh/monitor.h4
-rw-r--r--usr.bin/ssh/monitor_wrap.c17
-rw-r--r--usr.bin/ssh/monitor_wrap.h6
-rw-r--r--usr.bin/ssh/packet.c10
-rw-r--r--usr.bin/ssh/serverloop.c14
-rw-r--r--usr.bin/ssh/session.c92
-rw-r--r--usr.bin/ssh/session.h5
-rw-r--r--usr.bin/ssh/ssh-agent.c15
-rw-r--r--usr.bin/ssh/ssh-gss.h2
-rw-r--r--usr.bin/ssh/sshd.c59
25 files changed, 191 insertions, 267 deletions
diff --git a/usr.bin/ssh/Makefile.inc b/usr.bin/ssh/Makefile.inc
index 1b8106733c0..98c9cb5702a 100644
--- a/usr.bin/ssh/Makefile.inc
+++ b/usr.bin/ssh/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.25 2003/09/18 08:49:45 markus Exp $
+# $OpenBSD: Makefile.inc,v 1.26 2003/09/23 20:17:11 markus Exp $
CFLAGS+= -I${.CURDIR}/..
@@ -10,7 +10,7 @@ CDIAGFLAGS+= -Wno-uninitialized
CDIAGFLAGS+= -Wmissing-prototypes
CDIAGFLAGS+= -Wunused
#CDIAGFLAGS+= -Wsign-compare
-#CDIAGFLAGS+= -Wbounded
+CDIAGFLAGS+= -Wbounded
#DEBUG=-g
diff --git a/usr.bin/ssh/auth-krb5.c b/usr.bin/ssh/auth-krb5.c
index 86f13359f3b..c8131291d54 100644
--- a/usr.bin/ssh/auth-krb5.c
+++ b/usr.bin/ssh/auth-krb5.c
@@ -28,7 +28,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: auth-krb5.c,v 1.12 2003/08/28 12:54:34 markus Exp $");
+RCSID("$OpenBSD: auth-krb5.c,v 1.13 2003/09/23 20:17:11 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -49,7 +49,6 @@ krb5_init(void *context)
{
Authctxt *authctxt = (Authctxt *)context;
krb5_error_code problem;
- static int cleanup_registered = 0;
if (authctxt->krb5_ctx == NULL) {
problem = krb5_init_context(&authctxt->krb5_ctx);
@@ -57,10 +56,6 @@ krb5_init(void *context)
return (problem);
krb5_init_ets(authctxt->krb5_ctx);
}
- if (!cleanup_registered) {
- fatal_add_cleanup(krb5_cleanup_proc, authctxt);
- cleanup_registered = 1;
- }
return (0);
}
@@ -143,10 +138,8 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
}
void
-krb5_cleanup_proc(void *context)
+krb5_cleanup_proc(Authctxt *authctxt)
{
- Authctxt *authctxt = (Authctxt *)context;
-
debug("krb5_cleanup_proc called");
if (authctxt->krb5_fwd_ccache) {
krb5_cc_destroy(authctxt->krb5_ctx, authctxt->krb5_fwd_ccache);
diff --git a/usr.bin/ssh/auth.c b/usr.bin/ssh/auth.c
index 4b66fa09ae3..6a62e542a67 100644
--- a/usr.bin/ssh/auth.c
+++ b/usr.bin/ssh/auth.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: auth.c,v 1.49 2003/08/26 09:58:43 markus Exp $");
+RCSID("$OpenBSD: auth.c,v 1.50 2003/09/23 20:17:11 markus Exp $");
#include <libgen.h>
@@ -153,14 +153,6 @@ allowed_user(struct passwd * pw)
return 1;
}
-Authctxt *
-authctxt_new(void)
-{
- Authctxt *authctxt = xmalloc(sizeof(*authctxt));
- memset(authctxt, 0, sizeof(*authctxt));
- return authctxt;
-}
-
void
auth_log(Authctxt *authctxt, int authenticated, char *method, char *info)
{
diff --git a/usr.bin/ssh/auth.h b/usr.bin/ssh/auth.h
index 2fbb42143b4..e5424356199 100644
--- a/usr.bin/ssh/auth.h
+++ b/usr.bin/ssh/auth.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth.h,v 1.46 2003/08/28 12:54:34 markus Exp $ */
+/* $OpenBSD: auth.h,v 1.47 2003/09/23 20:17:11 markus Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -118,13 +118,12 @@ int user_key_allowed(struct passwd *, Key *);
int auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
int auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
int auth_krb5_password(Authctxt *authctxt, const char *password);
-void krb5_cleanup_proc(void *authctxt);
+void krb5_cleanup_proc(Authctxt *authctxt);
#endif /* KRB5 */
-Authctxt *do_authentication(void);
-Authctxt *do_authentication2(void);
+void do_authentication(Authctxt *);
+void do_authentication2(Authctxt *);
-Authctxt *authctxt_new(void);
void auth_log(Authctxt *, int, char *, char *);
void userauth_finish(Authctxt *, int, char *);
int auth_root_allowed(char *);
@@ -146,8 +145,6 @@ struct passwd * getpwnamallow(const char *user);
char *get_challenge(Authctxt *);
int verify_response(Authctxt *, const char *);
-struct passwd * auth_get_user(void);
-
char *expand_filename(const char *, struct passwd *);
char *authorized_keys_file(struct passwd *);
char *authorized_keys_file2(struct passwd *);
diff --git a/usr.bin/ssh/auth1.c b/usr.bin/ssh/auth1.c
index 6554afbfa70..63b1609496d 100644
--- a/usr.bin/ssh/auth1.c
+++ b/usr.bin/ssh/auth1.c
@@ -10,7 +10,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: auth1.c,v 1.52 2003/08/28 12:54:34 markus Exp $");
+RCSID("$OpenBSD: auth1.c,v 1.53 2003/09/23 20:17:11 markus Exp $");
#include "xmalloc.h"
#include "rsa.h"
@@ -235,10 +235,9 @@ do_authloop(Authctxt *authctxt)
* Performs authentication of an incoming connection. Session key has already
* been exchanged and encryption is enabled.
*/
-Authctxt *
-do_authentication(void)
+void
+do_authentication(Authctxt *authctxt)
{
- Authctxt *authctxt;
u_int ulen;
char *user, *style = NULL;
@@ -252,7 +251,6 @@ do_authentication(void)
if ((style = strchr(user, ':')) != NULL)
*style++ = '\0';
- authctxt = authctxt_new();
authctxt->user = user;
authctxt->style = style;
@@ -285,6 +283,4 @@ do_authentication(void)
packet_start(SSH_SMSG_SUCCESS);
packet_send();
packet_write_wait();
-
- return (authctxt);
}
diff --git a/usr.bin/ssh/auth2.c b/usr.bin/ssh/auth2.c
index 15da377c590..dc70cc90040 100644
--- a/usr.bin/ssh/auth2.c
+++ b/usr.bin/ssh/auth2.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: auth2.c,v 1.102 2003/08/26 09:58:43 markus Exp $");
+RCSID("$OpenBSD: auth2.c,v 1.103 2003/09/23 20:17:11 markus Exp $");
#include "ssh2.h"
#include "xmalloc.h"
@@ -45,8 +45,6 @@ extern ServerOptions options;
extern u_char *session_id2;
extern u_int session_id2_len;
-Authctxt *x_authctxt = NULL;
-
/* methods */
extern Authmethod method_none;
@@ -85,13 +83,9 @@ int hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
* loop until authctxt->success == TRUE
*/
-Authctxt *
-do_authentication2(void)
+void
+do_authentication2(Authctxt *authctxt)
{
- Authctxt *authctxt = authctxt_new();
-
- x_authctxt = authctxt; /*XXX*/
-
/* challenge-response is implemented via keyboard interactive */
if (options.challenge_response_authentication)
options.kbd_interactive_authentication = 1;
@@ -99,8 +93,6 @@ do_authentication2(void)
dispatch_init(&dispatch_protocol_error);
dispatch_set(SSH2_MSG_SERVICE_REQUEST, &input_service_request);
dispatch_run(DISPATCH_BLOCK, &authctxt->success, authctxt);
-
- return (authctxt);
}
static void
@@ -244,14 +236,6 @@ userauth_finish(Authctxt *authctxt, int authenticated, char *method)
}
}
-/* get current user */
-
-struct passwd*
-auth_get_user(void)
-{
- return (x_authctxt != NULL && x_authctxt->valid) ? x_authctxt->pw : NULL;
-}
-
#define DELIM ","
static char *
diff --git a/usr.bin/ssh/canohost.c b/usr.bin/ssh/canohost.c
index 518db347f3f..49089747fd9 100644
--- a/usr.bin/ssh/canohost.c
+++ b/usr.bin/ssh/canohost.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: canohost.c,v 1.37 2003/06/02 09:17:34 markus Exp $");
+RCSID("$OpenBSD: canohost.c,v 1.38 2003/09/23 20:17:11 markus Exp $");
#include "packet.h"
#include "xmalloc.h"
@@ -40,7 +40,7 @@ get_remote_hostname(int socket, int use_dns)
memset(&from, 0, sizeof(from));
if (getpeername(socket, (struct sockaddr *)&from, &fromlen) < 0) {
debug("getpeername failed: %.100s", strerror(errno));
- fatal_cleanup();
+ cleanup_exit(255);
}
if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop),
@@ -264,7 +264,7 @@ get_remote_ipaddr(void)
canonical_host_ip =
get_peer_ipaddr(packet_get_connection_in());
if (canonical_host_ip == NULL)
- fatal_cleanup();
+ cleanup_exit(255);
} else {
/* If not on socket, return UNKNOWN. */
canonical_host_ip = xstrdup("UNKNOWN");
@@ -304,7 +304,7 @@ get_sock_port(int sock, int local)
} else {
if (getpeername(sock, (struct sockaddr *)&from, &fromlen) < 0) {
debug("getpeername failed: %.100s", strerror(errno));
- fatal_cleanup();
+ cleanup_exit(255);
}
}
/* Return port number. */
diff --git a/usr.bin/ssh/cleanup.c b/usr.bin/ssh/cleanup.c
new file mode 100644
index 00000000000..11d1d4d9aed
--- /dev/null
+++ b/usr.bin/ssh/cleanup.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2003 Markus Friedl <markus@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include "includes.h"
+RCSID("$OpenBSD: cleanup.c,v 1.1 2003/09/23 20:17:11 markus Exp $");
+
+#include "log.h"
+
+/* default implementation */
+void
+cleanup_exit(int i)
+{
+ _exit(i);
+}
diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c
index bc50f0bca99..d3a32a81ac2 100644
--- a/usr.bin/ssh/clientloop.c
+++ b/usr.bin/ssh/clientloop.c
@@ -59,7 +59,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: clientloop.c,v 1.113 2003/09/19 17:43:35 markus Exp $");
+RCSID("$OpenBSD: clientloop.c,v 1.114 2003/09/23 20:17:11 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -1384,14 +1384,9 @@ client_init_dispatch(void)
/* client specific fatal cleanup */
void
-fatal(const char *fmt,...)
+cleanup_exit(int i)
{
- va_list args;
-
- va_start(args, fmt);
- do_log(SYSLOG_LEVEL_FATAL, fmt, args);
- va_end(args);
leave_raw_mode();
leave_non_blocking();
- _exit(255);
+ _exit(i);
}
diff --git a/usr.bin/ssh/fatal.c b/usr.bin/ssh/fatal.c
index 9e7d1600073..ae1aaac6edd 100644
--- a/usr.bin/ssh/fatal.c
+++ b/usr.bin/ssh/fatal.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: fatal.c,v 1.1 2002/02/22 12:20:34 markus Exp $");
+RCSID("$OpenBSD: fatal.c,v 1.2 2003/09/23 20:17:11 markus Exp $");
#include "log.h"
@@ -36,5 +36,5 @@ fatal(const char *fmt,...)
va_start(args, fmt);
do_log(SYSLOG_LEVEL_FATAL, fmt, args);
va_end(args);
- fatal_cleanup();
+ cleanup_exit(255);
}
diff --git a/usr.bin/ssh/gss-serv.c b/usr.bin/ssh/gss-serv.c
index 8fd1d63f03a..6574f9750b4 100644
--- a/usr.bin/ssh/gss-serv.c
+++ b/usr.bin/ssh/gss-serv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gss-serv.c,v 1.3 2003/08/31 13:31:57 markus Exp $ */
+/* $OpenBSD: gss-serv.c,v 1.4 2003/09/23 20:17:11 markus Exp $ */
/*
* Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
@@ -232,9 +232,9 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
return (ctx->major);
}
-/* As user - called through fatal cleanup hook */
+/* As user - called on fatal/exit */
void
-ssh_gssapi_cleanup_creds(void *ignored)
+ssh_gssapi_cleanup_creds(void)
{
if (gssapi_client.store.filename != NULL) {
/* Unlink probably isn't sufficient */
@@ -249,8 +249,6 @@ ssh_gssapi_storecreds(void)
{
if (gssapi_client.mech && gssapi_client.mech->storecreds) {
(*gssapi_client.mech->storecreds)(&gssapi_client);
- if (options.gss_cleanup_creds)
- fatal_add_cleanup(ssh_gssapi_cleanup_creds, NULL);
} else
debug("ssh_gssapi_storecreds: Not a GSSAPI mechanism");
}
diff --git a/usr.bin/ssh/lib/Makefile b/usr.bin/ssh/lib/Makefile
index bdec44a7e35..9204fe14289 100644
--- a/usr.bin/ssh/lib/Makefile
+++ b/usr.bin/ssh/lib/Makefile
@@ -1,11 +1,11 @@
-# $OpenBSD: Makefile,v 1.44 2003/08/22 10:56:09 markus Exp $
+# $OpenBSD: Makefile,v 1.45 2003/09/23 20:17:11 markus Exp $
.PATH: ${.CURDIR}/..
LIB= ssh
SRCS= authfd.c authfile.c bufaux.c buffer.c canohost.c channels.c \
cipher.c cipher-3des1.c cipher-aes.c cipher-bf1.c cipher-ctr.c \
- compat.c compress.c crc32.c deattack.c fatal.c \
+ cleanup.c compat.c compress.c crc32.c deattack.c fatal.c \
hostfile.c log.c match.c mpaux.c nchan.c packet.c readpass.c \
rsa.c tildexpand.c ttymodes.c xmalloc.c atomicio.c \
key.c dispatch.c kex.c mac.c uuencode.c misc.c \
diff --git a/usr.bin/ssh/log.c b/usr.bin/ssh/log.c
index c14ed9098c5..7c1f124a58c 100644
--- a/usr.bin/ssh/log.c
+++ b/usr.bin/ssh/log.c
@@ -34,7 +34,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: log.c,v 1.28 2003/05/24 09:02:22 djm Exp $");
+RCSID("$OpenBSD: log.c,v 1.29 2003/09/23 20:17:11 markus Exp $");
#include "log.h"
#include "xmalloc.h"
@@ -178,83 +178,6 @@ debug3(const char *fmt,...)
va_end(args);
}
-/* Fatal cleanup */
-
-struct fatal_cleanup {
- struct fatal_cleanup *next;
- void (*proc) (void *);
- void *context;
-};
-
-static struct fatal_cleanup *fatal_cleanups = NULL;
-
-/* Registers a cleanup function to be called by fatal() before exiting. */
-
-void
-fatal_add_cleanup(void (*proc) (void *), void *context)
-{
- struct fatal_cleanup *cu;
-
- cu = xmalloc(sizeof(*cu));
- cu->proc = proc;
- cu->context = context;
- cu->next = fatal_cleanups;
- fatal_cleanups = cu;
-}
-
-/* Removes a cleanup frunction to be called at fatal(). */
-
-void
-fatal_remove_cleanup(void (*proc) (void *context), void *context)
-{
- struct fatal_cleanup **cup, *cu;
-
- for (cup = &fatal_cleanups; *cup; cup = &cu->next) {
- cu = *cup;
- if (cu->proc == proc && cu->context == context) {
- *cup = cu->next;
- xfree(cu);
- return;
- }
- }
- fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx",
- (u_long) proc, (u_long) context);
-}
-
-/* Remove all cleanups, to be called after fork() */
-void
-fatal_remove_all_cleanups(void)
-{
- struct fatal_cleanup *cu, *next_cu;
-
- for (cu = fatal_cleanups; cu; cu = next_cu) {
- next_cu = cu->next;
- xfree(cu);
- }
- fatal_cleanups = NULL;
-}
-
-/* Cleanup and exit */
-void
-fatal_cleanup(void)
-{
- struct fatal_cleanup *cu, *next_cu;
- static int called = 0;
-
- if (called)
- exit(255);
- called = 1;
- /* Call cleanup functions. */
- for (cu = fatal_cleanups; cu; cu = next_cu) {
- next_cu = cu->next;
- debug("Calling cleanup 0x%lx(0x%lx)",
- (u_long) cu->proc, (u_long) cu->context);
- (*cu->proc) (cu->context);
- }
- exit(255);
-}
-
-
/*
* Initialize the log.
*/
diff --git a/usr.bin/ssh/log.h b/usr.bin/ssh/log.h
index 79c34e00d08..9f0546ac6fe 100644
--- a/usr.bin/ssh/log.h
+++ b/usr.bin/ssh/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.9 2003/04/08 20:21:28 itojun Exp $ */
+/* $OpenBSD: log.h,v 1.10 2003/09/23 20:17:11 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -56,11 +56,6 @@ void debug(const char *, ...) __attribute__((format(printf, 1, 2)));
void debug2(const char *, ...) __attribute__((format(printf, 1, 2)));
void debug3(const char *, ...) __attribute__((format(printf, 1, 2)));
-void fatal_cleanup(void);
-void fatal_add_cleanup(void (*) (void *), void *);
-void fatal_remove_cleanup(void (*) (void *), void *);
-void fatal_remove_all_cleanups(void);
-
void do_log(LogLevel, const char *, va_list);
-
+void cleanup_exit(int);
#endif
diff --git a/usr.bin/ssh/monitor.c b/usr.bin/ssh/monitor.c
index 6fe2abee8fe..269254092b2 100644
--- a/usr.bin/ssh/monitor.c
+++ b/usr.bin/ssh/monitor.c
@@ -25,7 +25,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: monitor.c,v 1.49 2003/08/28 12:54:34 markus Exp $");
+RCSID("$OpenBSD: monitor.c,v 1.50 2003/09/23 20:17:11 markus Exp $");
#include <openssl/dh.h>
@@ -247,14 +247,17 @@ monitor_permit_authentications(int permit)
}
}
-Authctxt *
-monitor_child_preauth(struct monitor *pmonitor)
+void
+monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
{
struct mon_table *ent;
int authenticated = 0;
debug3("preauth child monitor started");
+ authctxt = _authctxt;
+ memset(authctxt, 0, sizeof(*authctxt));
+
if (compat20) {
mon_dispatch = mon_dispatch_proto20;
@@ -267,8 +270,6 @@ monitor_child_preauth(struct monitor *pmonitor)
monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
}
- authctxt = authctxt_new();
-
/* The first few requests do not require asynchronous access */
while (!authenticated) {
authenticated = monitor_read(pmonitor, mon_dispatch, &ent);
@@ -296,8 +297,6 @@ monitor_child_preauth(struct monitor *pmonitor)
__func__, authctxt->user);
mm_get_keystate(pmonitor);
-
- return (authctxt);
}
static void
@@ -1007,7 +1006,7 @@ mm_record_login(Session *s, struct passwd *pw)
if (getpeername(packet_get_connection_in(),
(struct sockaddr *) & from, &fromlen) < 0) {
debug("getpeername: %.100s", strerror(errno));
- fatal_cleanup();
+ cleanup_exit(255);
}
}
/* Record that there was a login on that tty from the remote host. */
@@ -1022,7 +1021,6 @@ mm_session_close(Session *s)
debug3("%s: session %d pid %ld", __func__, s->self, (long)s->pid);
if (s->ttyfd != -1) {
debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd);
- fatal_remove_cleanup(session_pty_cleanup2, (void *)s);
session_pty_cleanup2(s);
}
s->used = 0;
@@ -1047,7 +1045,6 @@ mm_answer_pty(int socket, Buffer *m)
res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
if (res == 0)
goto error;
- fatal_add_cleanup(session_pty_cleanup2, (void *)s);
pty_setowner(authctxt->pw, s->tty);
buffer_put_int(m, 1);
diff --git a/usr.bin/ssh/monitor.h b/usr.bin/ssh/monitor.h
index c0ef143fbdd..2afbfed6f44 100644
--- a/usr.bin/ssh/monitor.h
+++ b/usr.bin/ssh/monitor.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor.h,v 1.11 2003/08/28 12:54:34 markus Exp $ */
+/* $OpenBSD: monitor.h,v 1.12 2003/09/23 20:17:11 markus Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
@@ -70,7 +70,7 @@ void monitor_reinit(struct monitor *);
void monitor_sync(struct monitor *);
struct Authctxt;
-struct Authctxt *monitor_child_preauth(struct monitor *);
+void monitor_child_preauth(struct Authctxt *, struct monitor *);
void monitor_child_postauth(struct monitor *);
struct mon_table;
diff --git a/usr.bin/ssh/monitor_wrap.c b/usr.bin/ssh/monitor_wrap.c
index 4edd4c04bd7..e9598bbce8c 100644
--- a/usr.bin/ssh/monitor_wrap.c
+++ b/usr.bin/ssh/monitor_wrap.c
@@ -25,7 +25,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: monitor_wrap.c,v 1.31 2003/08/28 12:54:34 markus Exp $");
+RCSID("$OpenBSD: monitor_wrap.c,v 1.32 2003/09/23 20:17:11 markus Exp $");
#include <openssl/bn.h>
#include <openssl/dh.h>
@@ -64,6 +64,16 @@ extern z_stream outgoing_stream;
extern struct monitor *pmonitor;
extern Buffer input, output;
+int
+mm_is_monitor(void)
+{
+ /*
+ * m_pid is only set in the privileged part, and
+ * points to the unprivileged child.
+ */
+ return (pmonitor->m_pid > 0);
+}
+
void
mm_request_send(int socket, enum monitor_reqtype type, Buffer *m)
{
@@ -92,7 +102,7 @@ mm_request_receive(int socket, Buffer *m)
res = atomicio(read, socket, buf, sizeof(buf));
if (res != sizeof(buf)) {
if (res == 0)
- fatal_cleanup();
+ cleanup_exit(255);
fatal("%s: read: %ld", __func__, (long)res);
}
msg_len = GET_32BIT(buf);
@@ -644,9 +654,8 @@ mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
}
void
-mm_session_pty_cleanup2(void *session)
+mm_session_pty_cleanup2(Session *s)
{
- Session *s = session;
Buffer m;
if (s->ttyfd == -1)
diff --git a/usr.bin/ssh/monitor_wrap.h b/usr.bin/ssh/monitor_wrap.h
index 92f940a4a72..f03222aef73 100644
--- a/usr.bin/ssh/monitor_wrap.h
+++ b/usr.bin/ssh/monitor_wrap.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor_wrap.h,v 1.11 2003/08/28 12:54:34 markus Exp $ */
+/* $OpenBSD: monitor_wrap.h,v 1.12 2003/09/23 20:17:11 markus Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
@@ -40,6 +40,7 @@ struct mm_master;
struct passwd;
struct Authctxt;
+int mm_is_monitor(void);
DH *mm_choose_dh(int, int, int);
int mm_key_sign(Key *, u_char **, u_int *, u_char *, u_int);
void mm_inform_authserv(char *, char *);
@@ -63,9 +64,10 @@ OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *ctxt,
int mm_ssh_gssapi_userok(char *user);
#endif
+struct Session;
void mm_terminate(void);
int mm_pty_allocate(int *, int *, char *, int);
-void mm_session_pty_cleanup2(void *);
+void mm_session_pty_cleanup2(struct Session *);
/* SSHv1 interfaces */
void mm_ssh1_session_id(u_char *);
diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c
index 7635ac2d138..bdc7f5e73cb 100644
--- a/usr.bin/ssh/packet.c
+++ b/usr.bin/ssh/packet.c
@@ -37,7 +37,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: packet.c,v 1.111 2003/09/19 11:33:09 markus Exp $");
+RCSID("$OpenBSD: packet.c,v 1.112 2003/09/23 20:17:11 markus Exp $");
#include <sys/queue.h>
@@ -863,7 +863,7 @@ packet_read_seqnr(u_int32_t *seqnr_p)
len = read(connection_in, buf, sizeof(buf));
if (len == 0) {
logit("Connection closed by %.200s", get_remote_ipaddr());
- fatal_cleanup();
+ cleanup_exit(255);
}
if (len < 0)
fatal("Read from socket failed: %.100s", strerror(errno));
@@ -1129,7 +1129,7 @@ packet_read_poll_seqnr(u_int32_t *seqnr_p)
logit("Received disconnect from %s: %u: %.400s",
get_remote_ipaddr(), reason, msg);
xfree(msg);
- fatal_cleanup();
+ cleanup_exit(255);
break;
case SSH2_MSG_UNIMPLEMENTED:
seqnr = packet_get_int();
@@ -1154,7 +1154,7 @@ packet_read_poll_seqnr(u_int32_t *seqnr_p)
msg = packet_get_string(NULL);
logit("Received disconnect from %s: %.400s",
get_remote_ipaddr(), msg);
- fatal_cleanup();
+ cleanup_exit(255);
xfree(msg);
break;
default:
@@ -1331,7 +1331,7 @@ packet_disconnect(const char *fmt,...)
/* Close the connection. */
packet_close();
- fatal_cleanup();
+ cleanup_exit(255);
}
/* Checks if there is any buffered output, and tries to write some of the output. */
diff --git a/usr.bin/ssh/serverloop.c b/usr.bin/ssh/serverloop.c
index 771dc14ff53..9f8b16490d7 100644
--- a/usr.bin/ssh/serverloop.c
+++ b/usr.bin/ssh/serverloop.c
@@ -35,7 +35,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: serverloop.c,v 1.110 2003/06/24 08:23:46 markus Exp $");
+RCSID("$OpenBSD: serverloop.c,v 1.111 2003/09/23 20:17:11 markus Exp $");
#include "xmalloc.h"
#include "packet.h"
@@ -60,7 +60,7 @@ extern ServerOptions options;
/* XXX */
extern Kex *xxx_kex;
-static Authctxt *xxx_authctxt;
+extern Authctxt *the_authctxt;
static Buffer stdin_buffer; /* Buffer for stdin data. */
static Buffer stdout_buffer; /* Buffer for stdout data. */
@@ -353,13 +353,13 @@ process_input(fd_set * readset)
connection_closed = 1;
if (compat20)
return;
- fatal_cleanup();
+ cleanup_exit(255);
} else if (len < 0) {
if (errno != EINTR && errno != EAGAIN) {
verbose("Read error from remote host "
"%.100s: %.100s",
get_remote_ipaddr(), strerror(errno));
- fatal_cleanup();
+ cleanup_exit(255);
}
} else {
/* Buffer any received data. */
@@ -754,8 +754,6 @@ server_loop2(Authctxt *authctxt)
max_fd = MAX(connection_in, connection_out);
max_fd = MAX(max_fd, notify_pipe[0]);
- xxx_authctxt = authctxt;
-
server_init_dispatch();
for (;;) {
@@ -898,7 +896,7 @@ server_request_session(char *ctype)
c = channel_new(ctype, SSH_CHANNEL_LARVAL,
-1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
0, "server-session", 1);
- if (session_open(xxx_authctxt, c->self) != 1) {
+ if (session_open(the_authctxt, c->self) != 1) {
debug("session open failed, free channel %d", c->self);
channel_free(c);
return NULL;
@@ -972,7 +970,7 @@ server_input_global_request(int type, u_int32_t seq, void *ctxt)
char *listen_address;
u_short listen_port;
- pw = auth_get_user();
+ pw = the_authctxt->pw;
if (pw == NULL)
fatal("server_input_global_request: no user");
listen_address = packet_get_string(NULL);
diff --git a/usr.bin/ssh/session.c b/usr.bin/ssh/session.c
index 0b4592a1378..b978fc83751 100644
--- a/usr.bin/ssh/session.c
+++ b/usr.bin/ssh/session.c
@@ -33,7 +33,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.164 2003/09/18 08:49:45 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.165 2003/09/23 20:17:11 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -66,7 +66,7 @@ RCSID("$OpenBSD: session.c,v 1.164 2003/09/18 08:49:45 markus Exp $");
Session *session_new(void);
void session_set_fds(Session *, int, int, int);
-void session_pty_cleanup(void *);
+void session_pty_cleanup(Session *);
void session_proctitle(Session *);
int session_setup_x11fwd(Session *);
void do_exec_pty(Session *, const char *);
@@ -102,6 +102,8 @@ Session sessions[MAX_SESSIONS];
login_cap_t *lc;
#endif
+static int is_child = 0;
+
/* Name and directory of socket for authentication agent forwarding. */
static char *auth_sock_name = NULL;
static char *auth_sock_dir = NULL;
@@ -109,10 +111,8 @@ static char *auth_sock_dir = NULL;
/* removes the agent forwarding socket */
static void
-auth_sock_cleanup_proc(void *_pw)
+auth_sock_cleanup_proc(struct passwd *pw)
{
- struct passwd *pw = _pw;
-
if (auth_sock_name != NULL) {
temporarily_use_uid(pw);
unlink(auth_sock_name);
@@ -156,9 +156,6 @@ auth_input_request_forwarding(struct passwd * pw)
snprintf(auth_sock_name, MAXPATHLEN, "%s/agent.%ld",
auth_sock_dir, (long) getpid());
- /* delete agent socket on fatal() */
- fatal_add_cleanup(auth_sock_cleanup_proc, pw);
-
/* Create the socket. */
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0)
@@ -212,13 +209,7 @@ do_authenticated(Authctxt *authctxt)
else
do_authenticated1(authctxt);
- /* remove agent socket */
- if (auth_sock_name != NULL)
- auth_sock_cleanup_proc(authctxt->pw);
-#ifdef KRB5
- if (options.kerberos_ticket_cleanup)
- krb5_cleanup_proc(authctxt);
-#endif
+ do_cleanup(authctxt);
}
/*
@@ -391,7 +382,7 @@ do_exec_no_pty(Session *s, const char *command)
/* Fork the child. */
if ((pid = fork()) == 0) {
- fatal_remove_all_cleanups();
+ is_child = 1;
/* Child. Reinitialize the log since the pid has changed. */
log_init(__progname, options.log_level, options.log_facility, log_stderr);
@@ -499,7 +490,7 @@ do_exec_pty(Session *s, const char *command)
/* Fork the child. */
if ((pid = fork()) == 0) {
- fatal_remove_all_cleanups();
+ is_child = 1;
/* Child. Reinitialize the log because the pid has changed. */
log_init(__progname, options.log_level, options.log_facility, log_stderr);
@@ -610,7 +601,7 @@ do_login(Session *s, const char *command)
if (getpeername(packet_get_connection_in(),
(struct sockaddr *) & from, &fromlen) < 0) {
debug("getpeername: %.100s", strerror(errno));
- fatal_cleanup();
+ cleanup_exit(255);
}
}
@@ -930,7 +921,7 @@ do_rc_files(Session *s, const char *shell)
if (debug_flag) {
fprintf(stderr,
"Running %.500s remove %.100s\n",
- options.xauth_location, s->auth_display);
+ options.xauth_location, s->auth_display);
fprintf(stderr,
"%.500s add %.100s %.100s %.100s\n",
options.xauth_location, s->auth_display,
@@ -1360,11 +1351,6 @@ session_pty_req(Session *s)
n_bytes = packet_remaining();
tty_parse_modes(s->ttyfd, &n_bytes);
- /*
- * Add a cleanup function to clear the utmp entry and record logout
- * time in case we call fatal() (e.g., the connection gets closed).
- */
- fatal_add_cleanup(session_pty_cleanup, (void *)s);
if (!use_privsep)
pty_setowner(s->pw, s->tty);
@@ -1546,10 +1532,8 @@ session_set_fds(Session *s, int fdin, int fdout, int fderr)
* (e.g., due to a dropped connection).
*/
void
-session_pty_cleanup2(void *session)
+session_pty_cleanup2(Session *s)
{
- Session *s = session;
-
if (s == NULL) {
error("session_pty_cleanup: no session");
return;
@@ -1580,9 +1564,9 @@ session_pty_cleanup2(void *session)
}
void
-session_pty_cleanup(void *session)
+session_pty_cleanup(Session *s)
{
- PRIVSEP(session_pty_cleanup2(session));
+ PRIVSEP(session_pty_cleanup2(s));
}
static char *
@@ -1651,10 +1635,8 @@ void
session_close(Session *s)
{
debug("session_close: session %d pid %ld", s->self, (long)s->pid);
- if (s->ttyfd != -1) {
- fatal_remove_cleanup(session_pty_cleanup, (void *)s);
+ if (s->ttyfd != -1)
session_pty_cleanup(s);
- }
if (s->term)
xfree(s->term);
if (s->display)
@@ -1703,10 +1685,8 @@ session_close_by_channel(int id, void *arg)
* delay detach of session, but release pty, since
* the fd's to the child are already closed
*/
- if (s->ttyfd != -1) {
- fatal_remove_cleanup(session_pty_cleanup, (void *)s);
+ if (s->ttyfd != -1)
session_pty_cleanup(s);
- }
return;
}
/* detach by removing callback */
@@ -1823,8 +1803,44 @@ static void
do_authenticated2(Authctxt *authctxt)
{
server_loop2(authctxt);
-#if defined(GSSAPI)
- if (options.gss_cleanup_creds)
- ssh_gssapi_cleanup_creds(NULL);
+}
+
+void
+do_cleanup(Authctxt *authctxt)
+{
+ static int called = 0;
+
+ debug("do_cleanup");
+
+ /* no cleanup if we're in the child for login shell */
+ if (is_child)
+ return;
+
+ /* avoid double cleanup */
+ if (called)
+ return;
+ called = 1;
+
+ if (authctxt == NULL)
+ return;
+#ifdef KRB5
+ if (options.kerberos_ticket_cleanup &&
+ authctxt->krb5_ctx)
+ krb5_cleanup_proc(authctxt);
#endif
+
+#ifdef GSSAPI
+ if (compat20 && options.gss_cleanup_creds)
+ ssh_gssapi_cleanup_creds();
+#endif
+
+ /* remove agent socket */
+ auth_sock_cleanup_proc(authctxt->pw);
+
+ /*
+ * Cleanup ptys/utmp only if privsep is disabled,
+ * or if running in monitor.
+ */
+ if (!use_privsep || mm_is_monitor())
+ session_destroy_all(session_pty_cleanup2);
}
diff --git a/usr.bin/ssh/session.h b/usr.bin/ssh/session.h
index 525e47f64ec..405b8fe8a91 100644
--- a/usr.bin/ssh/session.h
+++ b/usr.bin/ssh/session.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.h,v 1.20 2003/08/22 10:56:09 markus Exp $ */
+/* $OpenBSD: session.h,v 1.21 2003/09/23 20:17:11 markus Exp $ */
/*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -56,13 +56,14 @@ struct Session {
};
void do_authenticated(Authctxt *);
+void do_cleanup(Authctxt *);
int session_open(Authctxt *, int);
int session_input_channel_req(Channel *, const char *);
void session_close_by_pid(pid_t, int);
void session_close_by_channel(int, void *);
void session_destroy_all(void (*)(Session *));
-void session_pty_cleanup2(void *);
+void session_pty_cleanup2(Session *);
Session *session_new(void);
Session *session_by_tty(char *);
diff --git a/usr.bin/ssh/ssh-agent.c b/usr.bin/ssh/ssh-agent.c
index 542ac9e0ba2..1594c0fcb3a 100644
--- a/usr.bin/ssh/ssh-agent.c
+++ b/usr.bin/ssh/ssh-agent.c
@@ -35,7 +35,7 @@
#include "includes.h"
#include <sys/queue.h>
-RCSID("$OpenBSD: ssh-agent.c,v 1.113 2003/09/19 11:29:40 markus Exp $");
+RCSID("$OpenBSD: ssh-agent.c,v 1.114 2003/09/23 20:17:11 markus Exp $");
#include <openssl/evp.h>
#include <openssl/md5.h>
@@ -953,7 +953,7 @@ cleanup_socket(void)
rmdir(socket_dir);
}
-static void
+void
cleanup_exit(int i)
{
cleanup_socket();
@@ -967,17 +967,6 @@ cleanup_handler(int sig)
_exit(2);
}
-void
-fatal(const char *fmt,...)
-{
- va_list args;
- va_start(args, fmt);
- do_log(SYSLOG_LEVEL_FATAL, fmt, args);
- va_end(args);
- cleanup_socket();
- _exit(255);
-}
-
static void
check_parent_exists(int sig)
{
diff --git a/usr.bin/ssh/ssh-gss.h b/usr.bin/ssh/ssh-gss.h
index 263e51b94e0..71e288ea30d 100644
--- a/usr.bin/ssh/ssh-gss.h
+++ b/usr.bin/ssh/ssh-gss.h
@@ -101,7 +101,7 @@ OM_uint32 ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID oid);
int ssh_gssapi_userok(char *name);
void ssh_gssapi_do_child(char ***envp, u_int *envsizep);
-void ssh_gssapi_cleanup_creds(void *ignored);
+void ssh_gssapi_cleanup_creds(void);
void ssh_gssapi_storecreds(void);
#endif /* GSSAPI */
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index 311b3c0184b..d58fa816401 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -42,7 +42,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: sshd.c,v 1.277 2003/09/19 11:33:09 markus Exp $");
+RCSID("$OpenBSD: sshd.c,v 1.278 2003/09/23 20:17:11 markus Exp $");
#include <openssl/dh.h>
#include <openssl/bn.h>
@@ -192,6 +192,9 @@ int startup_pipe; /* in child */
int use_privsep;
struct monitor *pmonitor;
+/* global authentication context */
+Authctxt *the_authctxt = NULL;
+
/* Prototypes for various functions defined later in this file. */
void destroy_sensitive_data(void);
void demote_sensitive_data(void);
@@ -363,7 +366,7 @@ sshd_exchange_identification(int sock_in, int sock_out)
strlen(server_version_string))
!= strlen(server_version_string)) {
logit("Could not write ident string to %s", get_remote_ipaddr());
- fatal_cleanup();
+ cleanup_exit(255);
}
/* Read other sides version identification. */
@@ -372,7 +375,7 @@ sshd_exchange_identification(int sock_in, int sock_out)
if (atomicio(read, sock_in, &buf[i], 1) != 1) {
logit("Did not receive identification string from %s",
get_remote_ipaddr());
- fatal_cleanup();
+ cleanup_exit(255);
}
if (buf[i] == '\r') {
buf[i] = 0;
@@ -402,7 +405,7 @@ sshd_exchange_identification(int sock_in, int sock_out)
close(sock_out);
logit("Bad protocol version identification '%.100s' from %s",
client_version_string, get_remote_ipaddr());
- fatal_cleanup();
+ cleanup_exit(255);
}
debug("Client protocol version %d.%d; client software version %.100s",
remote_major, remote_minor, remote_version);
@@ -412,13 +415,13 @@ sshd_exchange_identification(int sock_in, int sock_out)
if (datafellows & SSH_BUG_PROBE) {
logit("probed from %s with %s. Don't panic.",
get_remote_ipaddr(), client_version_string);
- fatal_cleanup();
+ cleanup_exit(255);
}
if (datafellows & SSH_BUG_SCANNER) {
logit("scanned from %s with %s. Don't panic.",
get_remote_ipaddr(), client_version_string);
- fatal_cleanup();
+ cleanup_exit(255);
}
mismatch = 0;
@@ -464,7 +467,7 @@ sshd_exchange_identification(int sock_in, int sock_out)
logit("Protocol major versions differ for %s: %.200s vs. %.200s",
get_remote_ipaddr(),
server_version_string, client_version_string);
- fatal_cleanup();
+ cleanup_exit(255);
}
}
@@ -559,10 +562,9 @@ privsep_preauth_child(void)
#endif
}
-static Authctxt *
-privsep_preauth(void)
+static int
+privsep_preauth(Authctxt *authctxt)
{
- Authctxt *authctxt = NULL;
int status;
pid_t pid;
@@ -578,7 +580,7 @@ privsep_preauth(void)
debug2("Network child is on pid %ld", (long)pid);
close(pmonitor->m_recvfd);
- authctxt = monitor_child_preauth(pmonitor);
+ monitor_child_preauth(authctxt, pmonitor);
close(pmonitor->m_sendfd);
/* Sync memory */
@@ -588,7 +590,7 @@ privsep_preauth(void)
while (waitpid(pid, &status, 0) < 0)
if (errno != EINTR)
break;
- return (authctxt);
+ return (1);
} else {
/* child */
@@ -599,17 +601,12 @@ privsep_preauth(void)
privsep_preauth_child();
setproctitle("%s", "[net]");
}
- return (NULL);
+ return (0);
}
static void
privsep_postauth(Authctxt *authctxt)
{
- extern Authctxt *x_authctxt;
-
- /* XXX - Remote port forwarding */
- x_authctxt = authctxt;
-
if (authctxt->pw->pw_uid == 0 || options.use_login) {
/* File descriptor passing is broken or root login */
monitor_apply_keystate(pmonitor);
@@ -788,8 +785,8 @@ main(int ac, char **av)
int listen_sock, maxfd;
int startup_p[2];
int startups = 0;
- Authctxt *authctxt;
Key *key;
+ Authctxt *authctxt;
int ret, key_used = 0;
/* Save argv. */
@@ -1390,18 +1387,25 @@ main(int ac, char **av)
packet_set_nonblocking();
+ /* allocate authentication context */
+ authctxt = xmalloc(sizeof(*authctxt));
+ memset(authctxt, 0, sizeof(*authctxt));
+
+ /* XXX global for cleanup, access from other modules */
+ the_authctxt = authctxt;
+
if (use_privsep)
- if ((authctxt = privsep_preauth()) != NULL)
+ if (privsep_preauth(authctxt) == 1)
goto authenticated;
/* perform the key exchange */
/* authenticate user and start session */
if (compat20) {
do_ssh2_kex();
- authctxt = do_authentication2();
+ do_authentication2(authctxt);
} else {
do_ssh1_kex();
- authctxt = do_authentication();
+ do_authentication(authctxt);
}
/*
* If we use privilege separation, the unprivileged child transfers
@@ -1424,7 +1428,7 @@ main(int ac, char **av)
destroy_sensitive_data();
}
- /* Perform session preparation. */
+ /* Start session. */
do_authenticated(authctxt);
/* The connection has been terminated. */
@@ -1711,3 +1715,12 @@ do_ssh2_kex(void)
#endif
debug("KEX done");
}
+
+/* server specific fatal cleanup */
+void
+cleanup_exit(int i)
+{
+ if (the_authctxt)
+ do_cleanup(the_authctxt);
+ _exit(i);
+}