X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Fselinux_common.c;h=275a761d29b76b436ace882b6e2a0e6ffae8f8d8;hb=781b672b372ade5c1903adbdc4de8dcb16a29a37;hp=d506f0636ba230100d1cc3084ee8305f8fbdb7d6;hpb=39c651e9097e0e55a52c897982d6e84d281f7396;p=oweals%2Fbusybox.git diff --git a/libbb/selinux_common.c b/libbb/selinux_common.c index d506f0636..275a761d2 100644 --- a/libbb/selinux_common.c +++ b/libbb/selinux_common.c @@ -1,13 +1,15 @@ /* * libbb/selinux_common.c * -- common SELinux utility functions - * + * * Copyright 2007 KaiGai Kohei + * + * Licensed under GPLv2, see file LICENSE in this tarball for details. */ -#include "busybox.h" +#include "libbb.h" #include -context_t set_security_context_component(security_context_t cur_context, +context_t FAST_FUNC set_security_context_component(security_context_t cur_context, char *user, char *role, char *type, char *range) { context_t con = context_new(cur_context); @@ -29,7 +31,7 @@ error: return NULL; } -void setfscreatecon_or_die(security_context_t scontext) +void FAST_FUNC setfscreatecon_or_die(security_context_t scontext) { if (setfscreatecon(scontext) < 0) { /* Can be NULL. All known printf implementations @@ -38,3 +40,17 @@ void setfscreatecon_or_die(security_context_t scontext) "file creation context to %s", scontext); } } + +void FAST_FUNC selinux_preserve_fcontext(int fdesc) +{ + security_context_t context; + + if (fgetfilecon(fdesc, &context) < 0) { + if (errno == ENODATA || errno == ENOTSUP) + return; + bb_perror_msg_and_die("fgetfilecon failed"); + } + setfscreatecon_or_die(context); + freecon(context); +} +