Blame SOURCES/0189-bus-creds-always-set-SD_BUS_CREDS_PID-when-we-set-pi.patch

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