richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From 0ca06b7178ac205855238941eef7fe981447822a Mon Sep 17 00:00:00 2001
803fb7
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
803fb7
Date: Sun, 24 May 2015 20:20:06 -0400
803fb7
Subject: [PATCH] bus-creds: always set SD_BUS_CREDS_PID when we set pid in the
803fb7
 mask
803fb7
803fb7
Also reorder the code a bit to be easier to parse.
803fb7
803fb7
Cherry-picked from: 236f83a
803fb7
Related: #1230190
803fb7
---
803fb7
 src/core/selinux-access.c         |  2 +-
803fb7
 src/libsystemd/sd-bus/bus-creds.c | 17 +++++++----------
803fb7
 2 files changed, 8 insertions(+), 11 deletions(-)
803fb7
803fb7
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
803fb7
index 18888747f..ce4f39459 100644
803fb7
--- a/src/core/selinux-access.c
803fb7
+++ b/src/core/selinux-access.c
803fb7
@@ -240,7 +240,7 @@ int mac_selinux_generic_access_check(
803fb7
         audit_info.path = path;
803fb7
         audit_info.cmdline = cl;
803fb7
 
803fb7
-        r = selinux_check_access((security_context_t) scon, fcon, tclass, permission, &audit_info);
803fb7
+        r = selinux_check_access(scon, fcon, tclass, permission, &audit_info);
803fb7
         if (r < 0)
803fb7
                 r = sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "SELinux policy denies access.");
803fb7
 
803fb7
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
803fb7
index ea8a619c5..5b87fa950 100644
803fb7
--- a/src/libsystemd/sd-bus/bus-creds.c
803fb7
+++ b/src/libsystemd/sd-bus/bus-creds.c
803fb7
@@ -698,21 +698,18 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
803fb7
                 return 0;
803fb7
 
803fb7
         /* Try to retrieve PID from creds if it wasn't passed to us */
803fb7
-        if (pid <= 0 && (c->mask & SD_BUS_CREDS_PID))
803fb7
+        if (pid > 0) {
803fb7
+                c->pid = pid;
803fb7
+                c->mask |= SD_BUS_CREDS_PID;
803fb7
+        } else if (c->mask & SD_BUS_CREDS_PID)
803fb7
                 pid = c->pid;
803fb7
+        else
803fb7
+                /* Without pid we cannot do much... */
803fb7
+                return 0;
803fb7
 
803fb7
         if (tid <= 0 && (c->mask & SD_BUS_CREDS_TID))
803fb7
                 tid = c->pid;
803fb7
 
803fb7
-        /* Without pid we cannot do much... */
803fb7
-        if (pid <= 0)
803fb7
-                return 0;
803fb7
-
803fb7
-        if (pid > 0) {
803fb7
-                c->pid = pid;
803fb7
-                c->mask |= SD_BUS_CREDS_PID;
803fb7
-        }
803fb7
-
803fb7
         if (tid > 0) {
803fb7
                 c->tid = tid;
803fb7
                 c->mask |= SD_BUS_CREDS_TID;