1/* load_policy.c - Load a policy file
2 *
3 * Copyright 2015 The Android Open Source Project
4
5USE_LOAD_POLICY(NEWTOY(load_policy, "<1>1", TOYFLAG_USR|TOYFLAG_SBIN))
6
7config 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
20void load_policy_main(void)
21{
22  int fd = xopenro(*toys.optargs);
23  off_t policy_len = fdlength(fd);
24  char *policy_data = xmmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
25
26  close(fd);
27  if (security_load_policy(policy_data, policy_len) < 0)
28    perror_exit("security_load_policy %s", *toys.optargs);
29
30  munmap(policy_data, policy_len);
31}
32