getsebool.c 1.4 KB

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