chiark / gitweb /
log: log_error() and friends add a newline after each line anyway, so avoid including...
[elogind.git] / src / bus-proxyd / bus-proxyd.c
index 3b6e3399bbbd4961e5a9d1a7f2205fb82992512d..c4da8d6d7f26493b9fc4efebb55bb585094019aa 100644 (file)
@@ -365,6 +365,8 @@ int main(int argc, char *argv[]) {
         int r, in_fd, out_fd;
         bool got_hello = false;
         bool is_unix;
+        struct ucred ucred = {};
+        _cleanup_free_ char *peersec = NULL;
 
         log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
         log_parse_environment();
@@ -382,7 +384,7 @@ int main(int argc, char *argv[]) {
                 in_fd = SD_LISTEN_FDS_START;
                 out_fd = SD_LISTEN_FDS_START;
         } else {
-                log_error("Illegal number of file descriptors passed\n");
+                log_error("Illegal number of file descriptors passed");
                 goto finish;
         }
 
@@ -390,6 +392,11 @@ int main(int argc, char *argv[]) {
                 sd_is_socket(in_fd, AF_UNIX, 0, 0) > 0 &&
                 sd_is_socket(out_fd, AF_UNIX, 0, 0) > 0;
 
+        if (is_unix) {
+                getpeercred(in_fd, &ucred);
+                getpeersec(in_fd, &peersec);
+        }
+
         r = sd_bus_new(&a);
         if (r < 0) {
                 log_error("Failed to allocate bus: %s", strerror(-r));
@@ -408,6 +415,18 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
+        if (ucred.pid > 0) {
+                a->fake_creds.pid = ucred.pid;
+                a->fake_creds.uid = ucred.uid;
+                a->fake_creds.gid = ucred.gid;
+                a->fake_creds_valid = true;
+        }
+
+        if (peersec) {
+                a->fake_label = peersec;
+                peersec = NULL;
+        }
+
         r = sd_bus_start(a);
         if (r < 0) {
                 log_error("Failed to start bus client: %s", strerror(-r));
@@ -461,7 +480,7 @@ int main(int argc, char *argv[]) {
                 log_debug("Failed to rename process: %s", strerror(-r));
 
         if (a->is_kernel) {
-                _cleanup_free_ char *match;
+                _cleanup_free_ char *match = NULL;
                 const char *unique;
 
                 r = sd_bus_get_unique_name(a, &unique);