chiark / gitweb /
bus-proxyd: keep track of names acquired by legacy client
authorDaniel Mack <daniel@zonque.org>
Wed, 24 Sep 2014 15:10:31 +0000 (17:10 +0200)
committerDaniel Mack <daniel@zonque.org>
Tue, 11 Nov 2014 13:14:01 +0000 (14:14 +0100)
Store names successfully acquired by the legacy client into a hashmap.
We need to take these names into account when checking for send policies.

src/bus-proxyd/bus-proxyd.c

index 88346edeef87fe4a9a5fd1a17b04907ab23b5af4..aaa79243cf8d2b435852b6a1e3730427557e6977 100644 (file)
@@ -51,6 +51,8 @@ static char *arg_command_line_buffer = NULL;
 static bool arg_drop_privileges = false;
 static char **arg_configuration = NULL;
 
+static Hashmap *names_hash = NULL;
+
 static int help(void) {
 
         printf("%s [OPTIONS...]\n\n"
@@ -837,6 +839,8 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
                         return synthetic_reply_method_errno(m, r, NULL);
                 }
 
+                hashmap_remove(names_hash, name);
+
                 return synthetic_reply_method_return(m, "u", BUS_NAME_RELEASED);
 
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "ReloadConfig")) {
@@ -849,6 +853,7 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "RequestName")) {
                 const char *name;
                 uint32_t flags, param;
+                bool in_queue;
 
                 r = sd_bus_message_read(m, "su", &name, &flags);
                 if (r < 0)
@@ -876,7 +881,13 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
                         return synthetic_reply_method_errno(m, r, NULL);
                 }
 
-                if (r == 0)
+                in_queue = (r == 0);
+
+                r = hashmap_put(names_hash, name, NULL);
+                if (r < 0)
+                        return synthetic_reply_method_errno(m, r, NULL);
+
+                if (in_queue)
                         return synthetic_reply_method_return(m, "u", BUS_NAME_IN_QUEUE);
 
                 return synthetic_reply_method_return(m, "u", BUS_NAME_PRIMARY_OWNER);
@@ -1186,6 +1197,12 @@ int main(int argc, char *argv[]) {
                         goto finish;
         }
 
+        names_hash = hashmap_new(&string_hash_ops);
+        if (!names_hash) {
+                log_oom();
+                goto finish;
+        }
+
         r = sd_bus_new(&a);
         if (r < 0) {
                 log_error("Failed to allocate bus: %s", strerror(-r));
@@ -1514,6 +1531,7 @@ finish:
 
         policy_free(&policy);
         strv_free(arg_configuration);
+        hashmap_free(names_hash);
         free(arg_address);
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;