teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0192-journald-simplify-context-handling.patch

1ff636
From da4f4b5c330ad648c9ca9c33e1f0e65148042c12 Mon Sep 17 00:00:00 2001
1ff636
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
1ff636
Date: Sat, 6 Jun 2015 21:36:52 -0400
1ff636
Subject: [PATCH] journald: simplify context handling
1ff636
1ff636
By using our homegrown function we can dispense with all the iffdefery.
1ff636
1ff636
Cherry-picked from: 2de56f7
1ff636
Related: #1230190
1ff636
---
1ff636
 src/journal/journald-stream.c | 29 ++++++++---------------------
1ff636
 1 file changed, 8 insertions(+), 21 deletions(-)
1ff636
1ff636
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
181b3f
index 11b852d39..15a554c34 100644
1ff636
--- a/src/journal/journald-stream.c
1ff636
+++ b/src/journal/journald-stream.c
1ff636
@@ -57,10 +57,7 @@ struct StdoutStream {
1ff636
         int fd;
1ff636
 
1ff636
         struct ucred ucred;
1ff636
-#ifdef HAVE_SELINUX
1ff636
-        security_context_t security_context;
1ff636
-#endif
1ff636
-
1ff636
+        char *label;
1ff636
         char *identifier;
1ff636
         char *unit_id;
1ff636
         int priority;
1ff636
@@ -84,8 +81,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
1ff636
         char syslog_facility[sizeof("SYSLOG_FACILITY=")-1 + DECIMAL_STR_MAX(int) + 1];
1ff636
         _cleanup_free_ char *message = NULL, *syslog_identifier = NULL;
1ff636
         unsigned n = 0;
1ff636
-        char *label = NULL;
1ff636
-        size_t label_len = 0;
1ff636
+        size_t label_len;
1ff636
 
1ff636
         assert(s);
1ff636
         assert(p);
1ff636
@@ -130,14 +126,8 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
1ff636
         if (message)
1ff636
                 IOVEC_SET_STRING(iovec[n++], message);
1ff636
 
1ff636
-#ifdef HAVE_SELINUX
1ff636
-        if (s->security_context) {
1ff636
-                label = (char*) s->security_context;
1ff636
-                label_len = strlen((char*) s->security_context);
1ff636
-        }
1ff636
-#endif
1ff636
-
1ff636
-        server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, label, label_len, s->unit_id, priority, 0);
1ff636
+        label_len = s->label ? strlen(s->label) : 0;
1ff636
+        server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, s->label, label_len, s->unit_id, priority, 0);
1ff636
         return 0;
1ff636
 }
1ff636
 
1ff636
@@ -343,11 +333,7 @@ void stdout_stream_free(StdoutStream *s) {
1ff636
 
1ff636
         safe_close(s->fd);
1ff636
 
1ff636
-#ifdef HAVE_SELINUX
1ff636
-        if (s->security_context)
1ff636
-                freecon(s->security_context);
1ff636
-#endif
1ff636
-
1ff636
+        free(s->label);
1ff636
         free(s->identifier);
1ff636
         free(s->unit_id);
1ff636
         free(s);
1ff636
@@ -396,8 +382,9 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
1ff636
 
1ff636
 #ifdef HAVE_SELINUX
1ff636
         if (mac_selinux_use()) {
1ff636
-                if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
1ff636
-                        log_error_errno(errno, "Failed to determine peer security context: %m");
1ff636
+                r = getpeersec(fd, &stream->label);
1ff636
+                if (r < 0 && r != -EOPNOTSUPP)
1ff636
+                        (void) log_warning_errno(r, "Failed to determine peer security context: %m");
1ff636
         }
1ff636
 #endif
1ff636