3
0

setenforce.c 883 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "libbb.h"
  10. /* These strings are arranged so that odd ones
  11. * result in security_setenforce(1) being done,
  12. * the rest will do security_setenforce(0) */
  13. static const char *const setenforce_cmd[] = {
  14. "0",
  15. "1",
  16. "permissive",
  17. "enforcing",
  18. NULL,
  19. };
  20. int setenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  21. int setenforce_main(int argc UNUSED_PARAM, char **argv)
  22. {
  23. int i, rc;
  24. if (!argv[1] || argv[2])
  25. bb_show_usage();
  26. selinux_or_die();
  27. for (i = 0; setenforce_cmd[i]; i++) {
  28. if (strcasecmp(argv[1], setenforce_cmd[i]) != 0)
  29. continue;
  30. rc = security_setenforce(i & 1);
  31. if (rc < 0)
  32. bb_perror_msg_and_die("setenforce() failed");
  33. return 0;
  34. }
  35. bb_show_usage();
  36. }