client: refuse update of pipewire.* keys from client

Only the server and modules can update the properties with
pipewire.* keys.
This commit is contained in:
Wim Taymans 2020-07-17 16:47:49 +02:00
parent 07cc07597c
commit 15a4019e45
2 changed files with 45 additions and 36 deletions

View file

@ -132,12 +132,47 @@ static int client_error(void *object, uint32_t id, int res, const char *error)
return 0; return 0;
} }
static int update_properties(struct pw_impl_client *client, const struct spa_dict *dict, bool filter)
{
struct pw_resource *resource;
int changed = 0;
uint32_t i;
for (i = 0; i < dict->n_items; i++) {
if (filter && strstr(dict->items[i].key, "pipewire.") == dict->items[i].key &&
pw_properties_get(client->properties, dict->items[i].key) != NULL) {
pw_log_warn(NAME" %p: refuse property update '%s' to '%s'",
client, dict->items[i].key, dict->items[i].value);
continue;
}
changed += pw_properties_set(client->properties, dict->items[i].key, dict->items[i].value);
}
client->info.props = &client->properties->dict;
pw_log_debug(NAME" %p: updated %d properties", client, changed);
if (!changed)
return 0;
client->info.change_mask |= PW_CLIENT_CHANGE_MASK_PROPS;
pw_impl_client_emit_info_changed(client, &client->info);
if (client->global)
spa_list_for_each(resource, &client->global->resource_list, link)
pw_client_resource_info(resource, &client->info);
client->info.change_mask = 0;
return changed;
}
static int client_update_properties(void *object, const struct spa_dict *props) static int client_update_properties(void *object, const struct spa_dict *props)
{ {
struct pw_resource *resource = object; struct pw_resource *resource = object;
struct resource_data *data = pw_resource_get_user_data(resource); struct resource_data *data = pw_resource_get_user_data(resource);
struct pw_impl_client *client = data->client; struct pw_impl_client *client = data->client;
return pw_impl_client_update_properties(client, props); return update_properties(client, props, true);
} }
static int client_get_permissions(void *object, uint32_t index, uint32_t num) static int client_get_permissions(void *object, uint32_t index, uint32_t num)
@ -555,28 +590,7 @@ const struct pw_client_info *pw_impl_client_get_info(struct pw_impl_client *clie
SPA_EXPORT SPA_EXPORT
int pw_impl_client_update_properties(struct pw_impl_client *client, const struct spa_dict *dict) int pw_impl_client_update_properties(struct pw_impl_client *client, const struct spa_dict *dict)
{ {
struct pw_resource *resource; return update_properties(client, dict, false);
int changed;
changed = pw_properties_update(client->properties, dict);
client->info.props = &client->properties->dict;
pw_log_debug(NAME" %p: updated %d properties", client, changed);
if (!changed)
return 0;
client->info.change_mask |= PW_CLIENT_CHANGE_MASK_PROPS;
pw_impl_client_emit_info_changed(client, &client->info);
if (client->global)
spa_list_for_each(resource, &client->global->resource_list, link)
pw_client_resource_info(resource, &client->info);
client->info.change_mask = 0;
return changed;
} }
SPA_EXPORT SPA_EXPORT

View file

@ -39,19 +39,7 @@ extern "C" {
* Properties from other objects can also appear. This usually suggests some * Properties from other objects can also appear. This usually suggests some
* sort of parent/child or owner/owned relationship. * sort of parent/child or owner/owned relationship.
*/ */
#define PW_KEY_PROTOCOL "pipewire.protocol" /**< protocol used for connection */
/* Peroperties usually set on the core object */
#define PW_KEY_USER_NAME "pipewire.user-name" /**< The user name that runs pipewire */
#define PW_KEY_HOST_NAME "pipewire.host-name" /**< The host name of the machine */
#define PW_KEY_CORE_NAME "pipewire.core.name" /**< The name of the core. Default is
* pipewire-<user-name>-<pid> */
#define PW_KEY_CORE_VERSION "pipewire.core.version" /**< The version of the core. */
#define PW_KEY_CORE_DAEMON "pipewire.core.daemon" /**< If the core is listening for connections. */
/** The protocol key is usually set on a pw_client and contains a
* string describing the protocol used by the client to access
* PipeWire */
#define PW_KEY_PROTOCOL "pipewire.protocol"
#define PW_KEY_ACCESS "pipewire.access" /**< how the client access is controlled */ #define PW_KEY_ACCESS "pipewire.access" /**< how the client access is controlled */
/** Various keys related to the identity of a client process and its security. /** Various keys related to the identity of a client process and its security.
@ -71,8 +59,15 @@ extern "C" {
/* context */ /* context */
#define PW_KEY_CONTEXT_PROFILE_MODULES "context.profile.modules" /**< a context profile for modules */ #define PW_KEY_CONTEXT_PROFILE_MODULES "context.profile.modules" /**< a context profile for modules */
#define PW_KEY_USER_NAME "context.user-name" /**< The user name that runs pipewire */
#define PW_KEY_HOST_NAME "context.host-name" /**< The host name of the machine */
/* core */ /* core */
#define PW_KEY_CORE_NAME "core.name" /**< The name of the core. Default is
* pipewire-<user-name>-<pid> */
#define PW_KEY_CORE_VERSION "core.version" /**< The version of the core. */
#define PW_KEY_CORE_DAEMON "core.daemon" /**< If the core is listening for connections. */
#define PW_KEY_CORE_ID "core.id" /**< the core id */ #define PW_KEY_CORE_ID "core.id" /**< the core id */
#define PW_KEY_CORE_MONITORS "core.monitors" /**< the apis monitored by core. */ #define PW_KEY_CORE_MONITORS "core.monitors" /**< the apis monitored by core. */