1 /* $OpenBSD: sshd.c,v 1.420 2014/02/26 21:53:37 markus Exp $ */
3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 * This program is the ssh daemon. It listens for connections from clients,
7 * and performs authentication, executes use commands or shell, and forwards
8 * information to/from the application to the user client over an encrypted
9 * connection. This can also handle forwarding of X11, TCP/IP, and
10 * authentication agent connections.
12 * As far as I am concerned, the code I have written for this software
13 * can be used freely for any purpose. Any derived versions of this
14 * software must be clearly marked as such, and if the derived work is
15 * incompatible with the protocol description in the RFC file, it must be
16 * called by a name other than "ssh" or "Secure Shell".
18 * SSH2 implementation:
19 * Privilege Separation:
21 * Copyright (c) 2000, 2001, 2002 Markus Friedl. All rights reserved.
22 * Copyright (c) 2002 Niels Provos. All rights reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
33 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
38 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #include <sys/types.h>
49 #include <sys/ioctl.h>
51 #include <sys/socket.h>
52 #ifdef HAVE_SYS_STAT_H
53 # include <sys/stat.h>
55 #ifdef HAVE_SYS_TIME_H
56 # include <sys/time.h>
58 #include "openbsd-compat/sys-tree.h"
59 #include "openbsd-compat/sys-queue.h"
77 #include <openssl/dh.h>
78 #include <openssl/bn.h>
79 #include <openssl/rand.h>
80 #include "openbsd-compat/openssl-compat.h"
82 #ifdef HAVE_SECUREWARE
83 #include <sys/security.h>
89 #if defined(GSSAPI) && defined(HAVE_GSSAPI_GSSAPI_H)
90 #include <gssapi/gssapi.h>
91 #elif defined(GSSAPI) && defined(HAVE_GSSAPI_H)
105 #include "servconf.h"
113 #include "myproposal.h"
114 #include "authfile.h"
115 #include "pathnames.h"
116 #include "atomicio.h"
117 #include "canohost.h"
118 #include "hostfile.h"
123 #include "dispatch.h"
124 #include "channels.h"
126 #include "monitor_mm.h"
131 #include "monitor_wrap.h"
133 #include "ssh-sandbox.h"
148 #define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1)
149 #define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2)
150 #define REEXEC_CONFIG_PASS_FD (STDERR_FILENO + 3)
151 #define REEXEC_MIN_FREE_FD (STDERR_FILENO + 4)
153 extern char *__progname;
155 /* Server configuration options. */
156 ServerOptions options;
158 /* Name of the server configuration file. */
159 char *config_file_name = _PATH_SERVER_CONFIG_FILE;
162 * Debug mode flag. This can be set on the command line. If debug
163 * mode is enabled, extra debugging output will be sent to the system
164 * log, the daemon will not go to background, and will exit after processing
165 * the first connection.
169 /* Flag indicating that the daemon should only test the configuration and keys. */
172 /* Flag indicating that the daemon is being started from inetd. */
175 /* Flag indicating that sshd should not detach and become a daemon. */
176 int no_daemon_flag = 0;
178 /* debug goes to stderr unless inetd_flag is set */
181 /* Saved arguments to main(). */
186 int rexeced_flag = 0;
192 * The sockets that the server is listening; this is used in the SIGHUP
195 #define MAX_LISTEN_SOCKS 16
196 int listen_socks[MAX_LISTEN_SOCKS];
197 int num_listen_socks = 0;
200 * the client's version string, passed by sshd2 in compat mode. if != NULL,
201 * sshd will skip the version-number exchange
203 char *client_version_string = NULL;
204 char *server_version_string = NULL;
206 /* for rekeying XXX fixme */
209 /* Daemon's agent connection */
210 AuthenticationConnection *auth_conn = NULL;
214 * Any really sensitive data in the application is contained in this
215 * structure. The idea is that this structure could be locked into memory so
216 * that the pages do not get written into swap. However, there are some
217 * problems. The private key contains BIGNUMs, and we do not (in principle)
218 * have access to the internals of them, and locking just the structure is
219 * not very useful. Currently, memory locking is not implemented.
222 Key *server_key; /* ephemeral server key */
223 Key *ssh1_host_key; /* ssh1 host key */
224 Key **host_keys; /* all private host keys */
225 Key **host_pubkeys; /* all public host keys */
226 Key **host_certificates; /* all public host certificates */
229 u_char ssh1_cookie[SSH_SESSION_KEY_LENGTH];
233 * Flag indicating whether the RSA server key needs to be regenerated.
234 * Is set in the SIGALRM handler and cleared when the key is regenerated.
236 static volatile sig_atomic_t key_do_regen = 0;
238 /* This is set to true when a signal is received. */
239 static volatile sig_atomic_t received_sighup = 0;
240 static volatile sig_atomic_t received_sigterm = 0;
242 /* session identifier, used by RSA-auth */
243 u_char session_id[16];
246 u_char *session_id2 = NULL;
247 u_int session_id2_len = 0;
249 /* record remote hostname or ip */
250 u_int utmp_len = MAXHOSTNAMELEN;
252 /* options.max_startup sized array of fd ints */
253 int *startup_pipes = NULL;
254 int startup_pipe; /* in child */
256 /* variables used for privilege separation */
257 int use_privsep = -1;
258 struct monitor *pmonitor = NULL;
259 int privsep_is_preauth = 1;
261 /* global authentication context */
262 Authctxt *the_authctxt = NULL;
264 /* sshd_config buffer */
267 /* message to be displayed after login */
270 /* Unprivileged user */
271 struct passwd *privsep_pw = NULL;
273 /* Prototypes for various functions defined later in this file. */
274 void destroy_sensitive_data(void);
275 void demote_sensitive_data(void);
277 static void do_ssh1_kex(void);
278 static void do_ssh2_kex(void);
281 * Close all listening sockets
284 close_listen_socks(void)
288 for (i = 0; i < num_listen_socks; i++)
289 close(listen_socks[i]);
290 num_listen_socks = -1;
294 close_startup_pipes(void)
299 for (i = 0; i < options.max_startups; i++)
300 if (startup_pipes[i] != -1)
301 close(startup_pipes[i]);
305 * Signal handler for SIGHUP. Sshd execs itself when it receives SIGHUP;
306 * the effect is to reread the configuration file (and to regenerate
312 sighup_handler(int sig)
314 int save_errno = errno;
317 signal(SIGHUP, sighup_handler);
322 * Called from the main program after receiving SIGHUP.
323 * Restarts the server.
328 logit("Received SIGHUP; restarting.");
329 platform_pre_restart();
330 close_listen_socks();
331 close_startup_pipes();
332 alarm(0); /* alarm timer persists across exec */
333 signal(SIGHUP, SIG_IGN); /* will be restored after exec */
334 execv(saved_argv[0], saved_argv);
335 logit("RESTART FAILED: av[0]='%.100s', error: %.100s.", saved_argv[0],
341 * Generic signal handler for terminating signals in the master daemon.
345 sigterm_handler(int sig)
347 received_sigterm = sig;
351 * SIGCHLD handler. This is called whenever a child dies. This will then
352 * reap any zombies left by exited children.
356 main_sigchld_handler(int sig)
358 int save_errno = errno;
362 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
363 (pid < 0 && errno == EINTR))
366 signal(SIGCHLD, main_sigchld_handler);
371 * Signal handler for the alarm after the login grace period has expired.
375 grace_alarm_handler(int sig)
377 if (use_privsep && pmonitor != NULL && pmonitor->m_pid > 0)
378 kill(pmonitor->m_pid, SIGALRM);
381 * Try to kill any processes that we have spawned, E.g. authorized
382 * keys command helpers.
384 if (getpgid(0) == getpid()) {
385 signal(SIGTERM, SIG_IGN);
389 /* Log error and exit. */
390 sigdie("Timeout before authentication for %s", get_remote_ipaddr());
394 * Signal handler for the key regeneration alarm. Note that this
395 * alarm only occurs in the daemon waiting for connections, and it does not
396 * do anything with the private key or random state before forking.
397 * Thus there should be no concurrency control/asynchronous execution
401 generate_ephemeral_server_key(void)
403 verbose("Generating %s%d bit RSA key.",
404 sensitive_data.server_key ? "new " : "", options.server_key_bits);
405 if (sensitive_data.server_key != NULL)
406 key_free(sensitive_data.server_key);
407 sensitive_data.server_key = key_generate(KEY_RSA1,
408 options.server_key_bits);
409 verbose("RSA key generation complete.");
411 arc4random_buf(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH);
416 key_regeneration_alarm(int sig)
418 int save_errno = errno;
420 signal(SIGALRM, SIG_DFL);
426 sshd_exchange_identification(int sock_in, int sock_out)
430 int remote_major, remote_minor;
432 char *s, *newline = "\n";
433 char buf[256]; /* Must not be larger than remote_version. */
434 char remote_version[256]; /* Must be at least as big as buf. */
436 if ((options.protocol & SSH_PROTO_1) &&
437 (options.protocol & SSH_PROTO_2)) {
438 major = PROTOCOL_MAJOR_1;
440 } else if (options.protocol & SSH_PROTO_2) {
441 major = PROTOCOL_MAJOR_2;
442 minor = PROTOCOL_MINOR_2;
445 major = PROTOCOL_MAJOR_1;
446 minor = PROTOCOL_MINOR_1;
449 xasprintf(&server_version_string, "SSH-%d.%d-%.100s%s%s%s%s",
450 major, minor, SSH_VERSION,
451 options.hpn_disabled ? "" : SSH_VERSION_HPN,
452 *options.version_addendum == '\0' ? "" : " ",
453 options.version_addendum, newline);
455 /* Send our protocol version identification. */
456 if (roaming_atomicio(vwrite, sock_out, server_version_string,
457 strlen(server_version_string))
458 != strlen(server_version_string)) {
459 logit("Could not write ident string to %s", get_remote_ipaddr());
463 /* Read other sides version identification. */
464 memset(buf, 0, sizeof(buf));
465 for (i = 0; i < sizeof(buf) - 1; i++) {
466 if (roaming_atomicio(read, sock_in, &buf[i], 1) != 1) {
467 logit("Did not receive identification string from %s",
468 get_remote_ipaddr());
471 if (buf[i] == '\r') {
473 /* Kludge for F-Secure Macintosh < 1.0.2 */
475 strncmp(buf, "SSH-1.5-W1.0", 12) == 0)
479 if (buf[i] == '\n') {
484 buf[sizeof(buf) - 1] = 0;
485 client_version_string = xstrdup(buf);
488 * Check that the versions match. In future this might accept
489 * several versions and set appropriate flags to handle them.
491 if (sscanf(client_version_string, "SSH-%d.%d-%[^\n]\n",
492 &remote_major, &remote_minor, remote_version) != 3) {
493 s = "Protocol mismatch.\n";
494 (void) atomicio(vwrite, sock_out, s, strlen(s));
495 logit("Bad protocol version identification '%.100s' "
496 "from %s port %d", client_version_string,
497 get_remote_ipaddr(), get_remote_port());
502 debug("Client protocol version %d.%d; client software version %.100s",
503 remote_major, remote_minor, remote_version);
505 compat_datafellows(remote_version);
507 if ((datafellows & SSH_BUG_PROBE) != 0) {
508 logit("probed from %s with %s. Don't panic.",
509 get_remote_ipaddr(), client_version_string);
512 if ((datafellows & SSH_BUG_SCANNER) != 0) {
513 logit("scanned from %s with %s. Don't panic.",
514 get_remote_ipaddr(), client_version_string);
517 if ((datafellows & SSH_BUG_RSASIGMD5) != 0) {
518 logit("Client version \"%.100s\" uses unsafe RSA signature "
519 "scheme; disabling use of RSA keys", remote_version);
521 if ((datafellows & SSH_BUG_DERIVEKEY) != 0) {
522 fatal("Client version \"%.100s\" uses unsafe key agreement; "
523 "refusing connection", remote_version);
527 switch (remote_major) {
529 if (remote_minor == 99) {
530 if (options.protocol & SSH_PROTO_2)
536 if (!(options.protocol & SSH_PROTO_1)) {
540 if (remote_minor < 3) {
541 packet_disconnect("Your ssh version is too old and "
542 "is no longer supported. Please install a newer version.");
543 } else if (remote_minor == 3) {
544 /* note that this disables agent-forwarding */
549 if (options.protocol & SSH_PROTO_2) {
558 chop(server_version_string);
559 debug("Local version string %.200s", server_version_string);
562 s = "Protocol major versions differ.\n";
563 (void) atomicio(vwrite, sock_out, s, strlen(s));
566 logit("Protocol major versions differ for %s: %.200s vs. %.200s",
568 server_version_string, client_version_string);
573 /* Destroy the host and server keys. They will no longer be needed. */
575 destroy_sensitive_data(void)
579 if (sensitive_data.server_key) {
580 key_free(sensitive_data.server_key);
581 sensitive_data.server_key = NULL;
583 for (i = 0; i < options.num_host_key_files; i++) {
584 if (sensitive_data.host_keys[i]) {
585 key_free(sensitive_data.host_keys[i]);
586 sensitive_data.host_keys[i] = NULL;
588 if (sensitive_data.host_certificates[i]) {
589 key_free(sensitive_data.host_certificates[i]);
590 sensitive_data.host_certificates[i] = NULL;
593 sensitive_data.ssh1_host_key = NULL;
594 explicit_bzero(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH);
597 /* Demote private to public keys for network child */
599 demote_sensitive_data(void)
604 if (sensitive_data.server_key) {
605 tmp = key_demote(sensitive_data.server_key);
606 key_free(sensitive_data.server_key);
607 sensitive_data.server_key = tmp;
610 for (i = 0; i < options.num_host_key_files; i++) {
611 if (sensitive_data.host_keys[i]) {
612 tmp = key_demote(sensitive_data.host_keys[i]);
613 key_free(sensitive_data.host_keys[i]);
614 sensitive_data.host_keys[i] = tmp;
615 if (tmp->type == KEY_RSA1)
616 sensitive_data.ssh1_host_key = tmp;
618 /* Certs do not need demotion */
621 /* We do not clear ssh1_host key and cookie. XXX - Okay Niels? */
625 privsep_preauth_child(void)
630 /* Enable challenge-response authentication for privilege separation */
631 privsep_challenge_enable();
634 /* Cache supported mechanism OIDs for later use */
635 if (options.gss_authentication)
636 ssh_gssapi_prepare_supported_oids();
640 arc4random_buf(rnd, sizeof(rnd));
641 RAND_seed(rnd, sizeof(rnd));
642 explicit_bzero(rnd, sizeof(rnd));
644 /* Demote the private keys to public keys. */
645 demote_sensitive_data();
647 /* Change our root directory */
648 if (chroot(_PATH_PRIVSEP_CHROOT_DIR) == -1)
649 fatal("chroot(\"%s\"): %s", _PATH_PRIVSEP_CHROOT_DIR,
651 if (chdir("/") == -1)
652 fatal("chdir(\"/\"): %s", strerror(errno));
654 /* Drop our privileges */
655 debug3("privsep user:group %u:%u", (u_int)privsep_pw->pw_uid,
656 (u_int)privsep_pw->pw_gid);
658 /* XXX not ready, too heavy after chroot */
659 do_setusercontext(privsep_pw);
661 gidset[0] = privsep_pw->pw_gid;
662 if (setgroups(1, gidset) < 0)
663 fatal("setgroups: %.100s", strerror(errno));
664 permanently_set_uid(privsep_pw);
669 privsep_preauth(Authctxt *authctxt)
673 struct ssh_sandbox *box = NULL;
675 /* Set up unprivileged child process to deal with network data */
676 pmonitor = monitor_init();
677 /* Store a pointer to the kex for later rekeying */
678 pmonitor->m_pkex = &xxx_kex;
680 if (use_privsep == PRIVSEP_ON)
681 box = ssh_sandbox_init(pmonitor);
684 fatal("fork of unprivileged child failed");
685 } else if (pid != 0) {
686 debug2("Network child is on pid %ld", (long)pid);
688 pmonitor->m_pid = pid;
690 auth_conn = ssh_get_authentication_connection();
692 ssh_sandbox_parent_preauth(box, pid);
693 monitor_child_preauth(authctxt, pmonitor);
696 monitor_sync(pmonitor);
698 /* Wait for the child's exit status */
699 while (waitpid(pid, &status, 0) < 0) {
702 pmonitor->m_pid = -1;
703 fatal("%s: waitpid: %s", __func__, strerror(errno));
705 privsep_is_preauth = 0;
706 pmonitor->m_pid = -1;
707 if (WIFEXITED(status)) {
708 if (WEXITSTATUS(status) != 0)
709 fatal("%s: preauth child exited with status %d",
710 __func__, WEXITSTATUS(status));
711 } else if (WIFSIGNALED(status))
712 fatal("%s: preauth child terminated by signal %d",
713 __func__, WTERMSIG(status));
715 ssh_sandbox_parent_finish(box);
719 close(pmonitor->m_sendfd);
720 close(pmonitor->m_log_recvfd);
722 /* Arrange for logging to be sent to the monitor */
723 set_log_handler(mm_log_handler, pmonitor);
725 /* Demote the child */
726 if (getuid() == 0 || geteuid() == 0)
727 privsep_preauth_child();
728 setproctitle("%s", "[net]");
730 ssh_sandbox_child(box);
737 privsep_postauth(Authctxt *authctxt)
741 #ifdef DISABLE_FD_PASSING
744 if (authctxt->pw->pw_uid == 0 || options.use_login) {
746 /* File descriptor passing is broken or root login */
751 /* New socket pair */
752 monitor_reinit(pmonitor);
754 pmonitor->m_pid = fork();
755 if (pmonitor->m_pid == -1)
756 fatal("fork of unprivileged child failed");
757 else if (pmonitor->m_pid != 0) {
758 verbose("User child is on pid %ld", (long)pmonitor->m_pid);
759 buffer_clear(&loginmsg);
760 monitor_child_postauth(pmonitor);
768 close(pmonitor->m_sendfd);
769 pmonitor->m_sendfd = -1;
771 /* Demote the private keys to public keys. */
772 demote_sensitive_data();
775 arc4random_buf(rnd, sizeof(rnd));
776 RAND_seed(rnd, sizeof(rnd));
777 explicit_bzero(rnd, sizeof(rnd));
779 /* Drop privileges */
780 do_setusercontext(authctxt->pw);
783 /* It is safe now to apply the key state */
784 monitor_apply_keystate(pmonitor);
787 * Tell the packet layer that authentication was successful, since
788 * this information is not part of the key state.
790 packet_set_authenticated();
794 list_hostkey_types(void)
803 for (i = 0; i < options.num_host_key_files; i++) {
804 key = sensitive_data.host_keys[i];
806 key = sensitive_data.host_pubkeys[i];
814 if (buffer_len(&b) > 0)
815 buffer_append(&b, ",", 1);
816 p = key_ssh_name(key);
817 buffer_append(&b, p, strlen(p));
820 /* If the private key has a cert peer, then list that too */
821 key = sensitive_data.host_certificates[i];
825 case KEY_RSA_CERT_V00:
826 case KEY_DSA_CERT_V00:
830 case KEY_ED25519_CERT:
831 if (buffer_len(&b) > 0)
832 buffer_append(&b, ",", 1);
833 p = key_ssh_name(key);
834 buffer_append(&b, p, strlen(p));
838 buffer_append(&b, "\0", 1);
839 ret = xstrdup(buffer_ptr(&b));
841 debug("list_hostkey_types: %s", ret);
846 get_hostkey_by_type(int type, int need_private)
851 for (i = 0; i < options.num_host_key_files; i++) {
853 case KEY_RSA_CERT_V00:
854 case KEY_DSA_CERT_V00:
858 case KEY_ED25519_CERT:
859 key = sensitive_data.host_certificates[i];
862 key = sensitive_data.host_keys[i];
863 if (key == NULL && !need_private)
864 key = sensitive_data.host_pubkeys[i];
867 if (key != NULL && key->type == type)
868 return need_private ?
869 sensitive_data.host_keys[i] : key;
875 get_hostkey_public_by_type(int type)
877 return get_hostkey_by_type(type, 0);
881 get_hostkey_private_by_type(int type)
883 return get_hostkey_by_type(type, 1);
887 get_hostkey_by_index(int ind)
889 if (ind < 0 || ind >= options.num_host_key_files)
891 return (sensitive_data.host_keys[ind]);
895 get_hostkey_public_by_index(int ind)
897 if (ind < 0 || ind >= options.num_host_key_files)
899 return (sensitive_data.host_pubkeys[ind]);
903 get_hostkey_index(Key *key)
907 for (i = 0; i < options.num_host_key_files; i++) {
908 if (key_is_cert(key)) {
909 if (key == sensitive_data.host_certificates[i])
912 if (key == sensitive_data.host_keys[i])
914 if (key == sensitive_data.host_pubkeys[i])
922 * returns 1 if connection should be dropped, 0 otherwise.
923 * dropping starts at connection #max_startups_begin with a probability
924 * of (max_startups_rate/100). the probability increases linearly until
925 * all connections are dropped for startups > max_startups
928 drop_connection(int startups)
932 if (startups < options.max_startups_begin)
934 if (startups >= options.max_startups)
936 if (options.max_startups_rate == 100)
939 p = 100 - options.max_startups_rate;
940 p *= startups - options.max_startups_begin;
941 p /= options.max_startups - options.max_startups_begin;
942 p += options.max_startups_rate;
943 r = arc4random_uniform(100);
945 debug("drop_connection: p %d, r %d", p, r);
946 return (r < p) ? 1 : 0;
952 if (options.version_addendum && *options.version_addendum != '\0')
953 fprintf(stderr, "%s%s %s, %s\n",
954 SSH_RELEASE, options.hpn_disabled ? "" : SSH_VERSION_HPN,
955 options.version_addendum, SSLeay_version(SSLEAY_VERSION));
957 fprintf(stderr, "%s%s, %s\n",
958 SSH_RELEASE, options.hpn_disabled ? "" : SSH_VERSION_HPN,
959 SSLeay_version(SSLEAY_VERSION));
961 "usage: sshd [-46DdeiqTt] [-b bits] [-C connection_spec] [-c host_cert_file]\n"
962 " [-E log_file] [-f config_file] [-g login_grace_time]\n"
963 " [-h host_key_file] [-k key_gen_time] [-o option] [-p port]\n"
970 send_rexec_state(int fd, Buffer *conf)
974 debug3("%s: entering fd = %d config len %d", __func__, fd,
978 * Protocol from reexec master to child:
979 * string configuration
980 * u_int ephemeral_key_follows
981 * bignum e (only if ephemeral_key_follows == 1)
987 * string rngseed (only if OpenSSL is not self-seeded)
990 buffer_put_cstring(&m, buffer_ptr(conf));
992 if (sensitive_data.server_key != NULL &&
993 sensitive_data.server_key->type == KEY_RSA1) {
994 buffer_put_int(&m, 1);
995 buffer_put_bignum(&m, sensitive_data.server_key->rsa->e);
996 buffer_put_bignum(&m, sensitive_data.server_key->rsa->n);
997 buffer_put_bignum(&m, sensitive_data.server_key->rsa->d);
998 buffer_put_bignum(&m, sensitive_data.server_key->rsa->iqmp);
999 buffer_put_bignum(&m, sensitive_data.server_key->rsa->p);
1000 buffer_put_bignum(&m, sensitive_data.server_key->rsa->q);
1002 buffer_put_int(&m, 0);
1004 #ifndef OPENSSL_PRNG_ONLY
1005 rexec_send_rng_seed(&m);
1008 if (ssh_msg_send(fd, 0, &m) == -1)
1009 fatal("%s: ssh_msg_send failed", __func__);
1013 debug3("%s: done", __func__);
1017 recv_rexec_state(int fd, Buffer *conf)
1023 debug3("%s: entering fd = %d", __func__, fd);
1027 if (ssh_msg_recv(fd, &m) == -1)
1028 fatal("%s: ssh_msg_recv failed", __func__);
1029 if (buffer_get_char(&m) != 0)
1030 fatal("%s: rexec version mismatch", __func__);
1032 cp = buffer_get_string(&m, &len);
1034 buffer_append(conf, cp, len + 1);
1037 if (buffer_get_int(&m)) {
1038 if (sensitive_data.server_key != NULL)
1039 key_free(sensitive_data.server_key);
1040 sensitive_data.server_key = key_new_private(KEY_RSA1);
1041 buffer_get_bignum(&m, sensitive_data.server_key->rsa->e);
1042 buffer_get_bignum(&m, sensitive_data.server_key->rsa->n);
1043 buffer_get_bignum(&m, sensitive_data.server_key->rsa->d);
1044 buffer_get_bignum(&m, sensitive_data.server_key->rsa->iqmp);
1045 buffer_get_bignum(&m, sensitive_data.server_key->rsa->p);
1046 buffer_get_bignum(&m, sensitive_data.server_key->rsa->q);
1047 rsa_generate_additional_parameters(
1048 sensitive_data.server_key->rsa);
1051 #ifndef OPENSSL_PRNG_ONLY
1052 rexec_recv_rng_seed(&m);
1057 debug3("%s: done", __func__);
1060 /* Accept a connection from inetd */
1062 server_accept_inetd(int *sock_in, int *sock_out)
1068 close(REEXEC_CONFIG_PASS_FD);
1069 *sock_in = *sock_out = dup(STDIN_FILENO);
1071 startup_pipe = dup(REEXEC_STARTUP_PIPE_FD);
1072 close(REEXEC_STARTUP_PIPE_FD);
1075 *sock_in = dup(STDIN_FILENO);
1076 *sock_out = dup(STDOUT_FILENO);
1079 * We intentionally do not close the descriptors 0, 1, and 2
1080 * as our code for setting the descriptors won't work if
1081 * ttyfd happens to be one of those.
1083 if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
1084 dup2(fd, STDIN_FILENO);
1085 dup2(fd, STDOUT_FILENO);
1087 dup2(fd, STDERR_FILENO);
1088 if (fd > (log_stderr ? STDERR_FILENO : STDOUT_FILENO))
1091 debug("inetd sockets after dupping: %d, %d", *sock_in, *sock_out);
1095 * Listen for TCP connections
1100 int ret, listen_sock, on = 1;
1101 struct addrinfo *ai;
1102 char ntop[NI_MAXHOST], strport[NI_MAXSERV];
1106 for (ai = options.listen_addrs; ai; ai = ai->ai_next) {
1107 if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
1109 if (num_listen_socks >= MAX_LISTEN_SOCKS)
1110 fatal("Too many listen sockets. "
1111 "Enlarge MAX_LISTEN_SOCKS");
1112 if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen,
1113 ntop, sizeof(ntop), strport, sizeof(strport),
1114 NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1115 error("getnameinfo failed: %.100s",
1116 ssh_gai_strerror(ret));
1119 /* Create socket for listening. */
1120 listen_sock = socket(ai->ai_family, ai->ai_socktype,
1122 if (listen_sock < 0) {
1123 /* kernel may not support ipv6 */
1124 verbose("socket: %.100s", strerror(errno));
1127 if (set_nonblock(listen_sock) == -1) {
1132 * Set socket options.
1133 * Allow local port reuse in TIME_WAIT.
1135 if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR,
1136 &on, sizeof(on)) == -1)
1137 error("setsockopt SO_REUSEADDR: %s", strerror(errno));
1139 /* Only communicate in IPv6 over AF_INET6 sockets. */
1140 if (ai->ai_family == AF_INET6)
1141 sock_set_v6only(listen_sock);
1143 debug("Bind to port %s on %s.", strport, ntop);
1145 len = sizeof(socksize);
1146 getsockopt(listen_sock, SOL_SOCKET, SO_RCVBUF, &socksize, &len);
1147 debug("Server TCP RWIN socket size: %d", socksize);
1148 debug("HPN Buffer Size: %d", options.hpn_buffer_size);
1150 /* Bind the socket to the desired port. */
1151 if (bind(listen_sock, ai->ai_addr, ai->ai_addrlen) < 0) {
1152 error("Bind to port %s on %s failed: %.200s.",
1153 strport, ntop, strerror(errno));
1157 listen_socks[num_listen_socks] = listen_sock;
1160 /* Start listening on the port. */
1161 if (listen(listen_sock, SSH_LISTEN_BACKLOG) < 0)
1162 fatal("listen on [%s]:%s: %.100s",
1163 ntop, strport, strerror(errno));
1164 logit("Server listening on %s port %s.", ntop, strport);
1166 freeaddrinfo(options.listen_addrs);
1168 if (!num_listen_socks)
1169 fatal("Cannot bind any address.");
1173 * The main TCP accept loop. Note that, for the non-debug case, returns
1174 * from this function are in a forked subprocess.
1177 server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1180 int i, j, ret, maxfd;
1181 int key_used = 0, startups = 0;
1182 int startup_p[2] = { -1 , -1 };
1183 struct sockaddr_storage from;
1188 /* setup fd set for accept */
1191 for (i = 0; i < num_listen_socks; i++)
1192 if (listen_socks[i] > maxfd)
1193 maxfd = listen_socks[i];
1194 /* pipes connected to unauthenticated childs */
1195 startup_pipes = xcalloc(options.max_startups, sizeof(int));
1196 for (i = 0; i < options.max_startups; i++)
1197 startup_pipes[i] = -1;
1200 * Stay listening for connections until the system crashes or
1201 * the daemon is killed with a signal.
1204 if (received_sighup)
1208 fdset = (fd_set *)xcalloc(howmany(maxfd + 1, NFDBITS),
1211 for (i = 0; i < num_listen_socks; i++)
1212 FD_SET(listen_socks[i], fdset);
1213 for (i = 0; i < options.max_startups; i++)
1214 if (startup_pipes[i] != -1)
1215 FD_SET(startup_pipes[i], fdset);
1217 /* Wait in select until there is a connection. */
1218 ret = select(maxfd+1, fdset, NULL, NULL, NULL);
1219 if (ret < 0 && errno != EINTR)
1220 error("select: %.100s", strerror(errno));
1221 if (received_sigterm) {
1222 logit("Received signal %d; terminating.",
1223 (int) received_sigterm);
1224 close_listen_socks();
1225 unlink(options.pid_file);
1226 exit(received_sigterm == SIGTERM ? 0 : 255);
1228 if (key_used && key_do_regen) {
1229 generate_ephemeral_server_key();
1236 for (i = 0; i < options.max_startups; i++)
1237 if (startup_pipes[i] != -1 &&
1238 FD_ISSET(startup_pipes[i], fdset)) {
1240 * the read end of the pipe is ready
1241 * if the child has closed the pipe
1242 * after successful authentication
1243 * or if the child has died
1245 close(startup_pipes[i]);
1246 startup_pipes[i] = -1;
1249 for (i = 0; i < num_listen_socks; i++) {
1250 if (!FD_ISSET(listen_socks[i], fdset))
1252 fromlen = sizeof(from);
1253 *newsock = accept(listen_socks[i],
1254 (struct sockaddr *)&from, &fromlen);
1256 if (errno != EINTR && errno != EWOULDBLOCK &&
1257 errno != ECONNABORTED && errno != EAGAIN)
1258 error("accept: %.100s",
1260 if (errno == EMFILE || errno == ENFILE)
1264 if (unset_nonblock(*newsock) == -1) {
1268 if (drop_connection(startups) == 1) {
1269 debug("drop connection #%d", startups);
1273 if (pipe(startup_p) == -1) {
1278 if (rexec_flag && socketpair(AF_UNIX,
1279 SOCK_STREAM, 0, config_s) == -1) {
1280 error("reexec socketpair: %s",
1283 close(startup_p[0]);
1284 close(startup_p[1]);
1288 for (j = 0; j < options.max_startups; j++)
1289 if (startup_pipes[j] == -1) {
1290 startup_pipes[j] = startup_p[0];
1291 if (maxfd < startup_p[0])
1292 maxfd = startup_p[0];
1298 * Got connection. Fork a child to handle it, unless
1299 * we are in debugging mode.
1303 * In debugging mode. Close the listening
1304 * socket, and start processing the
1305 * connection without forking.
1307 debug("Server will not fork when running in debugging mode.");
1308 close_listen_socks();
1309 *sock_in = *newsock;
1310 *sock_out = *newsock;
1311 close(startup_p[0]);
1312 close(startup_p[1]);
1316 send_rexec_state(config_s[0],
1324 * Normal production daemon. Fork, and have
1325 * the child process the connection. The
1326 * parent continues listening.
1328 platform_pre_fork();
1329 if ((pid = fork()) == 0) {
1331 * Child. Close the listening and
1332 * max_startup sockets. Start using
1333 * the accepted socket. Reinitialize
1334 * logging (since our pid has changed).
1335 * We break out of the loop to handle
1338 platform_post_fork_child();
1339 startup_pipe = startup_p[1];
1340 close_startup_pipes();
1341 close_listen_socks();
1342 *sock_in = *newsock;
1343 *sock_out = *newsock;
1344 log_init(__progname,
1346 options.log_facility,
1353 /* Parent. Stay in the loop. */
1354 platform_post_fork_parent(pid);
1356 error("fork: %.100s", strerror(errno));
1358 debug("Forked child %ld.", (long)pid);
1360 close(startup_p[1]);
1363 send_rexec_state(config_s[0], &cfg);
1369 * Mark that the key has been used (it
1370 * was "given" to the child).
1372 if ((options.protocol & SSH_PROTO_1) &&
1374 /* Schedule server key regeneration alarm. */
1375 signal(SIGALRM, key_regeneration_alarm);
1376 alarm(options.key_regeneration_time);
1383 * Ensure that our random state differs
1384 * from that of the child
1387 arc4random_buf(rnd, sizeof(rnd));
1388 RAND_seed(rnd, sizeof(rnd));
1389 explicit_bzero(rnd, sizeof(rnd));
1392 /* child process check (or debug mode) */
1393 if (num_listen_socks < 0)
1400 * Main program for the daemon.
1403 main(int ac, char **av)
1405 extern char *optarg;
1407 int opt, i, j, on = 1;
1408 int sock_in = -1, sock_out = -1, newsock = -1;
1409 const char *remote_ip;
1411 char *line, *logfile = NULL;
1412 int config_s[2] = { -1 , -1 };
1414 u_int64_t ibytes, obytes;
1420 struct connection_info *connection_info = get_connection_info(0, 0);
1422 #ifdef HAVE_SECUREWARE
1423 (void)set_auth_parameters(ac, av);
1425 __progname = ssh_get_progname(av[0]);
1427 /* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
1430 saved_argv = xcalloc(ac + 1, sizeof(*saved_argv));
1431 for (i = 0; i < ac; i++)
1432 saved_argv[i] = xstrdup(av[i]);
1433 saved_argv[i] = NULL;
1435 #ifndef HAVE_SETPROCTITLE
1436 /* Prepare for later setproctitle emulation */
1437 compat_init_setproctitle(ac, av);
1441 if (geteuid() == 0 && setgroups(0, NULL) == -1)
1442 debug("setgroups(): %.200s", strerror(errno));
1444 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
1447 /* Initialize configuration options to their default values. */
1448 initialize_server_options(&options);
1450 /* Parse command-line arguments. */
1451 while ((opt = getopt(ac, av, "f:p:b:k:h:g:u:o:C:dDeE:iqrtQRT46")) != -1) {
1454 options.address_family = AF_INET;
1457 options.address_family = AF_INET6;
1460 config_file_name = optarg;
1463 if (options.num_host_cert_files >= MAX_HOSTCERTS) {
1464 fprintf(stderr, "too many host certificates.\n");
1467 options.host_cert_files[options.num_host_cert_files++] =
1468 derelativise_path(optarg);
1471 if (debug_flag == 0) {
1473 options.log_level = SYSLOG_LEVEL_DEBUG1;
1474 } else if (options.log_level < SYSLOG_LEVEL_DEBUG3)
1475 options.log_level++;
1481 logfile = xstrdup(optarg);
1500 options.log_level = SYSLOG_LEVEL_QUIET;
1503 options.server_key_bits = (int)strtonum(optarg, 256,
1507 options.ports_from_cmdline = 1;
1508 if (options.num_ports >= MAX_PORTS) {
1509 fprintf(stderr, "too many ports.\n");
1512 options.ports[options.num_ports++] = a2port(optarg);
1513 if (options.ports[options.num_ports-1] <= 0) {
1514 fprintf(stderr, "Bad port number.\n");
1519 if ((options.login_grace_time = convtime(optarg)) == -1) {
1520 fprintf(stderr, "Invalid login grace time.\n");
1525 if ((options.key_regeneration_time = convtime(optarg)) == -1) {
1526 fprintf(stderr, "Invalid key regeneration interval.\n");
1531 if (options.num_host_key_files >= MAX_HOSTKEYS) {
1532 fprintf(stderr, "too many host keys.\n");
1535 options.host_key_files[options.num_host_key_files++] =
1536 derelativise_path(optarg);
1545 if (parse_server_match_testspec(connection_info,
1550 utmp_len = (u_int)strtonum(optarg, 0, MAXHOSTNAMELEN+1, NULL);
1551 if (utmp_len > MAXHOSTNAMELEN) {
1552 fprintf(stderr, "Invalid utmp length.\n");
1557 line = xstrdup(optarg);
1558 if (process_server_config_line(&options, line,
1559 "command-line", 0, NULL, NULL) != 0)
1569 if (rexeced_flag || inetd_flag)
1571 if (!test_flag && (rexec_flag && (av[0] == NULL || *av[0] != '/')))
1572 fatal("sshd re-exec requires execution with an absolute path");
1574 closefrom(REEXEC_MIN_FREE_FD);
1576 closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
1578 OpenSSL_add_all_algorithms();
1580 /* If requested, redirect the logs to the specified logfile. */
1581 if (logfile != NULL) {
1582 log_redirect_stderr_to(logfile);
1586 * Force logging to stderr until we have loaded the private host
1587 * key (unless started from inetd)
1589 log_init(__progname,
1590 options.log_level == SYSLOG_LEVEL_NOT_SET ?
1591 SYSLOG_LEVEL_INFO : options.log_level,
1592 options.log_facility == SYSLOG_FACILITY_NOT_SET ?
1593 SYSLOG_FACILITY_AUTH : options.log_facility,
1594 log_stderr || !inetd_flag);
1597 * Unset KRB5CCNAME, otherwise the user's session may inherit it from
1598 * root's environment
1600 if (getenv("KRB5CCNAME") != NULL)
1601 (void) unsetenv("KRB5CCNAME");
1604 /* Cray can define user privs drop all privs now!
1605 * Not needed on PRIV_SU systems!
1610 sensitive_data.server_key = NULL;
1611 sensitive_data.ssh1_host_key = NULL;
1612 sensitive_data.have_ssh1_key = 0;
1613 sensitive_data.have_ssh2_key = 0;
1616 * If we're doing an extended config test, make sure we have all of
1617 * the parameters we need. If we're not doing an extended test,
1618 * do not silently ignore connection test params.
1620 if (test_flag >= 2 && server_match_spec_complete(connection_info) == 0)
1621 fatal("user, host and addr are all required when testing "
1623 if (test_flag < 2 && server_match_spec_complete(connection_info) >= 0)
1624 fatal("Config test connection parameter (-C) provided without "
1627 /* Fetch our configuration */
1630 recv_rexec_state(REEXEC_CONFIG_PASS_FD, &cfg);
1632 load_server_config(config_file_name, &cfg);
1634 parse_server_config(&options, rexeced_flag ? "rexec" : config_file_name,
1639 /* Fill in default values for those options not explicitly set. */
1640 fill_default_server_options(&options);
1642 /* challenge-response is implemented via keyboard interactive */
1643 if (options.challenge_response_authentication)
1644 options.kbd_interactive_authentication = 1;
1646 /* Check that options are sensible */
1647 if (options.authorized_keys_command_user == NULL &&
1648 (options.authorized_keys_command != NULL &&
1649 strcasecmp(options.authorized_keys_command, "none") != 0))
1650 fatal("AuthorizedKeysCommand set without "
1651 "AuthorizedKeysCommandUser");
1654 * Check whether there is any path through configured auth methods.
1655 * Unfortunately it is not possible to verify this generally before
1656 * daemonisation in the presence of Match block, but this catches
1657 * and warns for trivial misconfigurations that could break login.
1659 if (options.num_auth_methods != 0) {
1660 if ((options.protocol & SSH_PROTO_1))
1661 fatal("AuthenticationMethods is not supported with "
1663 for (n = 0; n < options.num_auth_methods; n++) {
1664 if (auth2_methods_valid(options.auth_methods[n],
1668 if (n >= options.num_auth_methods)
1669 fatal("AuthenticationMethods cannot be satisfied by "
1670 "enabled authentication methods");
1673 /* set default channel AF */
1674 channel_set_af(options.address_family);
1676 /* Check that there are no remaining arguments. */
1678 fprintf(stderr, "Extra argument %s.\n", av[optind]);
1682 debug("sshd version %.100s%.100s%s%.100s, %.100s",
1684 options.hpn_disabled ? "" : SSH_VERSION_HPN,
1685 *options.version_addendum == '\0' ? "" : " ",
1686 options.version_addendum,
1687 SSLeay_version(SSLEAY_VERSION));
1689 /* Store privilege separation user for later use if required. */
1690 if ((privsep_pw = getpwnam(SSH_PRIVSEP_USER)) == NULL) {
1691 if (use_privsep || options.kerberos_authentication)
1692 fatal("Privilege separation user %s does not exist",
1695 explicit_bzero(privsep_pw->pw_passwd,
1696 strlen(privsep_pw->pw_passwd));
1697 privsep_pw = pwcopy(privsep_pw);
1698 free(privsep_pw->pw_passwd);
1699 privsep_pw->pw_passwd = xstrdup("*");
1703 /* load host keys */
1704 sensitive_data.host_keys = xcalloc(options.num_host_key_files,
1706 sensitive_data.host_pubkeys = xcalloc(options.num_host_key_files,
1708 for (i = 0; i < options.num_host_key_files; i++) {
1709 sensitive_data.host_keys[i] = NULL;
1710 sensitive_data.host_pubkeys[i] = NULL;
1713 if (options.host_key_agent) {
1714 if (strcmp(options.host_key_agent, SSH_AUTHSOCKET_ENV_NAME))
1715 setenv(SSH_AUTHSOCKET_ENV_NAME,
1716 options.host_key_agent, 1);
1717 have_agent = ssh_agent_present();
1720 for (i = 0; i < options.num_host_key_files; i++) {
1721 key = key_load_private(options.host_key_files[i], "", NULL);
1722 pubkey = key_load_public(options.host_key_files[i], NULL);
1723 sensitive_data.host_keys[i] = key;
1724 sensitive_data.host_pubkeys[i] = pubkey;
1726 if (key == NULL && pubkey != NULL && pubkey->type != KEY_RSA1 &&
1728 debug("will rely on agent for hostkey %s",
1729 options.host_key_files[i]);
1730 keytype = pubkey->type;
1731 } else if (key != NULL) {
1732 keytype = key->type;
1734 error("Could not load host key: %s",
1735 options.host_key_files[i]);
1736 sensitive_data.host_keys[i] = NULL;
1737 sensitive_data.host_pubkeys[i] = NULL;
1743 sensitive_data.ssh1_host_key = key;
1744 sensitive_data.have_ssh1_key = 1;
1750 sensitive_data.have_ssh2_key = 1;
1753 debug("private host key: #%d type %d %s", i, keytype,
1754 key_type(key ? key : pubkey));
1756 if ((options.protocol & SSH_PROTO_1) && !sensitive_data.have_ssh1_key) {
1757 logit("Disabling protocol version 1. Could not load host key");
1758 options.protocol &= ~SSH_PROTO_1;
1760 if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) {
1761 logit("Disabling protocol version 2. Could not load host key");
1762 options.protocol &= ~SSH_PROTO_2;
1764 if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) {
1765 logit("sshd: no hostkeys available -- exiting.");
1770 * Load certificates. They are stored in an array at identical
1771 * indices to the public keys that they relate to.
1773 sensitive_data.host_certificates = xcalloc(options.num_host_key_files,
1775 for (i = 0; i < options.num_host_key_files; i++)
1776 sensitive_data.host_certificates[i] = NULL;
1778 for (i = 0; i < options.num_host_cert_files; i++) {
1779 key = key_load_public(options.host_cert_files[i], NULL);
1781 error("Could not load host certificate: %s",
1782 options.host_cert_files[i]);
1785 if (!key_is_cert(key)) {
1786 error("Certificate file is not a certificate: %s",
1787 options.host_cert_files[i]);
1791 /* Find matching private key */
1792 for (j = 0; j < options.num_host_key_files; j++) {
1793 if (key_equal_public(key,
1794 sensitive_data.host_keys[j])) {
1795 sensitive_data.host_certificates[j] = key;
1799 if (j >= options.num_host_key_files) {
1800 error("No matching private key for certificate: %s",
1801 options.host_cert_files[i]);
1805 sensitive_data.host_certificates[j] = key;
1806 debug("host certificate: #%d type %d %s", j, key->type,
1809 /* Check certain values for sanity. */
1810 if (options.protocol & SSH_PROTO_1) {
1811 if (options.server_key_bits < 512 ||
1812 options.server_key_bits > 32768) {
1813 fprintf(stderr, "Bad server key size.\n");
1817 * Check that server and host key lengths differ sufficiently. This
1818 * is necessary to make double encryption work with rsaref. Oh, I
1819 * hate software patents. I dont know if this can go? Niels
1821 if (options.server_key_bits >
1822 BN_num_bits(sensitive_data.ssh1_host_key->rsa->n) -
1823 SSH_KEY_BITS_RESERVED && options.server_key_bits <
1824 BN_num_bits(sensitive_data.ssh1_host_key->rsa->n) +
1825 SSH_KEY_BITS_RESERVED) {
1826 options.server_key_bits =
1827 BN_num_bits(sensitive_data.ssh1_host_key->rsa->n) +
1828 SSH_KEY_BITS_RESERVED;
1829 debug("Forcing server key to %d bits to make it differ from host key.",
1830 options.server_key_bits);
1837 if ((stat(_PATH_PRIVSEP_CHROOT_DIR, &st) == -1) ||
1838 (S_ISDIR(st.st_mode) == 0))
1839 fatal("Missing privilege separation directory: %s",
1840 _PATH_PRIVSEP_CHROOT_DIR);
1843 if (check_ntsec(_PATH_PRIVSEP_CHROOT_DIR) &&
1844 (st.st_uid != getuid () ||
1845 (st.st_mode & (S_IWGRP|S_IWOTH)) != 0))
1847 if (st.st_uid != 0 || (st.st_mode & (S_IWGRP|S_IWOTH)) != 0)
1849 fatal("%s must be owned by root and not group or "
1850 "world-writable.", _PATH_PRIVSEP_CHROOT_DIR);
1853 if (test_flag > 1) {
1854 if (server_match_spec_complete(connection_info) == 1)
1855 parse_server_match_config(&options, connection_info);
1856 dump_config(&options);
1859 /* Configuration looks good, so exit if in test mode. */
1864 * Clear out any supplemental groups we may have inherited. This
1865 * prevents inadvertent creation of files with bad modes (in the
1866 * portable version at least, it's certainly possible for PAM
1867 * to create a file, and we can't control the code in every
1868 * module which might be used).
1870 if (setgroups(0, NULL) < 0)
1871 debug("setgroups() failed: %.200s", strerror(errno));
1874 rexec_argv = xcalloc(rexec_argc + 2, sizeof(char *));
1875 for (i = 0; i < rexec_argc; i++) {
1876 debug("rexec_argv[%d]='%s'", i, saved_argv[i]);
1877 rexec_argv[i] = saved_argv[i];
1879 rexec_argv[rexec_argc] = "-R";
1880 rexec_argv[rexec_argc + 1] = NULL;
1883 /* Ensure that umask disallows at least group and world write */
1884 new_umask = umask(0077) | 0022;
1885 (void) umask(new_umask);
1887 /* Initialize the log (it is reinitialized below in case we forked). */
1888 if (debug_flag && (!inetd_flag || rexeced_flag))
1890 log_init(__progname, options.log_level, options.log_facility, log_stderr);
1893 * If not in debugging mode, and not started from inetd, disconnect
1894 * from the controlling terminal, and fork. The original process
1897 if (!(debug_flag || inetd_flag || no_daemon_flag)) {
1900 #endif /* TIOCNOTTY */
1901 if (daemon(0, 0) < 0)
1902 fatal("daemon() failed: %.200s", strerror(errno));
1904 /* Disconnect from the controlling tty. */
1906 fd = open(_PATH_TTY, O_RDWR | O_NOCTTY);
1908 (void) ioctl(fd, TIOCNOTTY, NULL);
1911 #endif /* TIOCNOTTY */
1913 /* Reinitialize the log (because of the fork above). */
1914 log_init(__progname, options.log_level, options.log_facility, log_stderr);
1916 /* Avoid killing the process in high-pressure swapping environments. */
1917 if (!inetd_flag && madvise(NULL, 0, MADV_PROTECT) != 0)
1918 debug("madvise(): %.200s", strerror(errno));
1920 /* Chdir to the root directory so that the current disk can be
1921 unmounted if desired. */
1922 if (chdir("/") == -1)
1923 error("chdir(\"/\"): %s", strerror(errno));
1925 /* ignore SIGPIPE */
1926 signal(SIGPIPE, SIG_IGN);
1928 /* Get a connection, either from inetd or a listening TCP socket */
1930 server_accept_inetd(&sock_in, &sock_out);
1932 platform_pre_listen();
1935 if (options.protocol & SSH_PROTO_1)
1936 generate_ephemeral_server_key();
1938 signal(SIGHUP, sighup_handler);
1939 signal(SIGCHLD, main_sigchld_handler);
1940 signal(SIGTERM, sigterm_handler);
1941 signal(SIGQUIT, sigterm_handler);
1944 * Write out the pid file after the sigterm handler
1945 * is setup and the listen sockets are bound
1948 FILE *f = fopen(options.pid_file, "w");
1951 error("Couldn't create pid file \"%s\": %s",
1952 options.pid_file, strerror(errno));
1954 fprintf(f, "%ld\n", (long) getpid());
1959 /* Accept a connection and return in a forked child */
1960 server_accept_loop(&sock_in, &sock_out,
1961 &newsock, config_s);
1964 /* This is the child processing a new connection. */
1965 setproctitle("%s", "[accepted]");
1968 * Create a new session and process group since the 4.4BSD
1969 * setlogin() affects the entire process group. We don't
1970 * want the child to be able to affect the parent.
1972 #if !defined(SSHD_ACQUIRES_CTTY)
1974 * If setsid is called, on some platforms sshd will later acquire a
1975 * controlling terminal which will result in "could not set
1976 * controlling tty" errors.
1978 if (!debug_flag && !inetd_flag && setsid() < 0)
1979 error("setsid: %.100s", strerror(errno));
1985 debug("rexec start in %d out %d newsock %d pipe %d sock %d",
1986 sock_in, sock_out, newsock, startup_pipe, config_s[0]);
1987 dup2(newsock, STDIN_FILENO);
1988 dup2(STDIN_FILENO, STDOUT_FILENO);
1989 if (startup_pipe == -1)
1990 close(REEXEC_STARTUP_PIPE_FD);
1991 else if (startup_pipe != REEXEC_STARTUP_PIPE_FD) {
1992 dup2(startup_pipe, REEXEC_STARTUP_PIPE_FD);
1993 close(startup_pipe);
1994 startup_pipe = REEXEC_STARTUP_PIPE_FD;
1997 dup2(config_s[1], REEXEC_CONFIG_PASS_FD);
2000 execv(rexec_argv[0], rexec_argv);
2002 /* Reexec has failed, fall back and continue */
2003 error("rexec of %s failed: %s", rexec_argv[0], strerror(errno));
2004 recv_rexec_state(REEXEC_CONFIG_PASS_FD, NULL);
2005 log_init(__progname, options.log_level,
2006 options.log_facility, log_stderr);
2009 close(REEXEC_CONFIG_PASS_FD);
2010 newsock = sock_out = sock_in = dup(STDIN_FILENO);
2011 if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
2012 dup2(fd, STDIN_FILENO);
2013 dup2(fd, STDOUT_FILENO);
2014 if (fd > STDERR_FILENO)
2017 debug("rexec cleanup in %d out %d newsock %d pipe %d sock %d",
2018 sock_in, sock_out, newsock, startup_pipe, config_s[0]);
2021 /* Executed child processes don't need these. */
2022 fcntl(sock_out, F_SETFD, FD_CLOEXEC);
2023 fcntl(sock_in, F_SETFD, FD_CLOEXEC);
2026 * Disable the key regeneration alarm. We will not regenerate the
2027 * key since we are no longer in a position to give it to anyone. We
2028 * will not restart on SIGHUP since it no longer makes sense.
2031 signal(SIGALRM, SIG_DFL);
2032 signal(SIGHUP, SIG_DFL);
2033 signal(SIGTERM, SIG_DFL);
2034 signal(SIGQUIT, SIG_DFL);
2035 signal(SIGCHLD, SIG_DFL);
2036 signal(SIGINT, SIG_DFL);
2040 * Initialize the resolver. This may not happen automatically
2041 * before privsep chroot().
2043 if ((_res.options & RES_INIT) == 0) {
2044 debug("res_init()");
2049 * Force GSS-API to parse its configuration and load any
2050 * mechanism plugins.
2054 OM_uint32 minor_status;
2055 gss_indicate_mechs(&minor_status, &mechs);
2056 gss_release_oid_set(&minor_status, &mechs);
2062 * Register our connection. This turns encryption off because we do
2065 packet_set_connection(sock_in, sock_out);
2066 packet_set_server();
2068 /* Set SO_KEEPALIVE if requested. */
2069 if (options.tcp_keep_alive && packet_connection_is_on_socket() &&
2070 setsockopt(sock_in, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) < 0)
2071 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
2073 if ((remote_port = get_remote_port()) < 0) {
2074 debug("get_remote_port failed");
2079 * We use get_canonical_hostname with usedns = 0 instead of
2080 * get_remote_ipaddr here so IP options will be checked.
2082 (void) get_canonical_hostname(0);
2084 * The rest of the code depends on the fact that
2085 * get_remote_ipaddr() caches the remote ip, even if
2086 * the socket goes away.
2088 remote_ip = get_remote_ipaddr();
2090 #ifdef SSH_AUDIT_EVENTS
2091 audit_connection_from(remote_ip, remote_port);
2094 allow_severity = options.log_facility|LOG_INFO;
2095 deny_severity = options.log_facility|LOG_WARNING;
2096 /* Check whether logins are denied from this host. */
2097 if (packet_connection_is_on_socket()) {
2098 struct request_info req;
2100 request_init(&req, RQ_DAEMON, __progname, RQ_FILE, sock_in, 0);
2103 if (!hosts_access(&req)) {
2104 debug("Connection refused by tcp wrapper");
2107 fatal("libwrap refuse returns");
2110 #endif /* LIBWRAP */
2112 /* Log the connection. */
2113 verbose("Connection from %s port %d on %s port %d",
2114 remote_ip, remote_port,
2115 get_local_ipaddr(sock_in), get_local_port());
2117 /* Set HPN options for the child. */
2118 channel_set_hpn(options.hpn_disabled, options.hpn_buffer_size);
2121 * We don't want to listen forever unless the other side
2122 * successfully authenticates itself. So we set up an alarm which is
2123 * cleared after successful authentication. A limit of zero
2124 * indicates no limit. Note that we don't set the alarm in debugging
2125 * mode; it is just annoying to have the server exit just when you
2126 * are about to discover the bug.
2128 signal(SIGALRM, grace_alarm_handler);
2130 alarm(options.login_grace_time);
2132 sshd_exchange_identification(sock_in, sock_out);
2134 /* In inetd mode, generate ephemeral key only for proto 1 connections */
2135 if (!compat20 && inetd_flag && sensitive_data.server_key == NULL)
2136 generate_ephemeral_server_key();
2138 packet_set_nonblocking();
2140 /* allocate authentication context */
2141 authctxt = xcalloc(1, sizeof(*authctxt));
2143 authctxt->loginmsg = &loginmsg;
2145 /* XXX global for cleanup, access from other modules */
2146 the_authctxt = authctxt;
2148 /* prepare buffer to collect messages to display to user after login */
2149 buffer_init(&loginmsg);
2153 if (privsep_preauth(authctxt) == 1)
2155 } else if (compat20 && have_agent)
2156 auth_conn = ssh_get_authentication_connection();
2158 /* perform the key exchange */
2159 /* authenticate user and start session */
2162 do_authentication2(authctxt);
2165 do_authentication(authctxt);
2168 * If we use privilege separation, the unprivileged child transfers
2169 * the current keystate and exits
2172 mm_send_keystate(pmonitor);
2178 * Cancel the alarm we set to limit the time taken for
2182 signal(SIGALRM, SIG_DFL);
2183 authctxt->authenticated = 1;
2184 if (startup_pipe != -1) {
2185 close(startup_pipe);
2189 #ifdef SSH_AUDIT_EVENTS
2190 audit_event(SSH_AUTH_SUCCESS);
2194 if (options.gss_authentication) {
2195 temporarily_use_uid(authctxt->pw);
2196 ssh_gssapi_storecreds();
2201 if (options.use_pam) {
2208 * In privilege separation, we fork another child and prepare
2209 * file descriptor passing.
2212 privsep_postauth(authctxt);
2213 /* the monitor process [priv] will not return */
2215 destroy_sensitive_data();
2218 packet_set_timeout(options.client_alive_interval,
2219 options.client_alive_count_max);
2221 /* Start session. */
2222 do_authenticated(authctxt);
2224 /* The connection has been terminated. */
2225 packet_get_state(MODE_IN, NULL, NULL, NULL, &ibytes);
2226 packet_get_state(MODE_OUT, NULL, NULL, NULL, &obytes);
2227 verbose("Transferred: sent %llu, received %llu bytes",
2228 (unsigned long long)obytes, (unsigned long long)ibytes);
2230 verbose("Closing connection to %.500s port %d", remote_ip, remote_port);
2233 if (options.use_pam)
2235 #endif /* USE_PAM */
2237 #ifdef SSH_AUDIT_EVENTS
2238 PRIVSEP(audit_event(SSH_CONNECTION_CLOSE));
2250 * Decrypt session_key_int using our private server key and private host key
2251 * (key with larger modulus first).
2254 ssh1_session_key(BIGNUM *session_key_int)
2258 if (BN_cmp(sensitive_data.server_key->rsa->n,
2259 sensitive_data.ssh1_host_key->rsa->n) > 0) {
2260 /* Server key has bigger modulus. */
2261 if (BN_num_bits(sensitive_data.server_key->rsa->n) <
2262 BN_num_bits(sensitive_data.ssh1_host_key->rsa->n) +
2263 SSH_KEY_BITS_RESERVED) {
2264 fatal("do_connection: %s: "
2265 "server_key %d < host_key %d + SSH_KEY_BITS_RESERVED %d",
2266 get_remote_ipaddr(),
2267 BN_num_bits(sensitive_data.server_key->rsa->n),
2268 BN_num_bits(sensitive_data.ssh1_host_key->rsa->n),
2269 SSH_KEY_BITS_RESERVED);
2271 if (rsa_private_decrypt(session_key_int, session_key_int,
2272 sensitive_data.server_key->rsa) <= 0)
2274 if (rsa_private_decrypt(session_key_int, session_key_int,
2275 sensitive_data.ssh1_host_key->rsa) <= 0)
2278 /* Host key has bigger modulus (or they are equal). */
2279 if (BN_num_bits(sensitive_data.ssh1_host_key->rsa->n) <
2280 BN_num_bits(sensitive_data.server_key->rsa->n) +
2281 SSH_KEY_BITS_RESERVED) {
2282 fatal("do_connection: %s: "
2283 "host_key %d < server_key %d + SSH_KEY_BITS_RESERVED %d",
2284 get_remote_ipaddr(),
2285 BN_num_bits(sensitive_data.ssh1_host_key->rsa->n),
2286 BN_num_bits(sensitive_data.server_key->rsa->n),
2287 SSH_KEY_BITS_RESERVED);
2289 if (rsa_private_decrypt(session_key_int, session_key_int,
2290 sensitive_data.ssh1_host_key->rsa) < 0)
2292 if (rsa_private_decrypt(session_key_int, session_key_int,
2293 sensitive_data.server_key->rsa) < 0)
2306 BIGNUM *session_key_int;
2307 u_char session_key[SSH_SESSION_KEY_LENGTH];
2309 u_int cipher_type, auth_mask, protocol_flags;
2312 * Generate check bytes that the client must send back in the user
2313 * packet in order for it to be accepted; this is used to defy ip
2314 * spoofing attacks. Note that this only works against somebody
2315 * doing IP spoofing from a remote machine; any machine on the local
2316 * network can still see outgoing packets and catch the random
2317 * cookie. This only affects rhosts authentication, and this is one
2318 * of the reasons why it is inherently insecure.
2320 arc4random_buf(cookie, sizeof(cookie));
2323 * Send our public key. We include in the packet 64 bits of random
2324 * data that must be matched in the reply in order to prevent IP
2327 packet_start(SSH_SMSG_PUBLIC_KEY);
2328 for (i = 0; i < 8; i++)
2329 packet_put_char(cookie[i]);
2331 /* Store our public server RSA key. */
2332 packet_put_int(BN_num_bits(sensitive_data.server_key->rsa->n));
2333 packet_put_bignum(sensitive_data.server_key->rsa->e);
2334 packet_put_bignum(sensitive_data.server_key->rsa->n);
2336 /* Store our public host RSA key. */
2337 packet_put_int(BN_num_bits(sensitive_data.ssh1_host_key->rsa->n));
2338 packet_put_bignum(sensitive_data.ssh1_host_key->rsa->e);
2339 packet_put_bignum(sensitive_data.ssh1_host_key->rsa->n);
2341 /* Put protocol flags. */
2342 packet_put_int(SSH_PROTOFLAG_HOST_IN_FWD_OPEN);
2344 /* Declare which ciphers we support. */
2345 packet_put_int(cipher_mask_ssh1(0));
2347 /* Declare supported authentication types. */
2349 if (options.rhosts_rsa_authentication)
2350 auth_mask |= 1 << SSH_AUTH_RHOSTS_RSA;
2351 if (options.rsa_authentication)
2352 auth_mask |= 1 << SSH_AUTH_RSA;
2353 if (options.challenge_response_authentication == 1)
2354 auth_mask |= 1 << SSH_AUTH_TIS;
2355 if (options.password_authentication)
2356 auth_mask |= 1 << SSH_AUTH_PASSWORD;
2357 packet_put_int(auth_mask);
2359 /* Send the packet and wait for it to be sent. */
2361 packet_write_wait();
2363 debug("Sent %d bit server key and %d bit host key.",
2364 BN_num_bits(sensitive_data.server_key->rsa->n),
2365 BN_num_bits(sensitive_data.ssh1_host_key->rsa->n));
2367 /* Read clients reply (cipher type and session key). */
2368 packet_read_expect(SSH_CMSG_SESSION_KEY);
2370 /* Get cipher type and check whether we accept this. */
2371 cipher_type = packet_get_char();
2373 if (!(cipher_mask_ssh1(0) & (1 << cipher_type)))
2374 packet_disconnect("Warning: client selects unsupported cipher.");
2376 /* Get check bytes from the packet. These must match those we
2377 sent earlier with the public key packet. */
2378 for (i = 0; i < 8; i++)
2379 if (cookie[i] != packet_get_char())
2380 packet_disconnect("IP Spoofing check bytes do not match.");
2382 debug("Encryption type: %.200s", cipher_name(cipher_type));
2384 /* Get the encrypted integer. */
2385 if ((session_key_int = BN_new()) == NULL)
2386 fatal("do_ssh1_kex: BN_new failed");
2387 packet_get_bignum(session_key_int);
2389 protocol_flags = packet_get_int();
2390 packet_set_protocol_flags(protocol_flags);
2393 /* Decrypt session_key_int using host/server keys */
2394 rsafail = PRIVSEP(ssh1_session_key(session_key_int));
2397 * Extract session key from the decrypted integer. The key is in the
2398 * least significant 256 bits of the integer; the first byte of the
2399 * key is in the highest bits.
2402 (void) BN_mask_bits(session_key_int, sizeof(session_key) * 8);
2403 len = BN_num_bytes(session_key_int);
2404 if (len < 0 || (u_int)len > sizeof(session_key)) {
2405 error("do_ssh1_kex: bad session key len from %s: "
2406 "session_key_int %d > sizeof(session_key) %lu",
2407 get_remote_ipaddr(), len, (u_long)sizeof(session_key));
2410 explicit_bzero(session_key, sizeof(session_key));
2411 BN_bn2bin(session_key_int,
2412 session_key + sizeof(session_key) - len);
2414 derive_ssh1_session_id(
2415 sensitive_data.ssh1_host_key->rsa->n,
2416 sensitive_data.server_key->rsa->n,
2417 cookie, session_id);
2419 * Xor the first 16 bytes of the session key with the
2422 for (i = 0; i < 16; i++)
2423 session_key[i] ^= session_id[i];
2427 int bytes = BN_num_bytes(session_key_int);
2428 u_char *buf = xmalloc(bytes);
2429 struct ssh_digest_ctx *md;
2431 logit("do_connection: generating a fake encryption key");
2432 BN_bn2bin(session_key_int, buf);
2433 if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL ||
2434 ssh_digest_update(md, buf, bytes) < 0 ||
2435 ssh_digest_update(md, sensitive_data.ssh1_cookie,
2436 SSH_SESSION_KEY_LENGTH) < 0 ||
2437 ssh_digest_final(md, session_key, sizeof(session_key)) < 0)
2438 fatal("%s: md5 failed", __func__);
2439 ssh_digest_free(md);
2440 if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL ||
2441 ssh_digest_update(md, session_key, 16) < 0 ||
2442 ssh_digest_update(md, sensitive_data.ssh1_cookie,
2443 SSH_SESSION_KEY_LENGTH) < 0 ||
2444 ssh_digest_final(md, session_key + 16,
2445 sizeof(session_key) - 16) < 0)
2446 fatal("%s: md5 failed", __func__);
2447 ssh_digest_free(md);
2448 explicit_bzero(buf, bytes);
2450 for (i = 0; i < 16; i++)
2451 session_id[i] = session_key[i] ^ session_key[i + 16];
2453 /* Destroy the private and public keys. No longer. */
2454 destroy_sensitive_data();
2457 mm_ssh1_session_id(session_id);
2459 /* Destroy the decrypted integer. It is no longer needed. */
2460 BN_clear_free(session_key_int);
2462 /* Set the session key. From this on all communications will be encrypted. */
2463 packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, cipher_type);
2465 /* Destroy our copy of the session key. It is no longer needed. */
2466 explicit_bzero(session_key, sizeof(session_key));
2468 debug("Received session key; encryption turned on.");
2470 /* Send an acknowledgment packet. Note that this packet is sent encrypted. */
2471 packet_start(SSH_SMSG_SUCCESS);
2473 packet_write_wait();
2477 sshd_hostkey_sign(Key *privkey, Key *pubkey, u_char **signature, u_int *slen,
2478 u_char *data, u_int dlen)
2481 if (PRIVSEP(key_sign(privkey, signature, slen, data, dlen) < 0))
2482 fatal("%s: key_sign failed", __func__);
2483 } else if (use_privsep) {
2484 if (mm_key_sign(pubkey, signature, slen, data, dlen) < 0)
2485 fatal("%s: pubkey_sign failed", __func__);
2487 if (ssh_agent_sign(auth_conn, pubkey, signature, slen, data,
2489 fatal("%s: ssh_agent_sign failed", __func__);
2494 * SSH2 key exchange: diffie-hellman-group1-sha1
2501 if (options.ciphers != NULL) {
2502 myproposal[PROPOSAL_ENC_ALGS_CTOS] =
2503 myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
2504 #ifdef NONE_CIPHER_ENABLED
2505 } else if (options.none_enabled == 1) {
2506 debug ("WARNING: None cipher enabled");
2507 myproposal[PROPOSAL_ENC_ALGS_CTOS] =
2508 myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_ENCRYPT_INCLUDE_NONE;
2511 myproposal[PROPOSAL_ENC_ALGS_CTOS] =
2512 compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
2513 myproposal[PROPOSAL_ENC_ALGS_STOC] =
2514 compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_STOC]);
2516 if (options.macs != NULL) {
2517 myproposal[PROPOSAL_MAC_ALGS_CTOS] =
2518 myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
2520 if (options.compression == COMP_NONE) {
2521 myproposal[PROPOSAL_COMP_ALGS_CTOS] =
2522 myproposal[PROPOSAL_COMP_ALGS_STOC] = "none";
2523 } else if (options.compression == COMP_DELAYED) {
2524 myproposal[PROPOSAL_COMP_ALGS_CTOS] =
2525 myproposal[PROPOSAL_COMP_ALGS_STOC] = "none,zlib@openssh.com";
2527 if (options.kex_algorithms != NULL)
2528 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
2530 myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
2531 myproposal[PROPOSAL_KEX_ALGS]);
2533 if (options.rekey_limit || options.rekey_interval)
2534 packet_set_rekey_limits((u_int32_t)options.rekey_limit,
2535 (time_t)options.rekey_interval);
2537 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal(
2538 list_hostkey_types());
2540 /* start key exchange */
2541 kex = kex_setup(myproposal);
2542 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
2543 kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
2544 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2545 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2546 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2547 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
2549 kex->client_version_string=client_version_string;
2550 kex->server_version_string=server_version_string;
2551 kex->load_host_public_key=&get_hostkey_public_by_type;
2552 kex->load_host_private_key=&get_hostkey_private_by_type;
2553 kex->host_key_index=&get_hostkey_index;
2554 kex->sign = sshd_hostkey_sign;
2558 dispatch_run(DISPATCH_BLOCK, &kex->done, kex);
2560 session_id2 = kex->session_id;
2561 session_id2_len = kex->session_id_len;
2564 /* send 1st encrypted/maced/compressed message */
2565 packet_start(SSH2_MSG_IGNORE);
2566 packet_put_cstring("markus");
2568 packet_write_wait();
2573 /* server specific fatal cleanup */
2578 do_cleanup(the_authctxt);
2579 if (use_privsep && privsep_is_preauth && pmonitor->m_pid > 1) {
2580 debug("Killing privsep child %d", pmonitor->m_pid);
2581 if (kill(pmonitor->m_pid, SIGKILL) != 0 &&
2583 error("%s: kill(%d): %s", __func__,
2584 pmonitor->m_pid, strerror(errno));
2587 #ifdef SSH_AUDIT_EVENTS
2588 /* done after do_cleanup so it can cancel the PAM auth 'thread' */
2589 if (!use_privsep || mm_is_monitor())
2590 audit_event(SSH_CONNECTION_ABANDON);