aboutsummaryrefslogtreecommitdiff
path: root/toys/android
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-03-27 20:50:28 -0500
committerRob Landley <rob@landley.net>2015-03-27 20:50:28 -0500
commit9c25bcb645c754f4c09d9d6b8da41bbded862f6c (patch)
treedd03838cf9f4dca531b0a19820fa9e873617f93f /toys/android
parentd410645aec7d51d49884a05863cf10497e43f0bc (diff)
downloadtoybox-9c25bcb645c754f4c09d9d6b8da41bbded862f6c.tar.gz
Promote load_policy to android.
Diffstat (limited to 'toys/android')
-rw-r--r--toys/android/load_policy.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/toys/android/load_policy.c b/toys/android/load_policy.c
new file mode 100644
index 00000000..aa59f36c
--- /dev/null
+++ b/toys/android/load_policy.c
@@ -0,0 +1,37 @@
+/* load_policy.c - Load a policy file
+ *
+ * Copyright 2015 The Android Open Source Project
+
+USE_LOAD_POLICY(NEWTOY(load_policy, "<1>1", TOYFLAG_USR|TOYFLAG_SBIN))
+
+config LOAD_POLICY
+ bool "load_policy"
+ depends on TOYBOX_SELINUX
+ default y
+ help
+ usage: load_policy FILE
+
+ Load the specified policy file.
+*/
+
+#define FOR_load_policy
+#include "toys.h"
+
+void load_policy_main(void)
+{
+ char *path = *toys.optargs;
+ char *policy_data = 0;
+ off_t policy_len;
+ int fd;
+
+ if ((fd = open(path, O_RDONLY)) != -1) {
+ policy_len = fdlength(fd);
+ policy_data = mmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
+ }
+
+ if (!policy_data || security_load_policy(policy_data, policy_len) < 0)
+ perror_exit("Couldn't %s %s: %s", policy_data ? "load" : "read", path);
+
+ munmap(policy_data, policy_len);
+}