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