2 * libbb/selinux_common.c
3 * -- common SELinux utility functions
5 * Copyright 2007 KaiGai Kohei <kaigai@kaigai.gr.jp>
7 * Licensed under GPLv2, see file LICENSE in this source tree.
10 #include <selinux/context.h>
12 context_t FAST_FUNC
set_security_context_component(security_context_t cur_context
,
13 char *user
, char *role
, char *type
, char *range
)
15 context_t con
= context_new(cur_context
);
19 if (user
&& context_user_set(con
, user
))
21 if (type
&& context_type_set(con
, type
))
23 if (range
&& context_range_set(con
, range
))
25 if (role
&& context_role_set(con
, role
))
34 void FAST_FUNC
setfscreatecon_or_die(security_context_t scontext
)
36 if (setfscreatecon(scontext
) < 0) {
37 /* Can be NULL. All known printf implementations
38 * display "(null)", "<null>" etc */
39 bb_perror_msg_and_die("can't set default "
40 "file creation context to %s", scontext
);
44 void FAST_FUNC
selinux_preserve_fcontext(int fdesc
)
46 security_context_t context
;
48 if (fgetfilecon(fdesc
, &context
) < 0) {
49 if (errno
== ENODATA
|| errno
== ENOTSUP
)
51 bb_perror_msg_and_die("fgetfilecon failed");
53 setfscreatecon_or_die(context
);