diff options
Diffstat (limited to 'libselinux/src/setfilecon.c')
-rw-r--r-- | libselinux/src/setfilecon.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libselinux/src/setfilecon.c b/libselinux/src/setfilecon.c new file mode 100644 index 00000000..8c633efb --- /dev/null +++ b/libselinux/src/setfilecon.c @@ -0,0 +1,31 @@ +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <sys/xattr.h> +#include "selinux_internal.h" +#include "policy.h" + +int setfilecon_raw(const char *path, security_context_t context) +{ + return setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, + 0); +} + +hidden_def(setfilecon_raw) + +int setfilecon(const char *path, security_context_t context) +{ + int ret; + security_context_t rcontext = context; + + if (selinux_trans_to_raw_context(context, &rcontext)) + return -1; + + ret = setfilecon_raw(path, rcontext); + + freecon(rcontext); + + return ret; +} |