platform-pledge.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2015 Joyent, Inc
  3. * Author: Alex Wilson <alex.wilson@joyent.com>
  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. #include <sys/types.h>
  19. #include <stdarg.h>
  20. #include <unistd.h>
  21. #include "platform.h"
  22. #include "openbsd-compat/openbsd-compat.h"
  23. /*
  24. * Drop any fine-grained privileges that are not needed for post-startup
  25. * operation of ssh-agent
  26. *
  27. * Should be as close as possible to pledge("stdio cpath unix id proc exec", ...)
  28. */
  29. void
  30. platform_pledge_agent(void)
  31. {
  32. #ifdef USE_SOLARIS_PRIVS
  33. /*
  34. * Note: Solaris priv dropping is closer to tame() than pledge(), but
  35. * we will use what we have.
  36. */
  37. solaris_drop_privs_root_pinfo_net();
  38. #endif
  39. }
  40. /*
  41. * Drop any fine-grained privileges that are not needed for post-startup
  42. * operation of sftp-server
  43. */
  44. void
  45. platform_pledge_sftp_server(void)
  46. {
  47. #ifdef USE_SOLARIS_PRIVS
  48. solaris_drop_privs_pinfo_net_fork_exec();
  49. #endif
  50. }
  51. /*
  52. * Drop any fine-grained privileges that are not needed for the post-startup
  53. * operation of the SSH client mux
  54. *
  55. * Should be as close as possible to pledge("stdio proc tty", ...)
  56. */
  57. void
  58. platform_pledge_mux(void)
  59. {
  60. #ifdef USE_SOLARIS_PRIVS
  61. solaris_drop_privs_root_pinfo_net_exec();
  62. #endif
  63. }