10f66f451Sopenharmony_ci/* load_policy.c - Load an SELinux policy file 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2015 The Android Open Source Project 40f66f451Sopenharmony_ci 50f66f451Sopenharmony_ciUSE_LOAD_POLICY(NEWTOY(load_policy, "<1>1", TOYFLAG_USR|TOYFLAG_SBIN)) 60f66f451Sopenharmony_ci 70f66f451Sopenharmony_ciconfig LOAD_POLICY 80f66f451Sopenharmony_ci bool "load_policy" 90f66f451Sopenharmony_ci depends on TOYBOX_SELINUX 100f66f451Sopenharmony_ci default y 110f66f451Sopenharmony_ci help 120f66f451Sopenharmony_ci usage: load_policy FILE 130f66f451Sopenharmony_ci 140f66f451Sopenharmony_ci Load the specified SELinux policy file. 150f66f451Sopenharmony_ci*/ 160f66f451Sopenharmony_ci 170f66f451Sopenharmony_ci#define FOR_load_policy 180f66f451Sopenharmony_ci#include "toys.h" 190f66f451Sopenharmony_ci 200f66f451Sopenharmony_civoid load_policy_main(void) 210f66f451Sopenharmony_ci{ 220f66f451Sopenharmony_ci int fd = xopenro(*toys.optargs); 230f66f451Sopenharmony_ci off_t policy_len = fdlength(fd); 240f66f451Sopenharmony_ci char *policy_data = xmmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0); 250f66f451Sopenharmony_ci 260f66f451Sopenharmony_ci close(fd); 270f66f451Sopenharmony_ci if (security_load_policy(policy_data, policy_len) < 0) 280f66f451Sopenharmony_ci perror_exit("security_load_policy %s", *toys.optargs); 290f66f451Sopenharmony_ci 300f66f451Sopenharmony_ci munmap(policy_data, policy_len); 310f66f451Sopenharmony_ci} 32