load_policy.c 675 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * load_policy
  3. * This implementation is based on old load_policy to be small.
  4. * Author: Yuichi Nakamura <ynakam@hitachisoft.jp>
  5. */
  6. #include "libbb.h"
  7. int load_policy_main(int argc, char **argv);
  8. int load_policy_main(int argc, char **argv)
  9. {
  10. int fd;
  11. struct stat st;
  12. void *data;
  13. if (argc != 2) {
  14. bb_show_usage();
  15. }
  16. fd = xopen(argv[1], O_RDONLY);
  17. if (fstat(fd, &st) < 0) {
  18. bb_perror_msg_and_die("can't fstat");
  19. }
  20. data = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
  21. if (data == MAP_FAILED) {
  22. bb_perror_msg_and_die("can't mmap");
  23. }
  24. if (security_load_policy(data, st.st_size) < 0) {
  25. bb_perror_msg_and_die("can't load policy");
  26. }
  27. return 0;
  28. }