X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/118466638aa651eac0d20513d348ddcc446bb5e6..0a583fe0c330d167f52784585afffdd8065a92cd:/src/pulse/client-conf.c diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c index 3eaca4d9..ea583a33 100644 --- a/src/pulse/client-conf.c +++ b/src/pulse/client-conf.c @@ -27,11 +27,10 @@ #include #include #include -#include #include -#include +#include #include #include #include @@ -58,19 +57,23 @@ static const pa_client_conf default_conf = { .default_source = NULL, .default_server = NULL, .default_dbus_server = NULL, - .autospawn = TRUE, - .disable_shm = FALSE, + .autospawn = true, + .disable_shm = false, .cookie_file = NULL, - .cookie_valid = FALSE, - .shm_size = 0 + .cookie_valid = false, + .shm_size = 0, + .auto_connect_localhost = false, + .auto_connect_display = false }; +static int parse_cookie_file(pa_client_conf* c); + pa_client_conf *pa_client_conf_new(void) { pa_client_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf)); c->daemon_binary = pa_xstrdup(PA_BINARY); c->extra_arguments = pa_xstrdup("--log-target=syslog"); - c->cookie_file = pa_xstrdup(PA_NATIVE_COOKIE_FILE); + c->cookie_file = NULL; return c; } @@ -87,7 +90,7 @@ void pa_client_conf_free(pa_client_conf *c) { pa_xfree(c); } -int pa_client_conf_load(pa_client_conf *c, const char *filename) { +int pa_client_conf_load(pa_client_conf *c) { FILE *f = NULL; char *fn = NULL; int r = -1; @@ -105,29 +108,19 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) { { "disable-shm", pa_config_parse_bool, &c->disable_shm, NULL }, { "enable-shm", pa_config_parse_not_bool, &c->disable_shm, NULL }, { "shm-size-bytes", pa_config_parse_size, &c->shm_size, NULL }, + { "auto-connect-localhost", pa_config_parse_bool, &c->auto_connect_localhost, NULL }, + { "auto-connect-display", pa_config_parse_bool, &c->auto_connect_display, NULL }, { NULL, NULL, NULL, NULL }, }; - if (filename) { - - if (!(f = pa_fopen_cloexec(filename, "r"))) { - pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno)); + if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn))) + if (errno != ENOENT) goto finish; - } - - fn = pa_xstrdup(fn); - } else { - - if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn))) - if (errno != ENOENT) - goto finish; - } - - r = f ? pa_config_parse(fn, f, table, NULL) : 0; + r = f ? pa_config_parse(fn, f, table, NULL, NULL) : 0; if (!r) - r = pa_client_conf_load_cookie(c); + r = parse_cookie_file(c); finish: pa_xfree(fn); @@ -156,7 +149,7 @@ int pa_client_conf_env(pa_client_conf *c) { c->default_server = pa_xstrdup(e); /* We disable autospawning automatically if a specific server was set */ - c->autospawn = FALSE; + c->autospawn = false; } if ((e = getenv(ENV_DAEMON_BINARY))) { @@ -165,26 +158,72 @@ int pa_client_conf_env(pa_client_conf *c) { } if ((e = getenv(ENV_COOKIE_FILE))) { - pa_xfree(c->cookie_file); - c->cookie_file = pa_xstrdup(e); + return pa_client_conf_load_cookie_from_file(c, e); + } + + return 0; +} + +static int parse_cookie_file(pa_client_conf* c) { + int k; + + pa_assert(c); + + c->cookie_valid = false; - return pa_client_conf_load_cookie(c); + if (c->cookie_file) + k = pa_authkey_load_auto(c->cookie_file, true, c->cookie, sizeof(c->cookie)); + else { + k = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE, false, c->cookie, sizeof(c->cookie)); + + if (k < 0) { + k = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE_FALLBACK, false, c->cookie, sizeof(c->cookie)); + + if (k < 0) + k = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE, true, c->cookie, sizeof(c->cookie)); + } } + if (k < 0) + return k; + + c->cookie_valid = true; return 0; } -int pa_client_conf_load_cookie(pa_client_conf* c) { +int pa_client_conf_load_cookie_from_hex(pa_client_conf* c, const char *cookie_in_hex) { + uint8_t cookie[PA_NATIVE_COOKIE_LENGTH]; + pa_assert(c); + pa_assert(cookie_in_hex); - if (!c->cookie_file) - return -1; + if (pa_parsehex(cookie_in_hex, cookie, sizeof(cookie)) != sizeof(cookie)) { + pa_log(_("Failed to parse cookie data")); + return -PA_ERR_INVALID; + } - c->cookie_valid = FALSE; + pa_xfree(c->cookie_file); + c->cookie_file = NULL; - if (pa_authkey_load_auto(c->cookie_file, c->cookie, sizeof(c->cookie)) < 0) - return -1; + return pa_client_conf_set_cookie(c, cookie, PA_NATIVE_COOKIE_LENGTH); +} + +int pa_client_conf_load_cookie_from_file(pa_client_conf *c, const char *cookie_file_path) { + pa_assert(c); + pa_assert(cookie_file_path); + + pa_xfree(c->cookie_file); + c->cookie_file = pa_xstrdup(cookie_file_path); + return parse_cookie_file(c); +} + +int pa_client_conf_set_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_size) { + pa_assert(c); + pa_assert(cookie); - c->cookie_valid = TRUE; + if (cookie_size != PA_NATIVE_COOKIE_LENGTH) + return -PA_ERR_INVALID; + memcpy(c->cookie, cookie, cookie_size); + c->cookie_valid = true; return 0; }