diff options
author | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:32:03 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:32:03 +0000 |
commit | 04942aa41fa94ec6f2c3ce1d348f600f31bb7c78 (patch) | |
tree | af8e928bd79d3f2d0219bb5b2c78b573ec31d94c /sshd.c | |
parent | 9ad7b718d42e43f3a285fcbc8f91193931fce324 (diff) | |
parent | 16704d57999d987fb8d9ba53379841a79f016d67 (diff) |
import openssh-4.2p1-gsskex-20050926-2.patch
Diffstat (limited to 'sshd.c')
-rw-r--r-- | sshd.c | 107 |
1 files changed, 94 insertions, 13 deletions
@@ -42,7 +42,7 @@ | |||
42 | */ | 42 | */ |
43 | 43 | ||
44 | #include "includes.h" | 44 | #include "includes.h" |
45 | RCSID("$OpenBSD: sshd.c,v 1.308 2005/02/08 22:24:57 dtucker Exp $"); | 45 | RCSID("$OpenBSD: sshd.c,v 1.312 2005/07/25 11:59:40 markus Exp $"); |
46 | 46 | ||
47 | #include <openssl/dh.h> | 47 | #include <openssl/dh.h> |
48 | #include <openssl/bn.h> | 48 | #include <openssl/bn.h> |
@@ -86,6 +86,10 @@ RCSID("$OpenBSD: sshd.c,v 1.308 2005/02/08 22:24:57 dtucker Exp $"); | |||
86 | #include "monitor_wrap.h" | 86 | #include "monitor_wrap.h" |
87 | #include "monitor_fdpass.h" | 87 | #include "monitor_fdpass.h" |
88 | 88 | ||
89 | #ifdef USE_SECURITY_SESSION_API | ||
90 | #include <Security/AuthSession.h> | ||
91 | #endif | ||
92 | |||
89 | #ifdef LIBWRAP | 93 | #ifdef LIBWRAP |
90 | #include <tcpd.h> | 94 | #include <tcpd.h> |
91 | #include <syslog.h> | 95 | #include <syslog.h> |
@@ -358,7 +362,8 @@ key_regeneration_alarm(int sig) | |||
358 | static void | 362 | static void |
359 | sshd_exchange_identification(int sock_in, int sock_out) | 363 | sshd_exchange_identification(int sock_in, int sock_out) |
360 | { | 364 | { |
361 | int i, mismatch; | 365 | u_int i; |
366 | int mismatch; | ||
362 | int remote_major, remote_minor; | 367 | int remote_major, remote_minor; |
363 | int major, minor; | 368 | int major, minor; |
364 | char *s; | 369 | char *s; |
@@ -670,6 +675,12 @@ privsep_postauth(Authctxt *authctxt) | |||
670 | 675 | ||
671 | /* It is safe now to apply the key state */ | 676 | /* It is safe now to apply the key state */ |
672 | monitor_apply_keystate(pmonitor); | 677 | monitor_apply_keystate(pmonitor); |
678 | |||
679 | /* | ||
680 | * Tell the packet layer that authentication was successful, since | ||
681 | * this information is not part of the key state. | ||
682 | */ | ||
683 | packet_set_authenticated(); | ||
673 | } | 684 | } |
674 | 685 | ||
675 | static char * | 686 | static char * |
@@ -1033,7 +1044,7 @@ main(int ac, char **av) | |||
1033 | /* | 1044 | /* |
1034 | * Unset KRB5CCNAME, otherwise the user's session may inherit it from | 1045 | * Unset KRB5CCNAME, otherwise the user's session may inherit it from |
1035 | * root's environment | 1046 | * root's environment |
1036 | */ | 1047 | */ |
1037 | if (getenv("KRB5CCNAME") != NULL) | 1048 | if (getenv("KRB5CCNAME") != NULL) |
1038 | unsetenv("KRB5CCNAME"); | 1049 | unsetenv("KRB5CCNAME"); |
1039 | 1050 | ||
@@ -1111,6 +1122,7 @@ main(int ac, char **av) | |||
1111 | options.protocol &= ~SSH_PROTO_1; | 1122 | options.protocol &= ~SSH_PROTO_1; |
1112 | } | 1123 | } |
1113 | #ifndef GSSAPI | 1124 | #ifndef GSSAPI |
1125 | /* The GSSAPI key exchange can run without a host key */ | ||
1114 | if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) { | 1126 | if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) { |
1115 | logit("Disabling protocol version 2. Could not load host key"); | 1127 | logit("Disabling protocol version 2. Could not load host key"); |
1116 | options.protocol &= ~SSH_PROTO_2; | 1128 | options.protocol &= ~SSH_PROTO_2; |
@@ -1617,19 +1629,22 @@ main(int ac, char **av) | |||
1617 | signal(SIGCHLD, SIG_DFL); | 1629 | signal(SIGCHLD, SIG_DFL); |
1618 | signal(SIGINT, SIG_DFL); | 1630 | signal(SIGINT, SIG_DFL); |
1619 | 1631 | ||
1620 | /* Set SO_KEEPALIVE if requested. */ | ||
1621 | if (options.tcp_keep_alive && | ||
1622 | setsockopt(sock_in, SOL_SOCKET, SO_KEEPALIVE, &on, | ||
1623 | sizeof(on)) < 0) | ||
1624 | error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); | ||
1625 | |||
1626 | /* | 1632 | /* |
1627 | * Register our connection. This turns encryption off because we do | 1633 | * Register our connection. This turns encryption off because we do |
1628 | * not have a key. | 1634 | * not have a key. |
1629 | */ | 1635 | */ |
1630 | packet_set_connection(sock_in, sock_out); | 1636 | packet_set_connection(sock_in, sock_out); |
1637 | packet_set_server(); | ||
1638 | |||
1639 | /* Set SO_KEEPALIVE if requested. */ | ||
1640 | if (options.tcp_keep_alive && packet_connection_is_on_socket() && | ||
1641 | setsockopt(sock_in, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) < 0) | ||
1642 | error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); | ||
1631 | 1643 | ||
1632 | remote_port = get_remote_port(); | 1644 | if ((remote_port = get_remote_port()) < 0) { |
1645 | debug("get_remote_port failed"); | ||
1646 | cleanup_exit(255); | ||
1647 | } | ||
1633 | remote_ip = get_remote_ipaddr(); | 1648 | remote_ip = get_remote_ipaddr(); |
1634 | 1649 | ||
1635 | #ifdef SSH_AUDIT_EVENTS | 1650 | #ifdef SSH_AUDIT_EVENTS |
@@ -1655,6 +1670,62 @@ main(int ac, char **av) | |||
1655 | /* Log the connection. */ | 1670 | /* Log the connection. */ |
1656 | verbose("Connection from %.500s port %d", remote_ip, remote_port); | 1671 | verbose("Connection from %.500s port %d", remote_ip, remote_port); |
1657 | 1672 | ||
1673 | #ifdef USE_SECURITY_SESSION_API | ||
1674 | /* | ||
1675 | * Create a new security session for use by the new user login if | ||
1676 | * the current session is the root session or we are not launched | ||
1677 | * by inetd (eg: debugging mode or server mode). We do not | ||
1678 | * necessarily need to create a session if we are launched from | ||
1679 | * inetd because Panther xinetd will create a session for us. | ||
1680 | * | ||
1681 | * The only case where this logic will fail is if there is an | ||
1682 | * inetd running in a non-root session which is not creating | ||
1683 | * new sessions for us. Then all the users will end up in the | ||
1684 | * same session (bad). | ||
1685 | * | ||
1686 | * When the client exits, the session will be destroyed for us | ||
1687 | * automatically. | ||
1688 | * | ||
1689 | * We must create the session before any credentials are stored | ||
1690 | * (including AFS pags, which happens a few lines below). | ||
1691 | */ | ||
1692 | { | ||
1693 | OSStatus err = 0; | ||
1694 | SecuritySessionId sid = 0; | ||
1695 | SessionAttributeBits sattrs = 0; | ||
1696 | |||
1697 | err = SessionGetInfo(callerSecuritySession, &sid, &sattrs); | ||
1698 | if (err) | ||
1699 | error("SessionGetInfo() failed with error %.8X", | ||
1700 | (unsigned) err); | ||
1701 | else | ||
1702 | debug("Current Session ID is %.8X / Session Attributes a | ||
1703 | re %.8X", | ||
1704 | (unsigned) sid, (unsigned) sattrs); | ||
1705 | |||
1706 | if (inetd_flag && !(sattrs & sessionIsRoot)) | ||
1707 | debug("Running in inetd mode in a non-root session... " | ||
1708 | "assuming inetd created the session for us."); | ||
1709 | else { | ||
1710 | debug("Creating new security session..."); | ||
1711 | err = SessionCreate(0, sessionHasTTY | sessionIsRemote); | ||
1712 | if (err) | ||
1713 | error("SessionCreate() failed with error %.8X", | ||
1714 | (unsigned) err); | ||
1715 | |||
1716 | err = SessionGetInfo(callerSecuritySession, &sid, | ||
1717 | &sattrs); | ||
1718 | if (err) | ||
1719 | error("SessionGetInfo() failed with error %.8X", | ||
1720 | (unsigned) err); | ||
1721 | else | ||
1722 | debug("New Session ID is %.8X / Session Attribut | ||
1723 | es are %.8X", | ||
1724 | (unsigned) sid, (unsigned) sattrs); | ||
1725 | } | ||
1726 | } | ||
1727 | #endif | ||
1728 | |||
1658 | /* | 1729 | /* |
1659 | * We don\'t want to listen forever unless the other side | 1730 | * We don\'t want to listen forever unless the other side |
1660 | * successfully authenticates itself. So we set up an alarm which is | 1731 | * successfully authenticates itself. So we set up an alarm which is |
@@ -1675,6 +1746,8 @@ main(int ac, char **av) | |||
1675 | authctxt = xmalloc(sizeof(*authctxt)); | 1746 | authctxt = xmalloc(sizeof(*authctxt)); |
1676 | memset(authctxt, 0, sizeof(*authctxt)); | 1747 | memset(authctxt, 0, sizeof(*authctxt)); |
1677 | 1748 | ||
1749 | authctxt->loginmsg = &loginmsg; | ||
1750 | |||
1678 | /* XXX global for cleanup, access from other modules */ | 1751 | /* XXX global for cleanup, access from other modules */ |
1679 | the_authctxt = authctxt; | 1752 | the_authctxt = authctxt; |
1680 | 1753 | ||
@@ -1898,7 +1971,7 @@ do_ssh1_kex(void) | |||
1898 | if (!rsafail) { | 1971 | if (!rsafail) { |
1899 | BN_mask_bits(session_key_int, sizeof(session_key) * 8); | 1972 | BN_mask_bits(session_key_int, sizeof(session_key) * 8); |
1900 | len = BN_num_bytes(session_key_int); | 1973 | len = BN_num_bytes(session_key_int); |
1901 | if (len < 0 || len > sizeof(session_key)) { | 1974 | if (len < 0 || (u_int)len > sizeof(session_key)) { |
1902 | error("do_connection: bad session key len from %s: " | 1975 | error("do_connection: bad session key len from %s: " |
1903 | "session_key_int %d > sizeof(session_key) %lu", | 1976 | "session_key_int %d > sizeof(session_key) %lu", |
1904 | get_remote_ipaddr(), len, (u_long)sizeof(session_key)); | 1977 | get_remote_ipaddr(), len, (u_long)sizeof(session_key)); |
@@ -1985,10 +2058,14 @@ do_ssh2_kex(void) | |||
1985 | myproposal[PROPOSAL_MAC_ALGS_CTOS] = | 2058 | myproposal[PROPOSAL_MAC_ALGS_CTOS] = |
1986 | myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs; | 2059 | myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs; |
1987 | } | 2060 | } |
1988 | if (!options.compression) { | 2061 | if (options.compression == COMP_NONE) { |
1989 | myproposal[PROPOSAL_COMP_ALGS_CTOS] = | 2062 | myproposal[PROPOSAL_COMP_ALGS_CTOS] = |
1990 | myproposal[PROPOSAL_COMP_ALGS_STOC] = "none"; | 2063 | myproposal[PROPOSAL_COMP_ALGS_STOC] = "none"; |
2064 | } else if (options.compression == COMP_DELAYED) { | ||
2065 | myproposal[PROPOSAL_COMP_ALGS_CTOS] = | ||
2066 | myproposal[PROPOSAL_COMP_ALGS_STOC] = "none,zlib@openssh.com"; | ||
1991 | } | 2067 | } |
2068 | |||
1992 | myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types(); | 2069 | myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types(); |
1993 | 2070 | ||
1994 | /* start key exchange */ | 2071 | /* start key exchange */ |
@@ -2008,7 +2085,10 @@ do_ssh2_kex(void) | |||
2008 | if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0) | 2085 | if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0) |
2009 | orig = NULL; | 2086 | orig = NULL; |
2010 | 2087 | ||
2011 | gss = ssh_gssapi_server_mechanisms(); | 2088 | if (options.gss_keyex) |
2089 | gss = ssh_gssapi_server_mechanisms(); | ||
2090 | else | ||
2091 | gss = NULL; | ||
2012 | 2092 | ||
2013 | if (gss && orig) { | 2093 | if (gss && orig) { |
2014 | int len = strlen(orig) + strlen(gss) + 2; | 2094 | int len = strlen(orig) + strlen(gss) + 2; |
@@ -2041,6 +2121,7 @@ do_ssh2_kex(void) | |||
2041 | kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; | 2121 | kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; |
2042 | #ifdef GSSAPI | 2122 | #ifdef GSSAPI |
2043 | kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server; | 2123 | kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server; |
2124 | kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server; | ||
2044 | #endif | 2125 | #endif |
2045 | kex->server = 1; | 2126 | kex->server = 1; |
2046 | kex->client_version_string=client_version_string; | 2127 | kex->client_version_string=client_version_string; |