3
0

getsebool.c 1.6 KB

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