[systemd-commits] 6 commits - Makefile.am README TODO src/bus-proxyd src/libsystemd-bus src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Sun Dec 22 19:21:38 PST 2013


 Makefile.am                        |    2 
 README                             |    3 
 TODO                               |    3 
 src/bus-proxyd/bus-proxyd.c        |  381 +++++++++++++++++++++++++++++++------
 src/libsystemd-bus/bus-bloom.c     |   20 +
 src/libsystemd-bus/bus-container.c |    4 
 src/libsystemd-bus/bus-control.c   |   26 +-
 src/libsystemd-bus/bus-message.c   |   10 
 src/libsystemd-bus/bus-message.h   |    2 
 src/libsystemd-bus/bus-socket.c    |   34 +--
 src/libsystemd-bus/bus-socket.h    |    3 
 src/libsystemd-bus/sd-bus.c        |    2 
 src/shared/MurmurHash3.c           |  349 ---------------------------------
 src/shared/MurmurHash3.h           |   38 ---
 14 files changed, 383 insertions(+), 494 deletions(-)

New commits:
commit 8f04d2ebbaa5f330e5240d29917c02bce9892cff
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Dec 23 03:43:43 2013 +0100

    bus: make sure to request peer cred only after connect(), not before

diff --git a/src/libsystemd-bus/bus-container.c b/src/libsystemd-bus/bus-container.c
index 02886c4..1989afa 100644
--- a/src/libsystemd-bus/bus-container.c
+++ b/src/libsystemd-bus/bus-container.c
@@ -52,9 +52,7 @@ int bus_container_connect_socket(sd_bus *b) {
 
         b->output_fd = b->input_fd;
 
-        r = bus_socket_setup(b);
-        if (r < 0)
-                return r;
+        bus_socket_setup(b);
 
         child = fork();
         if (child < 0)
diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c
index a7eaf50..1f5d980 100644
--- a/src/libsystemd-bus/bus-socket.c
+++ b/src/libsystemd-bus/bus-socket.c
@@ -602,9 +602,8 @@ static int bus_socket_read_auth(sd_bus *b) {
         return 1;
 }
 
-int bus_socket_setup(sd_bus *b) {
+void bus_socket_setup(sd_bus *b) {
         int enable;
-        socklen_t l;
 
         assert(b);
 
@@ -620,16 +619,20 @@ int bus_socket_setup(sd_bus *b) {
         fd_inc_rcvbuf(b->input_fd, SNDBUF_SIZE);
         fd_inc_sndbuf(b->output_fd, SNDBUF_SIZE);
 
-        /* Get the peer for socketpair() sockets */
-        l = sizeof(b->ucred);
-        if (getsockopt(b->input_fd, SOL_SOCKET, SO_PEERCRED, &b->ucred, &l) >= 0 && l >= sizeof(b->ucred))
-                b->ucred_valid = b->ucred.pid > 0;
-
         b->is_kernel = false;
         b->message_version = 1;
         b->message_endian = 0;
+}
 
-        return 0;
+static void bus_get_peercred(sd_bus *b) {
+        socklen_t l;
+
+        assert(b);
+
+        /* Get the peer for socketpair() sockets */
+        l = sizeof(b->ucred);
+        if (getsockopt(b->input_fd, SOL_SOCKET, SO_PEERCRED, &b->ucred, &l) >= 0 && l >= sizeof(b->ucred))
+                b->ucred_valid = b->ucred.pid > 0;
 }
 
 static int bus_socket_start_auth_client(sd_bus *b) {
@@ -677,6 +680,8 @@ static int bus_socket_start_auth_client(sd_bus *b) {
 int bus_socket_start_auth(sd_bus *b) {
         assert(b);
 
+        bus_get_peercred(b);
+
         b->state = BUS_AUTHENTICATING;
         b->auth_timeout = now(CLOCK_MONOTONIC) + BUS_DEFAULT_TIMEOUT;
 
@@ -707,9 +712,7 @@ int bus_socket_connect(sd_bus *b) {
 
         b->output_fd = b->input_fd;
 
-        r = bus_socket_setup(b);
-        if (r < 0)
-                return r;
+        bus_socket_setup(b);
 
         r = connect(b->input_fd, &b->sockaddr.sa, b->sockaddr_size);
         if (r < 0) {
@@ -771,20 +774,15 @@ int bus_socket_exec(sd_bus *b) {
         close_nointr_nofail(s[1]);
         b->output_fd = b->input_fd = s[0];
 
-        r = bus_socket_setup(b);
-        if (r < 0)
-                return r;
+        bus_socket_setup(b);
 
         return bus_socket_start_auth(b);
 }
 
 int bus_socket_take_fd(sd_bus *b) {
-        int  r;
         assert(b);
 
-        r = bus_socket_setup(b);
-        if (r < 0)
-                return r;
+        bus_socket_setup(b);
 
         return bus_socket_start_auth(b);
 }
diff --git a/src/libsystemd-bus/bus-socket.h b/src/libsystemd-bus/bus-socket.h
index f959787..5a1c7d4 100644
--- a/src/libsystemd-bus/bus-socket.h
+++ b/src/libsystemd-bus/bus-socket.h
@@ -23,7 +23,8 @@
 
 #include "sd-bus.h"
 
-int bus_socket_setup(sd_bus *b);
+void bus_socket_setup(sd_bus *b);
+
 int bus_socket_connect(sd_bus *b);
 int bus_socket_exec(sd_bus *b);
 int bus_socket_take_fd(sd_bus *b);

commit cd789fdf45f188197bf99998e5a8be0f8c614c66
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Dec 23 03:30:41 2013 +0100

    bus: always talk to the full dbus driver object

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 2acd20b..a38ce0c 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -96,7 +96,7 @@ static int bus_request_name_dbus1(sd_bus *bus, const char *name, uint64_t flags)
         r = sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "RequestName",
                         NULL,
@@ -173,7 +173,7 @@ static int bus_release_name_dbus1(sd_bus *bus, const char *name) {
         r = sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "ReleaseName",
                         NULL,
@@ -295,7 +295,7 @@ static int bus_list_names_dbus1(sd_bus *bus, char ***acquired, char ***activatab
                 r = sd_bus_call_method(
                                 bus,
                                 "org.freedesktop.DBus",
-                                "/",
+                                "/org/freedesktop/DBus",
                                 "org.freedesktop.DBus",
                                 "ListNames",
                                 NULL,
@@ -315,7 +315,7 @@ static int bus_list_names_dbus1(sd_bus *bus, char ***acquired, char ***activatab
                 r = sd_bus_call_method(
                                 bus,
                                 "org.freedesktop.DBus",
-                                "/",
+                                "/org/freedesktop/DBus",
                                 "org.freedesktop.DBus",
                                 "ListActivatableNames",
                                 NULL,
@@ -565,7 +565,7 @@ static int bus_get_owner_dbus1(
                 r = sd_bus_call_method(
                                 bus,
                                 "org.freedesktop.DBus",
-                                "/",
+                                "/org/freedesktop/DBus",
                                 "org.freedesktop.DBus",
                                 "GetNameOwner",
                                 NULL,
@@ -603,7 +603,7 @@ static int bus_get_owner_dbus1(
                         r = sd_bus_call_method(
                                         bus,
                                         "org.freedesktop.DBus",
-                                        "/",
+                                        "/org/freedesktop/DBus",
                                         "org.freedesktop.DBus",
                                         "GetConnectionUnixProcessID",
                                         NULL,
@@ -632,7 +632,7 @@ static int bus_get_owner_dbus1(
                         r = sd_bus_call_method(
                                         bus,
                                         "org.freedesktop.DBus",
-                                        "/",
+                                        "/org/freedesktop/DBus",
                                         "org.freedesktop.DBus",
                                         "GetConnectionUnixUser",
                                         NULL,
@@ -659,7 +659,7 @@ static int bus_get_owner_dbus1(
                         r = sd_bus_call_method(
                                         bus,
                                         "org.freedesktop.DBus",
-                                        "/",
+                                        "/org/freedesktop/DBus",
                                         "org.freedesktop.DBus",
                                         "GetConnectionSELinuxSecurityContext",
                                         NULL,
@@ -1073,7 +1073,7 @@ static int bus_add_match_internal_dbus1(
         return sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "AddMatch",
                         NULL,
@@ -1130,7 +1130,7 @@ static int bus_remove_match_internal_dbus1(
         return sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "RemoveMatch",
                         NULL,

commit a7639e37afd6afeb7b83b11e75894faa06694ba6
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Dec 23 02:59:03 2013 +0100

    bus-proxyd: synthesize NameAcquire/NameLost signals for socket clients

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index d1f9f76..3b6e339 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -123,17 +123,248 @@ static int parse_argv(int argc, char *argv[]) {
         return 1;
 }
 
+static int rename_service(sd_bus *b) {
+        _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+        _cleanup_free_ char *p = NULL, *name = NULL;
+        const char *comm;
+        char **cmdline;
+        uid_t uid;
+        pid_t pid;
+        int r;
+
+        assert(b);
+
+        r = sd_bus_get_peer_creds(b, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_CMDLINE|SD_BUS_CREDS_COMM, &creds);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_creds_get_uid(creds, &uid);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_creds_get_pid(creds, &pid);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_creds_get_cmdline(creds, &cmdline);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_creds_get_comm(creds, &comm);
+        if (r < 0)
+                return r;
+
+        name = uid_to_name(uid);
+        if (!name)
+                return -ENOMEM;
+
+        p = strv_join(cmdline, " ");
+        if (!p)
+                return -ENOMEM;
+
+        /* The status string gets the full command line ... */
+        sd_notifyf(false,
+                   "STATUS=Processing requests from client PID %lu (%s); UID %lu (%s)",
+                   (unsigned long) pid, p,
+                   (unsigned long) uid, name);
+
+        /* ... and the argv line only the short comm */
+        if (arg_command_line_buffer) {
+                size_t m, w;
+
+                m = strlen(arg_command_line_buffer);
+                w = snprintf(arg_command_line_buffer, m,
+                             "[PID %lu/%s; UID %lu/%s]",
+                             (unsigned long) pid, comm,
+                             (unsigned long) uid, name);
+
+                if (m > w)
+                        memset(arg_command_line_buffer + w, 0, m - w);
+        }
+
+        return 0;
+}
+
+static int synthesize_name_acquired(sd_bus *a, sd_bus *b, sd_bus_message *m) {
+        _cleanup_bus_message_unref_ sd_bus_message *n = NULL;
+        const char *name, *old_owner, *new_owner;
+        int r;
+
+        assert(a);
+        assert(b);
+        assert(m);
+
+        /* If we get NameOwnerChanged for our own name, we need to
+         * synthesize NameLost/NameAcquired, since socket clients need
+         * that, even though it is obsoleted on kdbus */
+
+        if (!a->is_kernel)
+                return 0;
+
+        if (!sd_bus_message_is_signal(m, "org.freedesktop.DBus", "NameOwnerChanged") ||
+            !streq_ptr(m->path, "/org/freedesktop/DBus") ||
+            !streq_ptr(m->sender, "org.freedesktop.DBus"))
+                return 0;
+
+        r = sd_bus_message_read(m, "sss", &name, &old_owner, &new_owner);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_rewind(m, true);
+        if (r < 0)
+                return r;
+
+        if (streq(old_owner, a->unique_name)) {
+
+                r = sd_bus_message_new_signal(
+                                b,
+                                "/org/freedesktop/DBus",
+                                "org.freedesktop.DBus",
+                                "NameLost",
+                                &n);
+
+        } else if (streq(new_owner, a->unique_name)) {
+
+                r = sd_bus_message_new_signal(
+                                b,
+                                "/org/freedesktop/DBus",
+                                "org.freedesktop.DBus",
+                                "NameAcquired",
+                                &n);
+        } else
+                return 0;
+
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_append(n, "s", name);
+        if (r < 0)
+                return r;
+
+        r = bus_message_append_sender(n, "org.freedesktop.DBus");
+        if (r < 0)
+                return r;
+
+        r = bus_seal_synthetic_message(b, n);
+        if (r < 0)
+                return r;
+
+        return sd_bus_send(b, n, NULL);
+}
+
+static int process_hello(sd_bus *a, sd_bus *b, sd_bus_message *m, bool *got_hello) {
+        _cleanup_bus_message_unref_ sd_bus_message *n = NULL;
+        bool is_hello;
+        int r;
+
+        assert(a);
+        assert(b);
+        assert(m);
+        assert(got_hello);
+
+        /* As reaction to hello we need to respond with two messages:
+         * the callback reply and the NameAcquired for the unique
+         * name, since hello is otherwise obsolete on kdbus. */
+
+        is_hello =
+                sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "Hello") &&
+                streq_ptr(m->destination, "org.freedesktop.DBus");
+
+        if (!is_hello) {
+
+                if (*got_hello)
+                        return 0;
+
+                log_error("First packet isn't hello (it's %s.%s), aborting.", m->interface, m->member);
+                return -EIO;
+        }
+
+        if (*got_hello) {
+                log_error("Got duplicate hello, aborting.");
+                return -EIO;
+        }
+
+        *got_hello = true;
+
+        if (!a->is_kernel)
+                return 0;
+
+        r = sd_bus_message_new_method_return(m, &n);
+        if (r < 0) {
+                log_error("Failed to generate HELLO reply: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_bus_message_append(n, "s", a->unique_name);
+        if (r < 0) {
+                log_error("Failed to append unique name to HELLO reply: %s", strerror(-r));
+                return r;
+        }
+
+        r = bus_message_append_sender(n, "org.freedesktop.DBus");
+        if (r < 0) {
+                log_error("Failed to append sender to HELLO reply: %s", strerror(-r));
+                return r;
+        }
+
+        r = bus_seal_synthetic_message(b, n);
+        if (r < 0) {
+                log_error("Failed to seal HELLO reply: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_bus_send(b, n, NULL);
+        if (r < 0) {
+                log_error("Failed to send HELLO reply: %s", strerror(-r));
+                return r;
+        }
+
+        n = sd_bus_message_unref(n);
+        r = sd_bus_message_new_signal(
+                        b,
+                        "/org/freedesktop/DBus",
+                        "org.freedesktop.DBus",
+                        "NameAcquired",
+                        &n);
+        if (r < 0) {
+                log_error("Failed to allocate initial NameAcquired message: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_bus_message_append(n, "s", a->unique_name);
+        if (r < 0) {
+                log_error("Failed to append unique name to NameAcquired message: %s", strerror(-r));
+                return r;
+        }
+
+        r = bus_message_append_sender(n, "org.freedesktop.DBus");
+        if (r < 0) {
+                log_error("Failed to append sender to NameAcquired message: %s", strerror(-r));
+                return r;
+        }
+
+        r = bus_seal_synthetic_message(b, n);
+        if (r < 0) {
+                log_error("Failed to seal NameAcquired message: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_bus_send(b, n, NULL);
+        if (r < 0) {
+                log_error("Failed to send NameAcquired message: %s", strerror(-r));
+                return r;
+        }
+
+        return 1;
+}
+
 int main(int argc, char *argv[]) {
 
-        _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
         _cleanup_bus_unref_ sd_bus *a = NULL, *b = NULL;
         sd_id128_t server_id;
         int r, in_fd, out_fd;
-        char **cmdline;
-        const char *comm;
+        bool got_hello = false;
         bool is_unix;
-        uid_t uid;
-        pid_t pid;
 
         log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
         log_parse_environment();
@@ -225,44 +456,59 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        if (sd_bus_get_peer_creds(b, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_CMDLINE|SD_BUS_CREDS_COMM, &creds) >= 0 &&
-            sd_bus_creds_get_uid(creds, &uid) >= 0 &&
-            sd_bus_creds_get_pid(creds, &pid) >= 0 &&
-            sd_bus_creds_get_cmdline(creds, &cmdline) >= 0 &&
-            sd_bus_creds_get_comm(creds, &comm) >= 0) {
-                _cleanup_free_ char *p = NULL, *name = NULL;
+        r = rename_service(b);
+        if (r < 0)
+                log_debug("Failed to rename process: %s", strerror(-r));
 
-                name = uid_to_name(uid);
-                if (!name) {
-                        r = log_oom();
+        if (a->is_kernel) {
+                _cleanup_free_ char *match;
+                const char *unique;
+
+                r = sd_bus_get_unique_name(a, &unique);
+                if (r < 0) {
+                        log_error("Failed to get unique name: %s", strerror(-r));
                         goto finish;
                 }
 
-                p = strv_join(cmdline, " ");
-                if (!p) {
-                        r = log_oom();
+                match = strjoin("type='signal',"
+                                "sender='org.freedesktop.DBus',"
+                                "path='/org/freedesktop/DBus',"
+                                "interface='org.freedesktop.DBus',"
+                                "member='NameOwnerChanged',"
+                                "arg1='",
+                                unique,
+                                "'",
+                                NULL);
+                if (!match) {
+                        log_oom();
                         goto finish;
                 }
 
-                /* The status string gets the full command line ... */
-                sd_notifyf(false,
-                           "STATUS=Processing requests from client PID %lu (%s); UID %lu (%s)",
-                           (unsigned long) pid, p,
-                           (unsigned long) uid, name);
-
-                /* ... and the argv line only the short comm */
-                if (arg_command_line_buffer) {
-                        size_t m, w;
-
-                        m = strlen(arg_command_line_buffer);
-                        w = snprintf(arg_command_line_buffer, m,
-                                     "[PID %lu/%s; UID %lu/%s]",
-                                     (unsigned long) pid, comm,
-                                     (unsigned long) uid, name);
+                r = sd_bus_add_match(a, match, NULL, NULL);
+                if (r < 0) {
+                        log_error("Failed to add match for NameLost: %s", strerror(-r));
+                        goto finish;
+                }
 
-                        if (m > w)
-                                memset(arg_command_line_buffer + w, 0, m - w);
+                free(match);
+                match = strjoin("type='signal',"
+                                "sender='org.freedesktop.DBus',"
+                                "path='/org/freedesktop/DBus',"
+                                "interface='org.freedesktop.DBus',"
+                                "member='NameOwnerChanged',"
+                                "arg2='",
+                                unique,
+                                "'",
+                                NULL);
+                if (!match) {
+                        log_oom();
+                        goto finish;
+                }
 
+                r = sd_bus_add_match(a, match, NULL, NULL);
+                if (r < 0) {
+                        log_error("Failed to add match for NameAcquired: %s", strerror(-r));
+                        goto finish;
                 }
         }
 
@@ -274,34 +520,43 @@ int main(int argc, char *argv[]) {
                 struct pollfd *pollfd;
                 int k;
 
-                r = sd_bus_process(a, &m);
-                if (r < 0) {
-                        /* treat 'connection reset by peer' as clean exit condition */
-                        if (r == -ECONNRESET)
-                                r = 0;
-                        else
-                                log_error("Failed to process bus a: %s", strerror(-r));
-
-                        goto finish;
-                }
+                if (got_hello) {
+                        r = sd_bus_process(a, &m);
+                        if (r < 0) {
+                                /* treat 'connection reset by peer' as clean exit condition */
+                                if (r == -ECONNRESET)
+                                        r = 0;
+                                else
+                                        log_error("Failed to process bus a: %s", strerror(-r));
 
-                if (m) {
-                        /* We officially got EOF, let's quit */
-                        if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected")) {
-                                r = 0;
                                 goto finish;
                         }
 
-                        k = sd_bus_send(b, m, NULL);
-                        if (k < 0) {
-                                r = k;
-                                log_error("Failed to send message: %s", strerror(-r));
-                                goto finish;
+                        if (m) {
+                                /* We officially got EOF, let's quit */
+                                if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected")) {
+                                        r = 0;
+                                        goto finish;
+                                }
+
+                                k = synthesize_name_acquired(a, b, m);
+                                if (k < 0) {
+                                        r = k;
+                                        log_error("Failed to synthesize message: %s", strerror(-r));
+                                        goto finish;
+                                }
+
+                                k = sd_bus_send(b, m, NULL);
+                                if (k < 0) {
+                                        r = k;
+                                        log_error("Failed to send message: %s", strerror(-r));
+                                        goto finish;
+                                }
                         }
-                }
 
-                if (r > 0)
-                        continue;
+                        if (r > 0)
+                                continue;
+                }
 
                 r = sd_bus_process(b, &m);
                 if (r < 0) {
@@ -321,12 +576,22 @@ int main(int argc, char *argv[]) {
                                 goto finish;
                         }
 
-                        k = sd_bus_send(a, m, NULL);
+                        k = process_hello(a, b, m, &got_hello);
                         if (k < 0) {
                                 r = k;
-                                log_error("Failed to send message: %s", strerror(-r));
                                 goto finish;
                         }
+
+                        if (k > 0)
+                                r = k;
+                        else {
+                                k = sd_bus_send(a, m, NULL);
+                                if (k < 0) {
+                                        r = k;
+                                        log_error("Failed to send message: %s", strerror(-r));
+                                        goto finish;
+                                }
+                        }
                 }
 
                 if (r > 0)
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index b0f4b16..39a85d5 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -5524,3 +5524,13 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
 
         return 0;
 }
+
+int bus_message_append_sender(sd_bus_message *m, const char *sender) {
+        assert(m);
+        assert(sender);
+
+        assert_return(!m->sealed, -EPERM);
+        assert_return(!m->sender, -EPERM);
+
+        return message_append_field_string(m, BUS_MESSAGE_HEADER_SENDER, SD_BUS_TYPE_STRING, sender, &m->sender);
+}
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index cd1fb0e..589c819 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -234,3 +234,5 @@ int bus_message_to_errno(sd_bus_message *m);
 int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_error *e, sd_bus_message **m);
 
 int bus_message_remarshal(sd_bus *bus, sd_bus_message **m);
+
+int bus_message_append_sender(sd_bus_message *m, const char *sender);
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 5ea27ee..ee62b34 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -374,7 +374,7 @@ static int bus_send_hello(sd_bus *bus) {
         r = sd_bus_message_new_method_call(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "Hello",
                         &m);

commit 508c6f95cbcf1afd234eb9220554fc13f9698fa5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Dec 23 02:08:12 2013 +0100

    update TODO

diff --git a/TODO b/TODO
index 3704445..49e47ae 100644
--- a/TODO
+++ b/TODO
@@ -50,8 +50,6 @@ Features:
 * code cleanup
   - we probably should replace the left-over uses of strv_append() and replace them by strv_push() or strv_extend()
 
-* switch to SipHash for hashmaps/sets?
-
 * when we detect low battery and no AC on boot, show pretty splash and refuse boot
 
 * move libasyncns into systemd as libsystemd-asyncns
@@ -123,7 +121,6 @@ Features:
   - longer term:
     * priority queues
     * priority inheritance
-  - move to siphash for bloom filter
   - dbus spec updates:
        - kdbus mapping
        - NameLost/NameAcquired obsolete

commit dff91e8b7fa396284768a22b62c36dbe23a3b206
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Dec 23 02:08:05 2013 +0100

    bus: use memcpy() rather than unbounded strcpy()

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index f08d78a..2acd20b 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -803,7 +803,7 @@ static int add_name_change_match(sd_bus *bus,
                 item->name_change.new.id = new_owner_id;
 
                 if (name)
-                        strcpy(item->name_change.name, name);
+                        memcpy(item->name_change.name, name, l);
 
                 /* If the old name is unset or empty, then
                  * this can match against added names */
@@ -854,7 +854,9 @@ static int add_name_change_match(sd_bus *bus,
                 m->cookie = cookie;
 
                 item = m->items;
-                item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change);
+                item->size =
+                        offsetof(struct kdbus_item, id_change) +
+                        sizeof(struct kdbus_notify_id_change);
                 item->id_change.id = name_id;
 
                 /* If the old name is unset or empty, then this can

commit b67f541f130cd4c55da0b74af5fcbb4daeca1937
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Dec 22 23:26:07 2013 +0100

    bus: switch kdbus bloom filter over to SipHash (from MurmurHash3)
    
    Let's try to standardize on a single non-cryptographic hash algorithm,
    and for that SipHash appears to be the best answer.
    
    With this change there are two other hash functions left in systemd: an
    older version of MurmurHash embedded into libudev for the bloom filters
    in udev messages (which is hard to update, given that the we probably
    should stay compatible with older versions of the library). And lookup3
    in the journal files (which we could replace for new files, but which is
    probably not worth the work).

diff --git a/Makefile.am b/Makefile.am
index e1a7361..f4b1958 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -757,8 +757,6 @@ libsystemd_shared_la_SOURCES = \
 	src/shared/output-mode.h \
 	src/shared/MurmurHash2.c \
 	src/shared/MurmurHash2.h \
-	src/shared/MurmurHash3.c \
-	src/shared/MurmurHash3.h \
 	src/shared/acpi-fpdt.h \
 	src/shared/acpi-fpdt.c \
 	src/shared/boot-timestamps.h \
diff --git a/README b/README
index b4c4743..a1058c5 100644
--- a/README
+++ b/README
@@ -31,7 +31,8 @@ AUTHOR:
 LICENSE:
         LGPLv2.1+ for all code
         - except sd-daemon.[ch] and sd-readahead.[ch] which are MIT
-        - except src/shared/MurmurHash[23].c which is Public Domain
+        - except src/shared/MurmurHash2.c which is Public Domain
+        - except src/shared/siphash24.c which is CC0 Public Domain
         - except src/journal/lookup3.c which is Public Domain
         - except src/udev/* which is (currently still) GPLv2, GPLv2+
 
diff --git a/src/libsystemd-bus/bus-bloom.c b/src/libsystemd-bus/bus-bloom.c
index c3ad9f6..9e51334 100644
--- a/src/libsystemd-bus/bus-bloom.c
+++ b/src/libsystemd-bus/bus-bloom.c
@@ -20,16 +20,18 @@
 ***/
 
 #include "util.h"
-#include "MurmurHash3.h"
-
+#include "siphash24.h"
 #include "bus-bloom.h"
 
 static inline void set_bit(uint64_t filter[], unsigned b) {
         filter[b >> 6] |= 1ULL << (b & 63);
 }
 
+#define HASH_KEY1 SD_ID128_MAKE(b9,66,0b,f0,46,70,47,c1,88,75,c4,9c,54,b9,bd,15)
+#define HASH_KEY2 SD_ID128_MAKE(aa,a1,54,a2,e0,71,4b,39,bf,e1,dd,2e,9f,c5,4a,3b)
+
 static void bloom_add_data(uint64_t filter[BLOOM_SIZE/8], const void *data, size_t n) {
-        uint16_t hash[8];
+        uint8_t a[8], b[8];
         unsigned k = 0;
 
         /*
@@ -38,17 +40,19 @@ static void bloom_add_data(uint64_t filter[BLOOM_SIZE/8], const void *data, size
          * m=512   (bits in the filter)
          * k=8     (hash functions)
          *
-         * We calculate a single 128bit MurmurHash value of which we
-         * use 8 parts of 9 bits as individual hash functions.
+         * We calculate a two 64bit SipHash values (for two fixed but
+         * randomly generated hash keys) of which we use 8 parts of 9 bits
+         * as individual hash functions.
          *
          */
 
-        MurmurHash3_x64_128(data, n, 0, hash);
+        siphash24(a, data, n, HASH_KEY1.bytes);
+        siphash24(b, data, n, HASH_KEY2.bytes);
 
         assert_cc(BLOOM_SIZE*8 == 512);
 
-        for (k = 0; k < ELEMENTSOF(hash); k++)
-                set_bit(filter, hash[k] & 511);
+        for (k = 0; k < 8; k++)
+                set_bit(filter, ((uint16_t) a[k] << 1) ^ (uint16_t) b[k]);
 
         /* log_debug("bloom: adding <%.*s>", (int) n, (char*) data); */
 }
diff --git a/src/shared/MurmurHash3.c b/src/shared/MurmurHash3.c
deleted file mode 100644
index aa13873..0000000
--- a/src/shared/MurmurHash3.c
+++ /dev/null
@@ -1,349 +0,0 @@
-//-----------------------------------------------------------------------------
-// MurmurHash3 was written by Austin Appleby, and is placed in the public
-// domain. The author hereby disclaims copyright to this source code.
-
-// Note - The x86 and x64 versions do _not_ produce the same results, as the
-// algorithms are optimized for their respective platforms. You can still
-// compile and run any of them on any platform, but your performance with the
-// non-native version will be less than optimal.
-
-#include "MurmurHash3.h"
-
-//-----------------------------------------------------------------------------
-// Platform-specific functions and macros
-
-// Microsoft Visual Studio
-
-#if defined(_MSC_VER)
-
-#define FORCE_INLINE	__forceinline
-
-#include <stdlib.h>
-
-#define ROTL32(x,y)	_rotl(x,y)
-#define ROTL64(x,y)	_rotl64(x,y)
-
-#define BIG_CONSTANT(x) (x)
-
-// Other compilers
-
-#else	// defined(_MSC_VER)
-
-#define	FORCE_INLINE inline __attribute__((always_inline))
-
-static inline uint32_t rotl32 ( uint32_t x, int8_t r )
-{
-  return (x << r) | (x >> (32 - r));
-}
-
-static inline uint64_t rotl64 ( uint64_t x, int8_t r )
-{
-  return (x << r) | (x >> (64 - r));
-}
-
-#define	ROTL32(x,y)	rotl32(x,y)
-#define ROTL64(x,y)	rotl64(x,y)
-
-#define BIG_CONSTANT(x) (x##LLU)
-
-#endif // !defined(_MSC_VER)
-
-//-----------------------------------------------------------------------------
-// Block read - if your platform needs to do endian-swapping or can only
-// handle aligned reads, do the conversion here
-
-static FORCE_INLINE uint32_t getblock32 ( const uint32_t * p, int i )
-{
-  return p[i];
-}
-
-static FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, int i )
-{
-  return p[i];
-}
-
-//-----------------------------------------------------------------------------
-// Finalization mix - force all bits of a hash block to avalanche
-
-static FORCE_INLINE uint32_t fmix32 ( uint32_t h )
-{
-  h ^= h >> 16;
-  h *= 0x85ebca6b;
-  h ^= h >> 13;
-  h *= 0xc2b2ae35;
-  h ^= h >> 16;
-
-  return h;
-}
-
-//----------
-
-static FORCE_INLINE uint64_t fmix64 ( uint64_t k )
-{
-  k ^= k >> 33;
-  k *= BIG_CONSTANT(0xff51afd7ed558ccd);
-  k ^= k >> 33;
-  k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
-  k ^= k >> 33;
-
-  return k;
-}
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x86_32 ( const void * key, size_t len,
-                          uint32_t seed, void * out )
-{
-  const uint8_t * data = (const uint8_t*)key;
-  const int nblocks = len / 4;
-
-  uint32_t h1 = seed;
-
-  const uint32_t c1 = 0xcc9e2d51;
-  const uint32_t c2 = 0x1b873593;
-
-  const uint8_t * tail;
-  uint32_t k1;
-
-  //----------
-  // body
-
-  const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
-
-  for(int i = -nblocks; i; i++)
-  {
-    k1 = getblock32(blocks,i);
-
-    k1 *= c1;
-    k1 = ROTL32(k1,15);
-    k1 *= c2;
-
-    h1 ^= k1;
-    h1 = ROTL32(h1,13);
-    h1 = h1*5+0xe6546b64;
-  }
-
-  //----------
-  // tail
-
-  tail = (const uint8_t*)(data + nblocks*4);
-
-  k1 = 0;
-
-  switch(len & 3)
-  {
-  case 3: k1 ^= tail[2] << 16;
-  case 2: k1 ^= tail[1] << 8;
-  case 1: k1 ^= tail[0];
-          k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
-  };
-
-  //----------
-  // finalization
-
-  h1 ^= len;
-
-  h1 = fmix32(h1);
-
-  *(uint32_t*)out = h1;
-}
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x86_128 ( const void * key, const size_t len,
-                           uint32_t seed, void * out )
-{
-  const uint8_t * data = (const uint8_t*)key;
-  const int nblocks = len / 16;
-
-  uint32_t h1 = seed;
-  uint32_t h2 = seed;
-  uint32_t h3 = seed;
-  uint32_t h4 = seed;
-
-  const uint32_t c1 = 0x239b961b;
-  const uint32_t c2 = 0xab0e9789;
-  const uint32_t c3 = 0x38b34ae5;
-  const uint32_t c4 = 0xa1e38b93;
-
-  const uint8_t * tail;
-
-  uint32_t k1;
-  uint32_t k2;
-  uint32_t k3;
-  uint32_t k4;
-
-  //----------
-  // body
-
-  const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
-
-  for(int i = -nblocks; i; i++)
-  {
-    k1 = getblock32(blocks,i*4+0);
-    k2 = getblock32(blocks,i*4+1);
-    k3 = getblock32(blocks,i*4+2);
-    k4 = getblock32(blocks,i*4+3);
-
-    k1 *= c1; k1  = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
-
-    h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
-
-    k2 *= c2; k2  = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
-
-    h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
-
-    k3 *= c3; k3  = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
-
-    h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
-
-    k4 *= c4; k4  = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
-
-    h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
-  }
-
-  //----------
-  // tail
-
-  tail = (const uint8_t*)(data + nblocks*16);
-
-  k1 = 0;
-  k2 = 0;
-  k3 = 0;
-  k4 = 0;
-
-  switch(len & 15)
-  {
-  case 15: k4 ^= tail[14] << 16;
-  case 14: k4 ^= tail[13] << 8;
-  case 13: k4 ^= tail[12] << 0;
-           k4 *= c4; k4  = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
-
-  case 12: k3 ^= tail[11] << 24;
-  case 11: k3 ^= tail[10] << 16;
-  case 10: k3 ^= tail[ 9] << 8;
-  case  9: k3 ^= tail[ 8] << 0;
-           k3 *= c3; k3  = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
-
-  case  8: k2 ^= tail[ 7] << 24;
-  case  7: k2 ^= tail[ 6] << 16;
-  case  6: k2 ^= tail[ 5] << 8;
-  case  5: k2 ^= tail[ 4] << 0;
-           k2 *= c2; k2  = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
-
-  case  4: k1 ^= tail[ 3] << 24;
-  case  3: k1 ^= tail[ 2] << 16;
-  case  2: k1 ^= tail[ 1] << 8;
-  case  1: k1 ^= tail[ 0] << 0;
-           k1 *= c1; k1  = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
-  };
-
-  //----------
-  // finalization
-
-  h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
-
-  h1 += h2; h1 += h3; h1 += h4;
-  h2 += h1; h3 += h1; h4 += h1;
-
-  h1 = fmix32(h1);
-  h2 = fmix32(h2);
-  h3 = fmix32(h3);
-  h4 = fmix32(h4);
-
-  h1 += h2; h1 += h3; h1 += h4;
-  h2 += h1; h3 += h1; h4 += h1;
-
-  ((uint32_t*)out)[0] = h1;
-  ((uint32_t*)out)[1] = h2;
-  ((uint32_t*)out)[2] = h3;
-  ((uint32_t*)out)[3] = h4;
-}
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x64_128 ( const void * key, const size_t len,
-                           const uint32_t seed, void * out )
-{
-  const uint8_t * data = (const uint8_t*)key;
-  const int nblocks = len / 16;
-
-  uint64_t h1 = seed;
-  uint64_t h2 = seed;
-
-  const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
-  const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
-
-  const uint8_t *tail;
-
-  uint64_t k1;
-  uint64_t k2;
-
-  //----------
-  // body
-
-  const uint64_t * blocks = (const uint64_t *)(data);
-
-  for(int i = 0; i < nblocks; i++)
-  {
-    k1 = getblock64(blocks,i*2+0);
-    k2 = getblock64(blocks,i*2+1);
-
-    k1 *= c1; k1  = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
-
-    h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
-
-    k2 *= c2; k2  = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
-
-    h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
-  }
-
-  //----------
-  // tail
-
-  tail = (const uint8_t*)(data + nblocks*16);
-
-  k1 = 0;
-  k2 = 0;
-
-  switch(len & 15)
-  {
-  case 15: k2 ^= (uint64_t)(tail[14]) << 48;
-  case 14: k2 ^= (uint64_t)(tail[13]) << 40;
-  case 13: k2 ^= (uint64_t)(tail[12]) << 32;
-  case 12: k2 ^= (uint64_t)(tail[11]) << 24;
-  case 11: k2 ^= (uint64_t)(tail[10]) << 16;
-  case 10: k2 ^= (uint64_t)(tail[ 9]) << 8;
-  case  9: k2 ^= (uint64_t)(tail[ 8]) << 0;
-           k2 *= c2; k2  = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
-
-  case  8: k1 ^= (uint64_t)(tail[ 7]) << 56;
-  case  7: k1 ^= (uint64_t)(tail[ 6]) << 48;
-  case  6: k1 ^= (uint64_t)(tail[ 5]) << 40;
-  case  5: k1 ^= (uint64_t)(tail[ 4]) << 32;
-  case  4: k1 ^= (uint64_t)(tail[ 3]) << 24;
-  case  3: k1 ^= (uint64_t)(tail[ 2]) << 16;
-  case  2: k1 ^= (uint64_t)(tail[ 1]) << 8;
-  case  1: k1 ^= (uint64_t)(tail[ 0]) << 0;
-           k1 *= c1; k1  = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
-  };
-
-  //----------
-  // finalization
-
-  h1 ^= len; h2 ^= len;
-
-  h1 += h2;
-  h2 += h1;
-
-  h1 = fmix64(h1);
-  h2 = fmix64(h2);
-
-  h1 += h2;
-  h2 += h1;
-
-  ((uint64_t*)out)[0] = h1;
-  ((uint64_t*)out)[1] = h2;
-}
-
-//-----------------------------------------------------------------------------
diff --git a/src/shared/MurmurHash3.h b/src/shared/MurmurHash3.h
deleted file mode 100644
index 07c474e..0000000
--- a/src/shared/MurmurHash3.h
+++ /dev/null
@@ -1,38 +0,0 @@
-//-----------------------------------------------------------------------------
-// MurmurHash3 was written by Austin Appleby, and is placed in the public
-// domain. The author hereby disclaims copyright to this source code.
-
-#ifndef _MURMURHASH3_H_
-#define _MURMURHASH3_H_
-
-//-----------------------------------------------------------------------------
-// Platform-specific functions and macros
-
-// Microsoft Visual Studio
-
-#if defined(_MSC_VER)
-
-typedef unsigned char uint8_t;
-typedef unsigned long uint32_t;
-typedef unsigned __int64 uint64_t;
-
-// Other compilers
-
-#else	// defined(_MSC_VER)
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#endif // !defined(_MSC_VER)
-
-//-----------------------------------------------------------------------------
-
-void MurmurHash3_x86_32  ( const void * key, size_t len, uint32_t seed, void * out );
-
-void MurmurHash3_x86_128 ( const void * key, size_t len, uint32_t seed, void * out );
-
-void MurmurHash3_x64_128 ( const void * key, size_t len, uint32_t seed, void * out );
-
-//-----------------------------------------------------------------------------
-
-#endif // _MURMURHASH3_H_



More information about the systemd-commits mailing list