getsebool.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * getsebool
  3. *
  4. * Based on libselinux 1.33.1
  5. * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp>
  6. *
  7. */
  8. #include "libbb.h"
  9. int getsebool_main(int argc, char **argv);
  10. int getsebool_main(int argc, char **argv)
  11. {
  12. int i, rc = 0, active, pending, len = 0;
  13. char **names;
  14. unsigned opt;
  15. selinux_or_die();
  16. opt = getopt32(argv, "a");
  17. if (opt) { /* -a */
  18. if (argc > 2)
  19. bb_show_usage();
  20. rc = security_get_boolean_names(&names, &len);
  21. if (rc)
  22. bb_perror_msg_and_die("cannot get boolean names");
  23. if (!len) {
  24. puts("No booleans");
  25. return 0;
  26. }
  27. }
  28. if (!len) {
  29. if (argc < 2)
  30. bb_show_usage();
  31. len = argc - 1;
  32. names = xmalloc(sizeof(char *) * len);
  33. for (i = 0; i < len; i++)
  34. names[i] = xstrdup(argv[i + 1]);
  35. }
  36. for (i = 0; i < len; i++) {
  37. active = security_get_boolean_active(names[i]);
  38. if (active < 0) {
  39. bb_error_msg_and_die("error getting active value for %s", names[i]);
  40. }
  41. pending = security_get_boolean_pending(names[i]);
  42. if (pending < 0) {
  43. bb_error_msg_and_die("error getting pending value for %s", names[i]);
  44. }
  45. printf("%s --> %s", names[i], (active ? "on" : "off"));
  46. if (pending != active)
  47. printf(" pending: %s", (pending ? "on" : "off"));
  48. putchar('\n');
  49. }
  50. if (ENABLE_FEATURE_CLEAN_UP) {
  51. for (i = 0; i < len; i++)
  52. free(names[i]);
  53. free(names);
  54. }
  55. return rc;
  56. }