sandbox-pledge.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $OpenBSD: sandbox-pledge.c,v 1.1 2015/10/09 01:37:08 deraadt Exp $ */
  2. /*
  3. * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "includes.h"
  18. #ifdef SANDBOX_PLEDGE
  19. #include <sys/types.h>
  20. #include <sys/ioctl.h>
  21. #include <sys/syscall.h>
  22. #include <sys/socket.h>
  23. #include <sys/wait.h>
  24. #include <errno.h>
  25. #include <limits.h>
  26. #include <stdarg.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <unistd.h>
  30. #include <pwd.h>
  31. #include "log.h"
  32. #include "ssh-sandbox.h"
  33. #include "xmalloc.h"
  34. struct ssh_sandbox {
  35. pid_t child_pid;
  36. };
  37. struct ssh_sandbox *
  38. ssh_sandbox_init(struct monitor *m)
  39. {
  40. struct ssh_sandbox *box;
  41. debug3("%s: preparing pledge sandbox", __func__);
  42. box = xcalloc(1, sizeof(*box));
  43. box->child_pid = 0;
  44. return box;
  45. }
  46. void
  47. ssh_sandbox_child(struct ssh_sandbox *box)
  48. {
  49. if (pledge("stdio", NULL) == -1)
  50. fatal("%s: pledge()", __func__);
  51. }
  52. void
  53. ssh_sandbox_parent_finish(struct ssh_sandbox *box)
  54. {
  55. free(box);
  56. debug3("%s: finished", __func__);
  57. }
  58. void
  59. ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
  60. {
  61. box->child_pid = child_pid;
  62. /* Nothing to do here */
  63. }
  64. #endif /* SANDBOX_PLEDGE */