summaryrefslogtreecommitdiff
path: root/sshd.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshd.c')
-rw-r--r--sshd.c119
1 files changed, 116 insertions, 3 deletions
diff --git a/sshd.c b/sshd.c
index 04778ea99..add61cc5f 100644
--- a/sshd.c
+++ b/sshd.c
@@ -117,6 +117,10 @@
117#include "monitor_fdpass.h" 117#include "monitor_fdpass.h"
118#include "version.h" 118#include "version.h"
119 119
120#ifdef USE_SECURITY_SESSION_API
121#include <Security/AuthSession.h>
122#endif
123
120#ifdef LIBWRAP 124#ifdef LIBWRAP
121#include <tcpd.h> 125#include <tcpd.h>
122#include <syslog.h> 126#include <syslog.h>
@@ -419,7 +423,7 @@ sshd_exchange_identification(int sock_in, int sock_out)
419 major = PROTOCOL_MAJOR_1; 423 major = PROTOCOL_MAJOR_1;
420 minor = PROTOCOL_MINOR_1; 424 minor = PROTOCOL_MINOR_1;
421 } 425 }
422 snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n", major, minor, SSH_VERSION); 426 snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n", major, minor, SSH_RELEASE);
423 server_version_string = xstrdup(buf); 427 server_version_string = xstrdup(buf);
424 428
425 /* Send our protocol version identification. */ 429 /* Send our protocol version identification. */
@@ -1305,7 +1309,12 @@ main(int ac, char **av)
1305 /* ignored */ 1309 /* ignored */
1306 break; 1310 break;
1307 case 'q': 1311 case 'q':
1308 options.log_level = SYSLOG_LEVEL_QUIET; 1312 if (options.log_level == SYSLOG_LEVEL_QUIET) {
1313 options.log_level = SYSLOG_LEVEL_SILENT;
1314 }
1315 else if (options.log_level != SYSLOG_LEVEL_SILENT) {
1316 options.log_level = SYSLOG_LEVEL_QUIET;
1317 }
1309 break; 1318 break;
1310 case 'b': 1319 case 'b':
1311 options.server_key_bits = (int)strtonum(optarg, 256, 1320 options.server_key_bits = (int)strtonum(optarg, 256,
@@ -1481,10 +1490,13 @@ main(int ac, char **av)
1481 logit("Disabling protocol version 1. Could not load host key"); 1490 logit("Disabling protocol version 1. Could not load host key");
1482 options.protocol &= ~SSH_PROTO_1; 1491 options.protocol &= ~SSH_PROTO_1;
1483 } 1492 }
1493#ifndef GSSAPI
1494 /* The GSSAPI key exchange can run without a host key */
1484 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) { 1495 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) {
1485 logit("Disabling protocol version 2. Could not load host key"); 1496 logit("Disabling protocol version 2. Could not load host key");
1486 options.protocol &= ~SSH_PROTO_2; 1497 options.protocol &= ~SSH_PROTO_2;
1487 } 1498 }
1499#endif
1488 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) { 1500 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) {
1489 logit("sshd: no hostkeys available -- exiting."); 1501 logit("sshd: no hostkeys available -- exiting.");
1490 exit(1); 1502 exit(1);
@@ -1711,7 +1723,7 @@ main(int ac, char **av)
1711 * Register our connection. This turns encryption off because we do 1723 * Register our connection. This turns encryption off because we do
1712 * not have a key. 1724 * not have a key.
1713 */ 1725 */
1714 packet_set_connection(sock_in, sock_out); 1726 packet_set_connection(sock_in, sock_out, -1);
1715 packet_set_server(); 1727 packet_set_server();
1716 1728
1717 /* Set SO_KEEPALIVE if requested. */ 1729 /* Set SO_KEEPALIVE if requested. */
@@ -1759,6 +1771,60 @@ main(int ac, char **av)
1759 /* Log the connection. */ 1771 /* Log the connection. */
1760 verbose("Connection from %.500s port %d", remote_ip, remote_port); 1772 verbose("Connection from %.500s port %d", remote_ip, remote_port);
1761 1773
1774#ifdef USE_SECURITY_SESSION_API
1775 /*
1776 * Create a new security session for use by the new user login if
1777 * the current session is the root session or we are not launched
1778 * by inetd (eg: debugging mode or server mode). We do not
1779 * necessarily need to create a session if we are launched from
1780 * inetd because Panther xinetd will create a session for us.
1781 *
1782 * The only case where this logic will fail is if there is an
1783 * inetd running in a non-root session which is not creating
1784 * new sessions for us. Then all the users will end up in the
1785 * same session (bad).
1786 *
1787 * When the client exits, the session will be destroyed for us
1788 * automatically.
1789 *
1790 * We must create the session before any credentials are stored
1791 * (including AFS pags, which happens a few lines below).
1792 */
1793 {
1794 OSStatus err = 0;
1795 SecuritySessionId sid = 0;
1796 SessionAttributeBits sattrs = 0;
1797
1798 err = SessionGetInfo(callerSecuritySession, &sid, &sattrs);
1799 if (err)
1800 error("SessionGetInfo() failed with error %.8X",
1801 (unsigned) err);
1802 else
1803 debug("Current Session ID is %.8X / Session Attributes are %.8X",
1804 (unsigned) sid, (unsigned) sattrs);
1805
1806 if (inetd_flag && !(sattrs & sessionIsRoot))
1807 debug("Running in inetd mode in a non-root session... "
1808 "assuming inetd created the session for us.");
1809 else {
1810 debug("Creating new security session...");
1811 err = SessionCreate(0, sessionHasTTY | sessionIsRemote);
1812 if (err)
1813 error("SessionCreate() failed with error %.8X",
1814 (unsigned) err);
1815
1816 err = SessionGetInfo(callerSecuritySession, &sid,
1817 &sattrs);
1818 if (err)
1819 error("SessionGetInfo() failed with error %.8X",
1820 (unsigned) err);
1821 else
1822 debug("New Session ID is %.8X / Session Attributes are %.8X",
1823 (unsigned) sid, (unsigned) sattrs);
1824 }
1825 }
1826#endif
1827
1762 /* 1828 /*
1763 * We don't want to listen forever unless the other side 1829 * We don't want to listen forever unless the other side
1764 * successfully authenticates itself. So we set up an alarm which is 1830 * successfully authenticates itself. So we set up an alarm which is
@@ -2117,12 +2183,59 @@ do_ssh2_kex(void)
2117 2183
2118 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types(); 2184 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types();
2119 2185
2186#ifdef GSSAPI
2187 {
2188 char *orig;
2189 char *gss = NULL;
2190 char *newstr = NULL;
2191 orig = myproposal[PROPOSAL_KEX_ALGS];
2192
2193 /*
2194 * If we don't have a host key, then there's no point advertising
2195 * the other key exchange algorithms
2196 */
2197
2198 if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
2199 orig = NULL;
2200
2201 if (options.gss_keyex)
2202 gss = ssh_gssapi_server_mechanisms();
2203 else
2204 gss = NULL;
2205
2206 if (gss && orig)
2207 xasprintf(&newstr, "%s,%s", gss, orig);
2208 else if (gss)
2209 newstr = gss;
2210 else if (orig)
2211 newstr = orig;
2212
2213 /*
2214 * If we've got GSSAPI mechanisms, then we've got the 'null' host
2215 * key alg, but we can't tell people about it unless its the only
2216 * host key algorithm we support
2217 */
2218 if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0)
2219 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null";
2220
2221 if (newstr)
2222 myproposal[PROPOSAL_KEX_ALGS] = newstr;
2223 else
2224 fatal("No supported key exchange algorithms");
2225 }
2226#endif
2227
2120 /* start key exchange */ 2228 /* start key exchange */
2121 kex = kex_setup(myproposal); 2229 kex = kex_setup(myproposal);
2122 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; 2230 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
2123 kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server; 2231 kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
2124 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; 2232 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2125 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; 2233 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2234#ifdef GSSAPI
2235 kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
2236 kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
2237 kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
2238#endif
2126 kex->server = 1; 2239 kex->server = 1;
2127 kex->client_version_string=client_version_string; 2240 kex->client_version_string=client_version_string;
2128 kex->server_version_string=server_version_string; 2241 kex->server_version_string=server_version_string;