setenforce.c 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * setenforce
  3. *
  4. * Based on libselinux 1.33.1
  5. * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp>
  6. *
  7. * Licensed under GPLv2, see file LICENSE in this source tree.
  8. */
  9. //usage:#define setenforce_trivial_usage
  10. //usage: "[Enforcing | Permissive | 1 | 0]"
  11. //usage:#define setenforce_full_usage ""
  12. #include "libbb.h"
  13. /* These strings are arranged so that odd ones
  14. * result in security_setenforce(1) being done,
  15. * the rest will do security_setenforce(0) */
  16. static const char *const setenforce_cmd[] = {
  17. "0",
  18. "1",
  19. "permissive",
  20. "enforcing",
  21. NULL,
  22. };
  23. int setenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  24. int setenforce_main(int argc UNUSED_PARAM, char **argv)
  25. {
  26. int i, rc;
  27. if (!argv[1] || argv[2])
  28. bb_show_usage();
  29. selinux_or_die();
  30. for (i = 0; setenforce_cmd[i]; i++) {
  31. if (strcasecmp(argv[1], setenforce_cmd[i]) != 0)
  32. continue;
  33. rc = security_setenforce(i & 1);
  34. if (rc < 0)
  35. bb_perror_msg_and_die("setenforce() failed");
  36. return 0;
  37. }
  38. bb_show_usage();
  39. }