getsebool.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * getsebool
  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. //config:config GETSEBOOL
  10. //config: bool "getsebool (5.5 kb)"
  11. //config: default n
  12. //config: depends on SELINUX
  13. //config: help
  14. //config: Enable support to get SELinux boolean values.
  15. //applet:IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
  16. //kbuild:lib-$(CONFIG_GETSEBOOL) += getsebool.o
  17. //usage:#define getsebool_trivial_usage
  18. //usage: "-a or getsebool boolean..."
  19. //usage:#define getsebool_full_usage "\n\n"
  20. //usage: " -a Show all selinux booleans"
  21. #include "libbb.h"
  22. int getsebool_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  23. int getsebool_main(int argc, char **argv)
  24. {
  25. int i, rc = 0, active, pending, len = 0;
  26. char **names;
  27. unsigned opt;
  28. selinux_or_die();
  29. opt = getopt32(argv, "a");
  30. if (opt) { /* -a */
  31. if (argc > 2)
  32. bb_show_usage();
  33. rc = security_get_boolean_names(&names, &len);
  34. if (rc)
  35. bb_perror_msg_and_die("can't get boolean names");
  36. if (!len) {
  37. puts("No booleans");
  38. return 0;
  39. }
  40. }
  41. if (!len) {
  42. if (argc < 2)
  43. bb_show_usage();
  44. len = argc - 1;
  45. names = xmalloc(sizeof(char *) * len);
  46. for (i = 0; i < len; i++)
  47. names[i] = xstrdup(argv[i + 1]);
  48. }
  49. for (i = 0; i < len; i++) {
  50. active = security_get_boolean_active(names[i]);
  51. if (active < 0) {
  52. bb_error_msg_and_die("error getting active value for %s", names[i]);
  53. }
  54. pending = security_get_boolean_pending(names[i]);
  55. if (pending < 0) {
  56. bb_error_msg_and_die("error getting pending value for %s", names[i]);
  57. }
  58. printf("%s --> %s", names[i], (active ? "on" : "off"));
  59. if (pending != active)
  60. printf(" pending: %s", (pending ? "on" : "off"));
  61. bb_putchar('\n');
  62. }
  63. if (ENABLE_FEATURE_CLEAN_UP) {
  64. for (i = 0; i < len; i++)
  65. free(names[i]);
  66. free(names);
  67. }
  68. return rc;
  69. }