diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c index f887962fc..bef3d8e46 100644 --- a/src/modules/module-esound-sink.c +++ b/src/modules/module-esound-sink.c @@ -527,6 +527,8 @@ int pa__init(pa_module*m) { const char *espeaker; uint32_t key; pa_sink_new_data data; + char *cookie_path; + int r; pa_assert(m); @@ -620,9 +622,18 @@ int pa__init(pa_module*m) { pa_socket_client_set_callback(u->client, on_connection, u); + cookie_path = pa_xstrdup(pa_modargs_get_value(ma, "cookie", NULL)); + if (!cookie_path) { + if (pa_append_to_home_dir(".esd_auth", &cookie_path) < 0) + goto fail; + } + /* Prepare the initial request */ u->write_data = pa_xmalloc(u->write_length = ESD_KEY_LEN + sizeof(int32_t)); - if (pa_authkey_load(pa_modargs_get_value(ma, "cookie", ".esd_auth"), true, u->write_data, ESD_KEY_LEN) < 0) { + + r = pa_authkey_load(cookie_path, true, u->write_data, ESD_KEY_LEN); + pa_xfree(cookie_path); + if (r < 0) { pa_log("Failed to load cookie"); goto fail; } diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c index fd1ccbf2c..317c9f9c9 100644 --- a/src/pulse/client-conf.c +++ b/src/pulse/client-conf.c @@ -168,6 +168,7 @@ void pa_client_conf_load(pa_client_conf *c, bool load_from_x11, bool load_from_e int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_length) { int r; + char *fallback_path; pa_assert(c); pa_assert(cookie); @@ -213,9 +214,12 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie if (r >= 0) return 0; - r = pa_authkey_load(PA_NATIVE_COOKIE_FILE_FALLBACK, false, cookie, cookie_length); - if (r >= 0) - return 0; + if (pa_append_to_home_dir(PA_NATIVE_COOKIE_FILE_FALLBACK, &fallback_path) > 0) { + r = pa_authkey_load(fallback_path, false, cookie, cookie_length); + pa_xfree(fallback_path); + if (r >= 0) + return 0; + } r = pa_authkey_load(PA_NATIVE_COOKIE_FILE, true, cookie, cookie_length); if (r >= 0) diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c index 7c1b7a210..755109c9a 100644 --- a/src/pulsecore/protocol-esound.c +++ b/src/pulsecore/protocol-esound.c @@ -1707,15 +1707,20 @@ int pa_esound_options_parse(pa_esound_options *o, pa_core *c, pa_modargs *ma) { pa_auth_cookie_unref(o->auth_cookie); if (enabled) { - const char *cn; + char *cn; /* The new name for this is 'auth-cookie', for compat reasons * we check the old name too */ - if (!(cn = pa_modargs_get_value(ma, "auth-cookie", NULL))) - if (!(cn = pa_modargs_get_value(ma, "cookie", NULL))) - cn = DEFAULT_COOKIE_FILE; + if (!(cn = pa_xstrdup(pa_modargs_get_value(ma, "auth-cookie", NULL)))) { + if (!(cn = pa_xstrdup(pa_modargs_get_value(ma, "cookie", NULL)))) { + if (pa_append_to_home_dir(DEFAULT_COOKIE_FILE, &cn) < 0) + return -1; + } + } - if (!(o->auth_cookie = pa_auth_cookie_get(c, cn, true, ESD_KEY_LEN))) + o->auth_cookie = pa_auth_cookie_get(c, cn, true, ESD_KEY_LEN); + pa_xfree(cn); + if (!o->auth_cookie) return -1; } else diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 606bf25cb..584e1d94c 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -5303,7 +5303,12 @@ int pa_native_options_parse(pa_native_options *o, pa_core *c, pa_modargs *ma) { else { o->auth_cookie = pa_auth_cookie_get(c, PA_NATIVE_COOKIE_FILE, false, PA_NATIVE_COOKIE_LENGTH); if (!o->auth_cookie) { - o->auth_cookie = pa_auth_cookie_get(c, PA_NATIVE_COOKIE_FILE_FALLBACK, false, PA_NATIVE_COOKIE_LENGTH); + char *fallback_path; + + if (pa_append_to_home_dir(PA_NATIVE_COOKIE_FILE_FALLBACK, &fallback_path) >= 0) { + o->auth_cookie = pa_auth_cookie_get(c, fallback_path, false, PA_NATIVE_COOKIE_LENGTH); + pa_xfree(fallback_path); + } if (!o->auth_cookie) o->auth_cookie = pa_auth_cookie_get(c, PA_NATIVE_COOKIE_FILE, true, PA_NATIVE_COOKIE_LENGTH);