setsebool.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * setsebool
  3. * Simple setsebool
  4. * NOTE: -P option requires libsemanage, so this feature is
  5. * omitted in this version
  6. * Yuichi Nakamura <ynakam@hitachisoft.jp>
  7. *
  8. * Licensed under GPLv2, see file LICENSE in this source tree.
  9. */
  10. //config:config SETSEBOOL
  11. //config: bool "setsebool (1.7 kb)"
  12. //config: default n
  13. //config: depends on SELINUX
  14. //config: help
  15. //config: Enable support for change boolean.
  16. //config: semanage and -P option is not supported yet.
  17. //applet:IF_SETSEBOOL(APPLET(setsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
  18. //kbuild:lib-$(CONFIG_SETSEBOOL) += setsebool.o
  19. //usage:#define setsebool_trivial_usage
  20. //usage: "boolean value"
  21. //usage:#define setsebool_full_usage "\n\n"
  22. //usage: "Change boolean setting"
  23. #include "libbb.h"
  24. int setsebool_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  25. int setsebool_main(int argc, char **argv)
  26. {
  27. char *p;
  28. int value;
  29. if (argc != 3)
  30. bb_show_usage();
  31. p = argv[2];
  32. if (LONE_CHAR(p, '1') || strcasecmp(p, "true") == 0 || strcasecmp(p, "on") == 0) {
  33. value = 1;
  34. } else if (LONE_CHAR(p, '0') || strcasecmp(p, "false") == 0 || strcasecmp(p, "off") == 0) {
  35. value = 0;
  36. } else {
  37. bb_show_usage();
  38. }
  39. if (security_set_boolean(argv[1], value) < 0)
  40. bb_simple_error_msg_and_die("can't set boolean");
  41. return 0;
  42. }