chiark / gitweb /
libsystemd-bus: add sd_bus_translate_attach_flags()
authorDaniel Mack <zonque@gmail.com>
Fri, 29 Nov 2013 16:21:39 +0000 (17:21 +0100)
committerDaniel Mack <zonque@gmail.com>
Fri, 29 Nov 2013 21:01:34 +0000 (22:01 +0100)
Factor out code from sd_bus_negotiate_attach_creds() to a generic
translate function, so it can be used from other places.

src/libsystemd-bus/bus-kernel.c
src/libsystemd-bus/bus-kernel.h
src/libsystemd-bus/sd-bus.c

index 1b586d8..1b54ba5 100644 (file)
@@ -566,6 +566,39 @@ static int bus_kernel_translate_message(sd_bus *bus, struct kdbus_msg *k, sd_bus
         return translate[found->type](bus, k, d, ret);
 }
 
+int kdbus_translate_attach_flags(uint64_t mask, uint64_t *kdbus_mask) {
+
+        uint64_t m = 0;
+
+        SET_FLAG(m, KDBUS_ATTACH_CREDS,
+                 !!(mask & (SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID)));
+
+        SET_FLAG(m, KDBUS_ATTACH_COMM,
+                 !!(mask & (SD_BUS_CREDS_COMM|SD_BUS_CREDS_TID_COMM)));
+
+        SET_FLAG(m, KDBUS_ATTACH_EXE,
+                 !!(mask & SD_BUS_CREDS_EXE));
+
+        SET_FLAG(m, KDBUS_ATTACH_CMDLINE,
+                 !!(mask & SD_BUS_CREDS_CMDLINE));
+
+        SET_FLAG(m, KDBUS_ATTACH_CGROUP,
+                 !!(mask & (SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID)));
+
+        SET_FLAG(m, KDBUS_ATTACH_CAPS,
+                 !!(mask & (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS)));
+
+        SET_FLAG(m, KDBUS_ATTACH_SECLABEL,
+                 !!(mask & SD_BUS_CREDS_SELINUX_CONTEXT));
+
+        SET_FLAG(m, KDBUS_ATTACH_AUDIT,
+                 !!(mask & (SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID)));
+
+        *kdbus_mask = m;
+
+        return 0;
+}
+
 static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_message **ret) {
         sd_bus_message *m = NULL;
         struct kdbus_item *d;
index 779a7de..18ded49 100644 (file)
@@ -70,3 +70,4 @@ void bus_kernel_flush_memfd(sd_bus *bus);
 int bus_kernel_parse_unique_name(const char *s, uint64_t *id);
 
 int sd_bus_kernel_translate_request_name_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
+int kdbus_translate_attach_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
index bfa6ba4..a894af0 100644 (file)
@@ -290,33 +290,7 @@ _public_ int sd_bus_negotiate_attach_creds(sd_bus *bus, uint64_t mask) {
         assert_return(bus->state == BUS_UNSET, -EPERM);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_CREDS,
-                 !!(mask & (SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID)));
-
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_COMM,
-                 !!(mask & (SD_BUS_CREDS_COMM|SD_BUS_CREDS_TID_COMM)));
-
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_EXE,
-                 !!(mask & SD_BUS_CREDS_EXE));
-
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_CMDLINE,
-                 !!(mask & SD_BUS_CREDS_CMDLINE));
-
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_CGROUP,
-                 !!(mask & (SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID)));
-
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_CAPS,
-                 !!(mask & (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS)));
-
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_SECLABEL,
-                 !!(mask & SD_BUS_CREDS_SELINUX_CONTEXT));
-
-        SET_FLAG(bus->attach_flags, KDBUS_ATTACH_AUDIT,
-                 !!(mask & (SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID)));
-
-        bus->creds_mask = mask;
-
-        return 0;
+        return kdbus_translate_attach_flags(mask, &bus->creds_mask);
 }
 
 _public_ int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t server_id) {