permissions: use current_client for security checks

Don't pass around the client object but keep track of the current
client in the core object. This way we don't need to add a client
argument to functions and can check security when needed.
This commit is contained in:
Wim Taymans 2018-01-24 11:41:40 +01:00
parent ab099d09dd
commit ff17fb68b5
10 changed files with 32 additions and 21 deletions

View file

@ -204,7 +204,7 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod
pw_log_debug("module %p: try to find and link to node '%d'", impl, path_id);
target = pw_core_find_port(impl->core, owner, port, path_id, NULL, 0, NULL, &error);
target = pw_core_find_port(impl->core, port, path_id, NULL, 0, NULL, &error);
if (target == NULL)
goto error;

View file

@ -874,8 +874,11 @@ static int
process_messages(struct client *client)
{
struct pw_client *c = client->client;
struct pw_core *core = c->core;
int type, res = -1;
core->current_client = c;
if (read(client->fd, &type, sizeof(enum jack_request_type)) != sizeof(enum jack_request_type)) {
pw_log_error("protocol-jack %p: failed to read type", client->impl);
goto error;
@ -951,12 +954,15 @@ process_messages(struct client *client)
if (res != 0)
goto error;
exit:
core->current_client = NULL;
return res;
error:
pw_log_error("protocol-jack %p: error handling type %d", client->impl, type);
pw_client_destroy(c);
return -1;
res = -EIO;
goto exit;
}
@ -1351,7 +1357,7 @@ static bool init_nodes(struct impl *impl)
make_audio_client(impl);
make_freewheel_client(impl);
pw_core_for_each_global(core, NULL, on_global, impl);
pw_core_for_each_global(core, on_global, impl);
return true;
}

View file

@ -83,13 +83,13 @@ static void *create_object(void *_data,
core = pw_client_get_core(client);
t = pw_core_get_type(core);
global = pw_core_find_global(core, client, output_node_id);
global = pw_core_find_global(core, output_node_id);
if (global == NULL || pw_global_get_type(global) != t->node)
goto no_output;
output_node = pw_global_get_object(global);
global = pw_core_find_global(core, client, input_node_id);
global = pw_core_find_global(core, input_node_id);
if (global == NULL || pw_global_get_type(global) != t->node)
goto no_input;

View file

@ -233,7 +233,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
spa_list_init(&impl->node_list);
pw_core_for_each_global(core, NULL, on_global, impl);
pw_core_for_each_global(core, on_global, impl);
pw_core_add_listener(core, &impl->core_listener, &core_events, impl);
pw_module_add_listener(module, &impl->module_listener, &module_events, impl);

View file

@ -168,11 +168,14 @@ process_messages(struct client_data *data)
{
struct pw_protocol_native_connection *conn = data->connection;
struct pw_client *client = data->client;
struct pw_core *core = client->core;
uint8_t opcode;
uint32_t id;
uint32_t size;
void *message;
core->current_client = client;
while (pw_protocol_native_connection_get_next(conn, &opcode, &id, &message, &size)) {
struct pw_resource *resource;
const struct pw_protocol_native_demarshal *demarshal;
@ -222,18 +225,20 @@ process_messages(struct client_data *data)
if (demarshal[opcode].func(resource, message, size) < 0)
goto invalid_message;
}
done:
core->current_client = NULL;
return;
invalid_method:
pw_log_error("protocol-native %p: invalid method %u on resource %u",
client->protocol, opcode, id);
pw_client_destroy(client);
return;
goto done;
invalid_message:
pw_log_error("protocol-native %p: invalid message received %u %u",
client->protocol, id, opcode);
pw_client_destroy(client);
return;
goto done;
}
static void