getenforce.c 674 B

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