Skip to content

Commit

Permalink
tree-wide: get rid of selinux_context_t (systemd#3732)
Browse files Browse the repository at this point in the history
SELinuxProject/selinux@9eb9c93
deprecated selinux_context_t. Replace with a simple char* everywhere.

Alternative fix for systemd#3719.
  • Loading branch information
keszybz authored and poettering committed Jul 15, 2016
1 parent 8d00539 commit 2ed9688
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/basic/selinux-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#include "util.h"

#ifdef HAVE_SELINUX
DEFINE_TRIVIAL_CLEANUP_FUNC(security_context_t, freecon);
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, freecon);
DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free);

#define _cleanup_security_context_free_ _cleanup_(freeconp)
#define _cleanup_freecon_ _cleanup_(freeconp)
#define _cleanup_context_free_ _cleanup_(context_freep)

static int cached_use = -1;
Expand Down Expand Up @@ -143,7 +143,7 @@ int mac_selinux_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {

r = lstat(path, &st);
if (r >= 0) {
_cleanup_security_context_free_ security_context_t fcon = NULL;
_cleanup_freecon_ char* fcon = NULL;

r = selabel_lookup_raw(label_hnd, &fcon, path, st.st_mode);

Expand Down Expand Up @@ -186,7 +186,7 @@ int mac_selinux_apply(const char *path, const char *label) {
assert(path);
assert(label);

if (setfilecon(path, (security_context_t) label) < 0) {
if (setfilecon(path, label) < 0) {
log_enforcing("Failed to set SELinux security context %s on path %s: %m", label, path);
if (security_getenforce() > 0)
return -errno;
Expand All @@ -199,7 +199,7 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
int r = -EOPNOTSUPP;

#ifdef HAVE_SELINUX
_cleanup_security_context_free_ security_context_t mycon = NULL, fcon = NULL;
_cleanup_freecon_ char *mycon = NULL, *fcon = NULL;
security_class_t sclass;

assert(exe);
Expand All @@ -217,7 +217,7 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
return -errno;

sclass = string_to_security_class("process");
r = security_compute_create_raw(mycon, fcon, sclass, (security_context_t *) label);
r = security_compute_create_raw(mycon, fcon, sclass, label);
if (r < 0)
return -errno;
#endif
Expand Down Expand Up @@ -246,7 +246,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
int r = -EOPNOTSUPP;

#ifdef HAVE_SELINUX
_cleanup_security_context_free_ security_context_t mycon = NULL, peercon = NULL, fcon = NULL;
_cleanup_freecon_ char *mycon = NULL, *peercon = NULL, *fcon = NULL;
_cleanup_context_free_ context_t pcon = NULL, bcon = NULL;
security_class_t sclass;
const char *range = NULL;
Expand Down Expand Up @@ -296,7 +296,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
return -ENOMEM;

sclass = string_to_security_class("process");
r = security_compute_create_raw(mycon, fcon, sclass, (security_context_t *) label);
r = security_compute_create_raw(mycon, fcon, sclass, label);
if (r < 0)
return -errno;
#endif
Expand All @@ -314,7 +314,7 @@ char* mac_selinux_free(char *label) {
return NULL;


freecon((security_context_t) label);
freecon(label);
#endif

return NULL;
Expand All @@ -323,7 +323,7 @@ char* mac_selinux_free(char *label) {
int mac_selinux_create_file_prepare(const char *path, mode_t mode) {

#ifdef HAVE_SELINUX
_cleanup_security_context_free_ security_context_t filecon = NULL;
_cleanup_freecon_ char *filecon = NULL;
int r;

assert(path);
Expand Down Expand Up @@ -383,7 +383,7 @@ int mac_selinux_create_socket_prepare(const char *label) {

assert(label);

if (setsockcreatecon((security_context_t) label) < 0) {
if (setsockcreatecon(label) < 0) {
log_enforcing("Failed to set SELinux security context %s for sockets: %m", label);

if (security_getenforce() == 1)
Expand Down Expand Up @@ -411,7 +411,7 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
/* Binds a socket and label its file system object according to the SELinux policy */

#ifdef HAVE_SELINUX
_cleanup_security_context_free_ security_context_t fcon = NULL;
_cleanup_freecon_ char *fcon = NULL;
const struct sockaddr_un *un;
bool context_changed = false;
char *path;
Expand Down
2 changes: 1 addition & 1 deletion src/core/selinux-access.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ int mac_selinux_generic_access_check(
const char *tclass = NULL, *scon = NULL;
struct audit_info audit_info = {};
_cleanup_free_ char *cl = NULL;
security_context_t fcon = NULL;
char *fcon = NULL;
char **cmdline = NULL;
int r = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/core/selinux-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int mac_selinux_setup(bool *loaded_policy) {
#ifdef HAVE_SELINUX
int enforce = 0;
usec_t before_load, after_load;
security_context_t con;
char *con;
int r;
union selinux_callback cb;
bool initialized = false;
Expand Down
2 changes: 1 addition & 1 deletion src/journal/journald-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ static void dispatch_message_real(
*((char*) mempcpy(stpcpy(x, "_SELINUX_CONTEXT="), label, label_len)) = 0;
IOVEC_SET_STRING(iovec[n++], x);
} else {
security_context_t con;
char *con;

if (getpidcon(ucred->pid, &con) >= 0) {
x = strjoina("_SELINUX_CONTEXT=", con);
Expand Down
2 changes: 1 addition & 1 deletion src/nspawn/nspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ static int inner_child(

#ifdef HAVE_SELINUX
if (arg_selinux_context)
if (setexeccon((security_context_t) arg_selinux_context) < 0)
if (setexeccon(arg_selinux_context) < 0)
return log_error_errno(errno, "setexeccon(\"%s\") failed: %m", arg_selinux_context);
#endif

Expand Down

0 comments on commit 2ed9688

Please sign in to comment.