diff options
Diffstat (limited to 'sshd.c')
-rw-r--r-- | sshd.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshd.c,v 1.383 2011/06/17 21:44:31 djm Exp $ */ | 1 | /* $OpenBSD: sshd.c,v 1.384 2011/06/22 21:57:01 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -118,6 +118,7 @@ | |||
118 | #endif | 118 | #endif |
119 | #include "monitor_wrap.h" | 119 | #include "monitor_wrap.h" |
120 | #include "roaming.h" | 120 | #include "roaming.h" |
121 | #include "sandbox.h" | ||
121 | #include "version.h" | 122 | #include "version.h" |
122 | 123 | ||
123 | #ifdef LIBWRAP | 124 | #ifdef LIBWRAP |
@@ -624,18 +625,23 @@ privsep_preauth(Authctxt *authctxt) | |||
624 | { | 625 | { |
625 | int status; | 626 | int status; |
626 | pid_t pid; | 627 | pid_t pid; |
628 | struct ssh_sandbox *box = NULL; | ||
627 | 629 | ||
628 | /* Set up unprivileged child process to deal with network data */ | 630 | /* Set up unprivileged child process to deal with network data */ |
629 | pmonitor = monitor_init(); | 631 | pmonitor = monitor_init(); |
630 | /* Store a pointer to the kex for later rekeying */ | 632 | /* Store a pointer to the kex for later rekeying */ |
631 | pmonitor->m_pkex = &xxx_kex; | 633 | pmonitor->m_pkex = &xxx_kex; |
632 | 634 | ||
635 | if (use_privsep == PRIVSEP_SANDBOX) | ||
636 | box = ssh_sandbox_init(); | ||
633 | pid = fork(); | 637 | pid = fork(); |
634 | if (pid == -1) { | 638 | if (pid == -1) { |
635 | fatal("fork of unprivileged child failed"); | 639 | fatal("fork of unprivileged child failed"); |
636 | } else if (pid != 0) { | 640 | } else if (pid != 0) { |
637 | debug2("Network child is on pid %ld", (long)pid); | 641 | debug2("Network child is on pid %ld", (long)pid); |
638 | 642 | ||
643 | if (box != NULL) | ||
644 | ssh_sandbox_parent_preauth(box, pid); | ||
639 | pmonitor->m_pid = pid; | 645 | pmonitor->m_pid = pid; |
640 | monitor_child_preauth(authctxt, pmonitor); | 646 | monitor_child_preauth(authctxt, pmonitor); |
641 | 647 | ||
@@ -643,10 +649,21 @@ privsep_preauth(Authctxt *authctxt) | |||
643 | monitor_sync(pmonitor); | 649 | monitor_sync(pmonitor); |
644 | 650 | ||
645 | /* Wait for the child's exit status */ | 651 | /* Wait for the child's exit status */ |
646 | while (waitpid(pid, &status, 0) < 0) | 652 | while (waitpid(pid, &status, 0) < 0) { |
647 | if (errno != EINTR) | 653 | if (errno != EINTR) |
648 | break; | 654 | fatal("%s: waitpid: %s", __func__, |
649 | return (1); | 655 | strerror(errno)); |
656 | } | ||
657 | if (WIFEXITED(status)) { | ||
658 | if (WEXITSTATUS(status) != 0) | ||
659 | fatal("%s: preauth child exited with status %d", | ||
660 | __func__, WEXITSTATUS(status)); | ||
661 | } else if (WIFSIGNALED(status)) | ||
662 | fatal("%s: preauth child terminated by signal %d", | ||
663 | __func__, WTERMSIG(status)); | ||
664 | if (box != NULL) | ||
665 | ssh_sandbox_parent_finish(box); | ||
666 | return 1; | ||
650 | } else { | 667 | } else { |
651 | /* child */ | 668 | /* child */ |
652 | close(pmonitor->m_sendfd); | 669 | close(pmonitor->m_sendfd); |
@@ -659,8 +676,11 @@ privsep_preauth(Authctxt *authctxt) | |||
659 | if (getuid() == 0 || geteuid() == 0) | 676 | if (getuid() == 0 || geteuid() == 0) |
660 | privsep_preauth_child(); | 677 | privsep_preauth_child(); |
661 | setproctitle("%s", "[net]"); | 678 | setproctitle("%s", "[net]"); |
679 | if (box != NULL) | ||
680 | ssh_sandbox_child(box); | ||
681 | |||
682 | return 0; | ||
662 | } | 683 | } |
663 | return (0); | ||
664 | } | 684 | } |
665 | 685 | ||
666 | static void | 686 | static void |