2 * libbb/selinux_common.c
3 * -- common SELinux utility functions
5 * Copyright 2007 KaiGai Kohei <kaigai@kaigai.gr.jp>
8 #include <selinux/context.h>
10 context_t FAST_FUNC set_security_context_component(security_context_t cur_context,
11 char *user, char *role, char *type, char *range)
13 context_t con = context_new(cur_context);
17 if (user && context_user_set(con, user))
19 if (type && context_type_set(con, type))
21 if (range && context_range_set(con, range))
23 if (role && context_role_set(con, role))
32 void FAST_FUNC setfscreatecon_or_die(security_context_t scontext)
34 if (setfscreatecon(scontext) < 0) {
35 /* Can be NULL. All known printf implementations
36 * display "(null)", "<null>" etc */
37 bb_perror_msg_and_die("cannot set default "
38 "file creation context to %s", scontext);
42 void FAST_FUNC selinux_preserve_fcontext(int fdesc)
44 security_context_t context;
46 if (fgetfilecon(fdesc, &context) < 0) {
47 if (errno == ENODATA || errno == ENOTSUP)
49 bb_perror_msg_and_die("fgetfilecon failed");
51 setfscreatecon_or_die(context);