setenforce.c 797 B

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