=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/monitor.c,v retrieving revision 1.68.2.2 retrieving revision 1.69 diff -u -r1.68.2.2 -r1.69 --- src/usr.bin/ssh/monitor.c 2006/11/08 00:17:14 1.68.2.2 +++ src/usr.bin/ssh/monitor.c 2006/03/07 09:07:40 1.69 @@ -1,4 +1,3 @@ -/* $OpenBSD: monitor.c,v 1.68.2.2 2006/11/08 00:17:14 brad Exp $ */ /* * Copyright 2002 Niels Provos * Copyright 2002 Markus Friedl @@ -25,36 +24,26 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "includes.h" +RCSID("$OpenBSD: monitor.c,v 1.69 2006/03/07 09:07:40 djm Exp $"); + #include #include -#include -#include -#include -#include - -#include -#include #include -#include #include -#include -#include #ifdef SKEY #include #endif -#include "xmalloc.h" +#include + #include "ssh.h" -#include "key.h" -#include "buffer.h" -#include "hostfile.h" #include "auth.h" -#include "cipher.h" #include "kex.h" #include "dh.h" -#include +#include "zlib.h" #include "packet.h" #include "auth-options.h" #include "sshpty.h" @@ -66,16 +55,17 @@ #include "servconf.h" #include "monitor.h" #include "monitor_mm.h" -#ifdef GSSAPI -#include "ssh-gss.h" -#endif #include "monitor_wrap.h" #include "monitor_fdpass.h" +#include "xmalloc.h" #include "misc.h" +#include "buffer.h" +#include "bufaux.h" #include "compat.h" #include "ssh2.h" #ifdef GSSAPI +#include "ssh-gss.h" static Gssctxt *gsscontext = NULL; #endif @@ -167,7 +157,6 @@ #define MON_ISAUTH 0x0004 /* Required for Authentication */ #define MON_AUTHDECIDE 0x0008 /* Decides Authentication */ #define MON_ONCE 0x0010 /* Disable after calling */ -#define MON_ALOG 0x0020 /* Log auth attempt without authenticating */ #define MON_AUTH (MON_ISAUTH|MON_AUTHDECIDE) @@ -213,8 +202,8 @@ {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey}, {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid}, {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword}, - {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH|MON_ALOG, mm_answer_rsa_keyallowed}, - {MONITOR_REQ_KEYALLOWED, MON_ISAUTH|MON_ALOG, mm_answer_keyallowed}, + {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH, mm_answer_rsa_keyallowed}, + {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed}, {MONITOR_REQ_RSACHALLENGE, MON_ONCE, mm_answer_rsa_challenge}, {MONITOR_REQ_RSARESPONSE, MON_ONCE|MON_AUTHDECIDE, mm_answer_rsa_response}, #ifdef BSD_AUTH @@ -291,8 +280,7 @@ /* The first few requests do not require asynchronous access */ while (!authenticated) { - auth_method = "unknown"; - authenticated = (monitor_read(pmonitor, mon_dispatch, &ent) == 1); + authenticated = monitor_read(pmonitor, mon_dispatch, &ent); if (authenticated) { if (!(ent->flags & MON_AUTHDECIDE)) fatal("%s: unexpected authentication from %d", @@ -302,7 +290,7 @@ authenticated = 0; } - if (ent->flags & (MON_AUTHDECIDE|MON_ALOG)) { + if (ent->flags & MON_AUTHDECIDE) { auth_log(authctxt, authenticated, auth_method, compat20 ? " ssh2" : ""); if (!authenticated) @@ -312,8 +300,6 @@ if (!authctxt->valid) fatal("%s: authenticated invalid user", __func__); - if (strcmp(auth_method, "unknown") == 0) - fatal("%s: authentication method name unknown", __func__); debug("%s: %s has been authenticated by privileged process", __func__, authctxt->user); @@ -494,7 +480,7 @@ p = buffer_get_string(m, &datlen); /* - * Supported KEX types will only return SHA1 (20 byte) or + * Supported KEX types will only return SHA1 (20 byte) or * SHA256 (32 byte) hashes */ if (datlen != 20 && datlen != 32) @@ -800,20 +786,17 @@ case MM_USERKEY: allowed = options.pubkey_authentication && user_key_allowed(authctxt->pw, key); - auth_method = "publickey"; break; case MM_HOSTKEY: allowed = options.hostbased_authentication && hostbased_key_allowed(authctxt->pw, cuser, chost, key); - auth_method = "hostbased"; break; case MM_RSAHOSTKEY: key->type = KEY_RSA1; /* XXX */ allowed = options.rhosts_rsa_authentication && auth_rhosts_rsa_key_allowed(authctxt->pw, cuser, chost, key); - auth_method = "rsa"; break; default: fatal("%s: unknown key type %d", __func__, type); @@ -833,12 +816,6 @@ key_blobtype = type; hostbased_cuser = cuser; hostbased_chost = chost; - } else { - /* Log failed attempt */ - auth_log(authctxt, 0, auth_method, compat20 ? " ssh2" : ""); - xfree(blob); - xfree(cuser); - xfree(chost); } debug3("%s: key %p is %s", @@ -1008,7 +985,7 @@ verified = key_verify(key, signature, signaturelen, data, datalen); debug3("%s: key %p signature %s", - __func__, key, (verified == 1) ? "verified" : "unverified"); + __func__, key, verified ? "verified" : "unverified"); key_free(key); xfree(blob); @@ -1023,7 +1000,7 @@ buffer_put_int(m, verified); mm_request_send(sock, MONITOR_ANS_KEYVERIFY, m); - return (verified == 1); + return (verified); } static void @@ -1040,7 +1017,7 @@ fromlen = sizeof(from); if (packet_connection_is_on_socket()) { if (getpeername(packet_get_connection_in(), - (struct sockaddr *)&from, &fromlen) < 0) { + (struct sockaddr *) & from, &fromlen) < 0) { debug("getpeername: %.100s", strerror(errno)); cleanup_exit(255); } @@ -1056,7 +1033,7 @@ { 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); + debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd); session_pty_cleanup2(s); } s->used = 0; @@ -1116,7 +1093,7 @@ /* no need to dup() because nobody closes ptyfd */ s->ptymaster = s->ptyfd; - debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd); + debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd); return (0); @@ -1203,7 +1180,6 @@ debug3("%s entering", __func__); - auth_method = "rsa"; if (options.rsa_authentication && authctxt->valid) { if ((client_n = BN_new()) == NULL) fatal("%s: BN_new", __func__); @@ -1398,7 +1374,8 @@ void *blob; u_int bloblen; - kex = xcalloc(1, sizeof(*kex)); + kex = xmalloc(sizeof(*kex)); + memset(kex, 0, sizeof(*kex)); kex->session_id = buffer_get_string(m, &kex->session_id_len); if ((session_id2 == NULL) || (kex->session_id_len != session_id2_len) || @@ -1563,8 +1540,9 @@ struct monitor *mon; int pair[2]; - mon = xcalloc(1, sizeof(*mon)); + mon = xmalloc(sizeof(*mon)); + mon->m_pid = 0; monitor_socketpair(pair); mon->m_recvfd = pair[0];