chiark / gitweb /
bus-proxyd: explicitly address messages to unique and well-known name
[elogind.git] / src / journal / journald-native.c
index 6a9ae8a6ceabbce87cbf548c4844bedb0e60802f..3c60b22eaf5550af35c2de30fb7afb4fa5f48077 100644 (file)
@@ -33,6 +33,7 @@
 #include "journald-console.h"
 #include "journald-syslog.h"
 #include "journald-wall.h"
+#include "memfd-util.h"
 
 bool valid_user_field(const char *p, size_t l, bool allow_protected) {
         const char *a;
@@ -69,15 +70,15 @@ bool valid_user_field(const char *p, size_t l, bool allow_protected) {
         return true;
 }
 
-static bool allow_object_pid(struct ucred *ucred) {
+static bool allow_object_pid(const struct ucred *ucred) {
         return ucred && ucred->uid == 0;
 }
 
 void server_process_native_message(
                 Server *s,
                 const void *buffer, size_t buffer_size,
-                struct ucred *ucred,
-                struct timeval *tv,
+                const struct ucred *ucred,
+                const struct timeval *tv,
                 const char *label, size_t label_len) {
 
         struct iovec *iovec = NULL;
@@ -302,8 +303,8 @@ finish:
 void server_process_native_file(
                 Server *s,
                 int fd,
-                struct ucred *ucred,
-                struct timeval *tv,
+                const struct ucred *ucred,
+                const struct timeval *tv,
                 const char *label, size_t label_len) {
 
         struct stat st;
@@ -319,9 +320,7 @@ void server_process_native_file(
         /* If it's a memfd, check if it is sealed. If so, we can just
          * use map it and use it, and do not need to copy the data
          * out. */
-        r = fcntl(fd, F_GET_SEALS);
-        sealed = r >= 0 &&
-                (r & (F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_SEAL)) == (F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_SEAL);
+        sealed = memfd_get_sealed(fd) > 0;
 
         if (!sealed && (!ucred || ucred->uid != 0)) {
                 _cleanup_free_ char *sl = NULL, *k = NULL;
@@ -413,7 +412,8 @@ void server_process_native_file(
 }
 
 int server_open_native_socket(Server*s) {
-        int one, r;
+        static const int one = 1;
+        int r;
 
         assert(s);
 
@@ -441,7 +441,6 @@ int server_open_native_socket(Server*s) {
         } else
                 fd_nonblock(s->native_fd, 1);
 
-        one = 1;
         r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
         if (r < 0) {
                 log_error("SO_PASSCRED failed: %m");
@@ -450,14 +449,12 @@ int server_open_native_socket(Server*s) {
 
 #ifdef HAVE_SELINUX
         if (mac_selinux_use()) {
-                one = 1;
                 r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
                 if (r < 0)
                         log_warning("SO_PASSSEC failed: %m");
         }
 #endif
 
-        one = 1;
         r = setsockopt(s->native_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one));
         if (r < 0) {
                 log_error("SO_TIMESTAMP failed: %m");