2007-03-12 03:46:02 +05:30
|
|
|
/*
|
|
|
|
* libbb/selinux_common.c
|
|
|
|
* -- common SELinux utility functions
|
2007-03-20 17:00:28 +05:30
|
|
|
*
|
2007-03-12 03:46:02 +05:30
|
|
|
* Copyright 2007 KaiGai Kohei <kaigai@kaigai.gr.jp>
|
2008-12-07 06:22:58 +05:30
|
|
|
*
|
|
|
|
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
2007-03-12 03:46:02 +05:30
|
|
|
*/
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2007-03-12 03:46:02 +05:30
|
|
|
#include <selinux/context.h>
|
|
|
|
|
2008-06-27 08:22:20 +05:30
|
|
|
context_t FAST_FUNC set_security_context_component(security_context_t cur_context,
|
2007-03-12 03:46:02 +05:30
|
|
|
char *user, char *role, char *type, char *range)
|
|
|
|
{
|
|
|
|
context_t con = context_new(cur_context);
|
|
|
|
if (!con)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (user && context_user_set(con, user))
|
|
|
|
goto error;
|
|
|
|
if (type && context_type_set(con, type))
|
|
|
|
goto error;
|
|
|
|
if (range && context_range_set(con, range))
|
|
|
|
goto error;
|
|
|
|
if (role && context_role_set(con, role))
|
|
|
|
goto error;
|
|
|
|
return con;
|
|
|
|
|
|
|
|
error:
|
|
|
|
context_free(con);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-03-12 23:52:55 +05:30
|
|
|
|
2008-06-27 08:22:20 +05:30
|
|
|
void FAST_FUNC setfscreatecon_or_die(security_context_t scontext)
|
2007-03-12 23:52:55 +05:30
|
|
|
{
|
|
|
|
if (setfscreatecon(scontext) < 0) {
|
|
|
|
/* Can be NULL. All known printf implementations
|
|
|
|
* display "(null)", "<null>" etc */
|
2009-11-13 13:38:27 +05:30
|
|
|
bb_perror_msg_and_die("can't set default "
|
2007-03-12 23:52:55 +05:30
|
|
|
"file creation context to %s", scontext);
|
|
|
|
}
|
|
|
|
}
|
2007-10-20 07:30:49 +05:30
|
|
|
|
2008-06-27 08:22:20 +05:30
|
|
|
void FAST_FUNC selinux_preserve_fcontext(int fdesc)
|
2007-10-20 07:30:49 +05:30
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|