diff options
author | Ray Strode <rstrode@redhat.com> | 2009-01-05 01:05:37 -0500 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2009-01-05 01:05:37 -0500 |
commit | d5f5aaa1a76ecc152adcc16dc9a7525b014217bd (patch) | |
tree | 64279e1acc389793183c44150387cc8495b1ce39 | |
parent | d923e259629ee10213d78ded2e5b173084b362e6 (diff) |
Generate a random socket address and export on bus
We store the socket address on the display object
and register the GetAddress method on the global
singleton object. The GetAddress method reads
the socket address from the display object and
sends it out over the bus.
-rw-r--r-- | wayland-system-compositor.c | 52 | ||||
-rw-r--r-- | wayland.c | 19 | ||||
-rw-r--r-- | wayland.h | 1 |
3 files changed, 68 insertions, 4 deletions
diff --git a/wayland-system-compositor.c b/wayland-system-compositor.c index 6d4e21d..d15127f 100644 --- a/wayland-system-compositor.c +++ b/wayland-system-compositor.c @@ -1079,10 +1079,46 @@ egl_compositor_create(struct wl_display *display, struct wl_event_loop *loop, st return ec; } -/* The plan here is to generate a random anonymous socket name and - * advertise that through a service on the session dbus. +/* We generate a random abstract socket name and advertise it on + * the system bus. It needs to be unique but doesn't + * have to be super-random. Since abstract sockets are public + * anyway, there's no added security by making the address secret. */ -static const char socket_name[] = "\0wayland"; +static void generate_socket_name(char *socket_name, size_t size) +{ + size_t i; + static bool is_seeded = false; + + if (!is_seeded) { + srandom((unsigned int) (intptr_t) socket_name); + is_seeded = true; + } + + socket_name[0] = '\0'; + for (i = 1; i < size; i++) { + socket_name[i] = (char) (((unsigned char) random()) + 1); + } +} + +static char *get_address(unsigned long *byte_count, struct wl_display *display) +{ + size_t address_size; + char *address; + + address = wl_display_get_socket(display, &address_size); + *byte_count = address_size; + + return address; +} +static struct wlsc_dbus_method_parameter get_address_out_parameters[] = { + { "address", "ay" } +}; + +struct wlsc_dbus_method get_address_method = { + "GetAddress", NULL, 0, + get_address_out_parameters, ARRAY_LENGTH(get_address_out_parameters), + (wlsc_dbus_method_handler_t) get_address +}; int main(int argc, char *argv[]) { @@ -1092,6 +1128,7 @@ int main(int argc, char *argv[]) GOptionContext *context; struct wl_event_loop *loop; struct wlsc_dbus *dbus; + char socket_name[96]; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, option_entries, "Wayland"); @@ -1119,12 +1156,19 @@ int main(int argc, char *argv[]) fprintf(stderr, "failed to create compositor\n"); exit(EXIT_FAILURE); } - + + generate_socket_name (socket_name, sizeof socket_name); + + /* FIXME: should probably generate a new name and loop in the extremely + * off chance of EADDRINUSE + */ if (wl_display_add_socket(display, socket_name, sizeof socket_name)) { fprintf(stderr, "failed to add socket: %m\n"); exit(EXIT_FAILURE); } + wlsc_dbus_register_method(dbus, &get_address_method, display); + wl_display_run(display); return 0; @@ -55,6 +55,9 @@ struct wl_display { uint32_t id; struct wl_list global_list; + + char *socket_name; + size_t socket_name_size; }; struct wl_object_ref { @@ -636,5 +639,21 @@ wl_display_add_socket(struct wl_display *display, WL_EVENT_READABLE, socket_data, display); + display->socket_name = malloc(name_size); + memcpy(display->socket_name, name, name_size); + display->socket_name_size = name_size; + return 0; } + +WL_EXPORT char * +wl_display_get_socket(struct wl_display *display, size_t *name_size) +{ + char *socket_name; + + socket_name = malloc(display->socket_name_size); + memcpy(socket_name, display->socket_name, display->socket_name_size); + *name_size = display->socket_name_size; + fprintf(stderr, "socket name size is %ld\n", *name_size); + return socket_name; +} @@ -115,6 +115,7 @@ struct wl_map { struct wl_display *wl_display_create(struct wl_event_loop *loop); struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display); int wl_display_add_socket(struct wl_display *display, const char *name, size_t name_size); +char *wl_display_get_socket(struct wl_display *display, size_t *name_size); void wl_display_run(struct wl_display *display); void |