3
0

getenforce.c 761 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * getenforce
  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 getenforce_trivial_usage NOUSAGE_STR
  10. //usage:#define getenforce_full_usage ""
  11. #include "libbb.h"
  12. int getenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  13. int getenforce_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  14. {
  15. int rc;
  16. rc = is_selinux_enabled();
  17. if (rc < 0)
  18. bb_error_msg_and_die("is_selinux_enabled() failed");
  19. if (rc == 1) {
  20. rc = security_getenforce();
  21. if (rc < 0)
  22. bb_error_msg_and_die("getenforce() failed");
  23. if (rc)
  24. puts("Enforcing");
  25. else
  26. puts("Permissive");
  27. } else {
  28. puts("Disabled");
  29. }
  30. return 0;
  31. }