2004-10-30 01:55:16 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2004-10-30 01:55:16 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-10-30 01:55:16 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-10-30 01:55:16 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/util.h>
|
|
|
|
|
#include <pulse/xmalloc.h>
|
|
|
|
|
|
|
|
|
|
#include <pulsecore/module.h>
|
|
|
|
|
#include <pulsecore/sink.h>
|
|
|
|
|
#include <pulsecore/core-scache.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
|
|
|
|
#include <pulsecore/namereg.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
#include <pulsecore/x11wrap.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/native-common.h>
|
|
|
|
|
#include <pulsecore/authkey-prop.h>
|
|
|
|
|
#include <pulsecore/authkey.h>
|
|
|
|
|
#include <pulsecore/x11prop.h>
|
|
|
|
|
#include <pulsecore/strlist.h>
|
|
|
|
|
#include <pulsecore/props.h>
|
2006-02-16 19:19:58 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
#include "module-x11-publish-symdef.h"
|
|
|
|
|
|
2007-11-09 18:25:40 +00:00
|
|
|
PA_MODULE_AUTHOR("Lennart Poettering");
|
2008-06-11 16:58:00 +00:00
|
|
|
PA_MODULE_DESCRIPTION("X11 credential publisher");
|
2007-11-09 18:25:40 +00:00
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION);
|
|
|
|
|
PA_MODULE_LOAD_ONCE(FALSE);
|
|
|
|
|
PA_MODULE_USAGE("display=<X11 display>");
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
"display",
|
|
|
|
|
"sink",
|
|
|
|
|
"source",
|
2004-11-07 20:48:46 +00:00
|
|
|
"cookie",
|
2004-10-30 01:55:16 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct userdata {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core *core;
|
2008-06-11 16:58:00 +00:00
|
|
|
pa_module *module;
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
char *id;
|
2004-11-07 20:48:46 +00:00
|
|
|
uint8_t auth_cookie[PA_NATIVE_COOKIE_LENGTH];
|
2008-06-11 16:58:00 +00:00
|
|
|
pa_bool_t auth_cookie_in_property;
|
|
|
|
|
|
|
|
|
|
pa_x11_wrapper *x11_wrapper;
|
|
|
|
|
pa_x11_client *x11_client;
|
2004-10-30 01:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
static void x11_kill_cb(pa_x11_wrapper *w, void *userdata) {
|
|
|
|
|
struct userdata *u = userdata;
|
|
|
|
|
|
|
|
|
|
pa_assert(w);
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->x11_wrapper == w);
|
|
|
|
|
|
|
|
|
|
if (u->x11_client)
|
|
|
|
|
pa_x11_client_free(u->x11_client);
|
|
|
|
|
|
|
|
|
|
if (u->x11_wrapper)
|
|
|
|
|
pa_x11_wrapper_unref(u->x11_wrapper);
|
|
|
|
|
|
|
|
|
|
u->x11_client = NULL;
|
|
|
|
|
u->x11_wrapper = NULL;
|
|
|
|
|
|
|
|
|
|
pa_module_unload_request(u->module);
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-07 20:48:46 +00:00
|
|
|
static int load_key(struct userdata *u, const char*fn) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(u);
|
2004-11-07 20:48:46 +00:00
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
u->auth_cookie_in_property = FALSE;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-07 20:48:46 +00:00
|
|
|
if (!fn && pa_authkey_prop_get(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_debug("using already loaded auth cookie.");
|
2004-11-07 20:48:46 +00:00
|
|
|
pa_authkey_prop_ref(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
|
|
|
|
|
u->auth_cookie_in_property = 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-07 20:48:46 +00:00
|
|
|
if (!fn)
|
|
|
|
|
fn = PA_NATIVE_COOKIE_FILE;
|
|
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
if (pa_authkey_load_auto(fn, u->auth_cookie, sizeof(u->auth_cookie)) < 0)
|
2004-11-07 20:48:46 +00:00
|
|
|
return -1;
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log_debug("Loading cookie from disk.");
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-07 20:48:46 +00:00
|
|
|
if (pa_authkey_prop_put(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0)
|
2008-06-11 16:58:00 +00:00
|
|
|
u->auth_cookie_in_property = TRUE;
|
2004-11-07 20:48:46 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
int pa__init(pa_module*m) {
|
2004-10-30 01:55:16 +00:00
|
|
|
struct userdata *u;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_modargs *ma = NULL;
|
2004-10-30 01:55:16 +00:00
|
|
|
char hn[256], un[128];
|
2004-11-07 20:48:46 +00:00
|
|
|
char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
|
|
|
|
|
const char *t;
|
2004-11-11 21:18:33 +00:00
|
|
|
char *s;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_strlist *l;
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(m);
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("failed to parse module arguments");
|
2004-10-30 01:55:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
m->userdata = u = pa_xnew(struct userdata, 1);
|
2007-10-28 19:13:50 +00:00
|
|
|
u->core = m->core;
|
2008-06-11 16:58:00 +00:00
|
|
|
u->module = m;
|
2004-10-30 01:55:16 +00:00
|
|
|
u->id = NULL;
|
2008-06-11 16:58:00 +00:00
|
|
|
u->auth_cookie_in_property = FALSE;
|
|
|
|
|
u->x11_client = NULL;
|
|
|
|
|
u->x11_wrapper = NULL;
|
2004-11-07 20:48:46 +00:00
|
|
|
|
|
|
|
|
if (load_key(u, pa_modargs_get_value(ma, "cookie", NULL)) < 0)
|
|
|
|
|
goto fail;
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
|
2004-10-30 01:55:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!(l = pa_property_get(m->core, PA_NATIVE_SERVER_PROPERTY_NAME)))
|
2004-11-09 01:04:17 +00:00
|
|
|
goto fail;
|
2004-11-11 21:18:33 +00:00
|
|
|
|
2007-10-29 20:30:53 +00:00
|
|
|
l = pa_strlist_reverse(l);
|
2004-11-11 21:18:33 +00:00
|
|
|
s = pa_strlist_tostring(l);
|
2007-10-29 20:30:53 +00:00
|
|
|
l = pa_strlist_reverse(l);
|
|
|
|
|
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SERVER", s);
|
2004-11-11 21:18:33 +00:00
|
|
|
pa_xfree(s);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-11 21:18:33 +00:00
|
|
|
if (!pa_get_fqdn(hn, sizeof(hn)) || !pa_get_user_name(un, sizeof(un)))
|
2004-11-09 01:04:17 +00:00
|
|
|
goto fail;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
u->id = pa_sprintf_malloc("%s@%s/%u", un, hn, (unsigned) getpid());
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID", u->id);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
if ((t = pa_modargs_get_value(ma, "source", NULL)))
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SOURCE", t);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
if ((t = pa_modargs_get_value(ma, "sink", NULL)))
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SINK", t);
|
2004-11-07 20:48:46 +00:00
|
|
|
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_COOKIE", pa_hexstr(u->auth_cookie, sizeof(u->auth_cookie), hx, sizeof(hx)));
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
u->x11_client = pa_x11_client_new(u->x11_wrapper, NULL, x11_kill_cb, u);
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
pa_modargs_free(ma);
|
2008-06-11 16:58:00 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
return 0;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
fail:
|
|
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa__done(m);
|
2008-06-11 16:58:00 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa__done(pa_module*m) {
|
2004-10-30 01:55:16 +00:00
|
|
|
struct userdata*u;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(m);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
if (!(u = m->userdata))
|
|
|
|
|
return;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
if (u->x11_client)
|
|
|
|
|
pa_x11_client_free(u->x11_client);
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
if (u->x11_wrapper) {
|
|
|
|
|
char t[256];
|
|
|
|
|
|
|
|
|
|
/* Yes, here is a race condition */
|
2006-06-19 23:56:54 +00:00
|
|
|
if (!pa_x11_get_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id))
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_warn("PulseAudio information vanished from X11!");
|
2004-10-30 01:55:16 +00:00
|
|
|
else {
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SERVER");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SINK");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SOURCE");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_COOKIE");
|
2006-04-22 21:51:30 +00:00
|
|
|
XSync(pa_x11_wrapper_get_display(u->x11_wrapper), False);
|
2004-10-30 01:55:16 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
pa_x11_wrapper_unref(u->x11_wrapper);
|
2008-06-11 16:58:00 +00:00
|
|
|
}
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2004-11-07 20:48:46 +00:00
|
|
|
if (u->auth_cookie_in_property)
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_authkey_prop_unref(m->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
|
2004-11-07 20:48:46 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
pa_xfree(u->id);
|
|
|
|
|
pa_xfree(u);
|
|
|
|
|
}
|