getenforce.c 631 B

1234567891011121314151617181920212223242526272829
  1. /* getenforce.c - Get the current SELinux mode
  2. *
  3. * Copyright 2014 The Android Open Source Project
  4. USE_GETENFORCE(NEWTOY(getenforce, ">0", TOYFLAG_USR|TOYFLAG_SBIN))
  5. config GETENFORCE
  6. bool "getenforce"
  7. default y
  8. depends on TOYBOX_SELINUX
  9. help
  10. usage: getenforce
  11. Shows whether SELinux is disabled, enforcing, or permissive.
  12. */
  13. #define FOR_getenforce
  14. #include "toys.h"
  15. void getenforce_main(void)
  16. {
  17. if (!is_selinux_enabled()) puts("Disabled");
  18. else {
  19. int ret = security_getenforce();
  20. if (ret == -1) perror_exit("Couldn't get enforcing status");
  21. else puts(ret ? "Enforcing" : "Permissive");
  22. }
  23. }