• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* load_policy.c - Load a policy file
2  *
3  * Copyright 2015 The Android Open Source Project
4 
5 USE_LOAD_POLICY(NEWTOY(load_policy, "<1>1", TOYFLAG_USR|TOYFLAG_SBIN))
6 
7 config LOAD_POLICY
8   bool "load_policy"
9   depends on TOYBOX_SELINUX
10   default y
11   help
12     usage: load_policy FILE
13 
14     Load the specified policy file.
15 */
16 
17 #define FOR_load_policy
18 #include "toys.h"
19 
load_policy_main(void)20 void load_policy_main(void)
21 {
22   char *path = *toys.optargs;
23   int fd = xopen(path, O_RDONLY);
24   off_t policy_len = fdlength(fd);
25   char *policy_data = mmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
26 
27   close(fd);
28   if (!policy_data || security_load_policy(policy_data, policy_len) < 0)
29     perror_exit("Couldn't %s %s", policy_data ? "load" : "read", path);
30 
31   munmap(policy_data, policy_len);
32 }
33