daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Blob Blame History Raw
From da4f4b5c330ad648c9ca9c33e1f0e65148042c12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Sat, 6 Jun 2015 21:36:52 -0400
Subject: [PATCH] journald: simplify context handling

By using our homegrown function we can dispense with all the iffdefery.

Cherry-picked from: 2de56f7
Related: #1230190
---
 src/journal/journald-stream.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index 11b852d39d..15a554c34d 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -57,10 +57,7 @@ struct StdoutStream {
         int fd;
 
         struct ucred ucred;
-#ifdef HAVE_SELINUX
-        security_context_t security_context;
-#endif
-
+        char *label;
         char *identifier;
         char *unit_id;
         int priority;
@@ -84,8 +81,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
         char syslog_facility[sizeof("SYSLOG_FACILITY=")-1 + DECIMAL_STR_MAX(int) + 1];
         _cleanup_free_ char *message = NULL, *syslog_identifier = NULL;
         unsigned n = 0;
-        char *label = NULL;
-        size_t label_len = 0;
+        size_t label_len;
 
         assert(s);
         assert(p);
@@ -130,14 +126,8 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
         if (message)
                 IOVEC_SET_STRING(iovec[n++], message);
 
-#ifdef HAVE_SELINUX
-        if (s->security_context) {
-                label = (char*) s->security_context;
-                label_len = strlen((char*) s->security_context);
-        }
-#endif
-
-        server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, label, label_len, s->unit_id, priority, 0);
+        label_len = s->label ? strlen(s->label) : 0;
+        server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, s->label, label_len, s->unit_id, priority, 0);
         return 0;
 }
 
@@ -343,11 +333,7 @@ void stdout_stream_free(StdoutStream *s) {
 
         safe_close(s->fd);
 
-#ifdef HAVE_SELINUX
-        if (s->security_context)
-                freecon(s->security_context);
-#endif
-
+        free(s->label);
         free(s->identifier);
         free(s->unit_id);
         free(s);
@@ -396,8 +382,9 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
 
 #ifdef HAVE_SELINUX
         if (mac_selinux_use()) {
-                if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
-                        log_error_errno(errno, "Failed to determine peer security context: %m");
+                r = getpeersec(fd, &stream->label);
+                if (r < 0 && r != -EOPNOTSUPP)
+                        (void) log_warning_errno(r, "Failed to determine peer security context: %m");
         }
 #endif