perm: add permission mask to global

Add a mask of possible permissions for a global.
Make sure the permissions of an object are limited to the global
mask.
This commit is contained in:
Wim Taymans 2023-07-26 18:43:15 +02:00
parent 9bcc90fdc3
commit 212fe59530
34 changed files with 53 additions and 5 deletions

View file

@ -265,6 +265,7 @@ pw_metadata_new(struct pw_context *context, struct pw_resource *resource,
impl->global = pw_global_new(context, impl->global = pw_global_new(context,
PW_TYPE_INTERFACE_Metadata, PW_TYPE_INTERFACE_Metadata,
PW_VERSION_METADATA, PW_VERSION_METADATA,
PW_METADATA_PERM_MASK,
properties, properties,
global_bind, impl); global_bind, impl);
if (impl->global == NULL) { if (impl->global == NULL) {

View file

@ -458,6 +458,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
impl->global = pw_global_new(context, impl->global = pw_global_new(context,
PW_TYPE_INTERFACE_Profiler, PW_TYPE_INTERFACE_Profiler,
PW_VERSION_PROFILER, PW_VERSION_PROFILER,
PW_PROFILER_PERM_MASK,
pw_properties_copy(props), pw_properties_copy(props),
global_bind, impl); global_bind, impl);
if (impl->global == NULL) { if (impl->global == NULL) {

View file

@ -292,6 +292,7 @@ int endpoint_stream_init(struct endpoint_stream *this,
this->global = pw_global_new (context, this->global = pw_global_new (context,
PW_TYPE_INTERFACE_EndpointStream, PW_TYPE_INTERFACE_EndpointStream,
PW_VERSION_ENDPOINT_STREAM, PW_VERSION_ENDPOINT_STREAM,
PW_ENDPOINT_STREAM_PERM_MASK,
properties, endpoint_stream_bind, this); properties, endpoint_stream_bind, this);
if (!this->global) if (!this->global)
goto no_mem; goto no_mem;

View file

@ -322,6 +322,7 @@ int endpoint_init(struct endpoint *this,
this->global = pw_global_new (context, this->global = pw_global_new (context,
PW_TYPE_INTERFACE_Endpoint, PW_TYPE_INTERFACE_Endpoint,
PW_VERSION_ENDPOINT, PW_VERSION_ENDPOINT,
PW_ENDPOINT_PERM_MASK,
NULL, endpoint_bind, this); NULL, endpoint_bind, this);
if (!this->global) if (!this->global)
goto no_mem; goto no_mem;

View file

@ -310,6 +310,7 @@ int endpoint_link_init(struct endpoint_link *this,
this->global = pw_global_new(context, this->global = pw_global_new(context,
PW_TYPE_INTERFACE_EndpointLink, PW_TYPE_INTERFACE_EndpointLink,
PW_VERSION_ENDPOINT_LINK, PW_VERSION_ENDPOINT_LINK,
PW_ENDPOINT_LINK_PERM_MASK,
properties, endpoint_link_bind, this); properties, endpoint_link_bind, this);
if (!this->global) if (!this->global)
goto no_mem; goto no_mem;

View file

@ -283,6 +283,7 @@ int session_init(struct session *this,
this->global = pw_global_new (context, this->global = pw_global_new (context,
PW_TYPE_INTERFACE_Session, PW_TYPE_INTERFACE_Session,
PW_VERSION_SESSION, PW_VERSION_SESSION,
PW_SESSION_PERM_MASK,
NULL, session_bind, this); NULL, session_bind, this);
if (!this->global) if (!this->global)
goto no_mem; goto no_mem;

View file

@ -390,6 +390,7 @@ static void *link_new(struct pw_context *context,
impl->global = pw_global_new(context, impl->global = pw_global_new(context,
PW_TYPE_INTERFACE_EndpointLink, PW_TYPE_INTERFACE_EndpointLink,
PW_VERSION_ENDPOINT_LINK, PW_VERSION_ENDPOINT_LINK,
PW_ENDPOINT_LINK_PERM_MASK,
properties, properties,
global_bind, impl); global_bind, impl);
if (impl->global == NULL) { if (impl->global == NULL) {

View file

@ -381,6 +381,7 @@ static void *stream_new(struct pw_context *context,
impl->global = pw_global_new(context, impl->global = pw_global_new(context,
PW_TYPE_INTERFACE_EndpointStream, PW_TYPE_INTERFACE_EndpointStream,
PW_VERSION_ENDPOINT_STREAM, PW_VERSION_ENDPOINT_STREAM,
PW_ENDPOINT_STREAM_PERM_MASK,
properties, properties,
global_bind, impl); global_bind, impl);
if (impl->global == NULL) { if (impl->global == NULL) {

View file

@ -390,6 +390,7 @@ static void *endpoint_new(struct pw_context *context,
impl->global = pw_global_new(context, impl->global = pw_global_new(context,
PW_TYPE_INTERFACE_Endpoint, PW_TYPE_INTERFACE_Endpoint,
PW_VERSION_ENDPOINT, PW_VERSION_ENDPOINT,
PW_ENDPOINT_PERM_MASK,
properties, properties,
global_bind, impl); global_bind, impl);
if (impl->global == NULL) { if (impl->global == NULL) {

View file

@ -379,6 +379,7 @@ static void *session_new(struct pw_context *context,
impl->global = pw_global_new(context, impl->global = pw_global_new(context,
PW_TYPE_INTERFACE_Session, PW_TYPE_INTERFACE_Session,
PW_VERSION_SESSION, PW_VERSION_SESSION,
PW_SESSION_PERM_MASK,
properties, properties,
global_bind, impl); global_bind, impl);
if (impl->global == NULL) { if (impl->global == NULL) {

View file

@ -25,6 +25,8 @@ extern "C" {
*/ */
#define PW_TYPE_INTERFACE_Client PW_TYPE_INFO_INTERFACE_BASE "Client" #define PW_TYPE_INTERFACE_Client PW_TYPE_INFO_INTERFACE_BASE "Client"
#define PW_CLIENT_PERM_MASK PW_PERM_RWX
#define PW_VERSION_CLIENT 3 #define PW_VERSION_CLIENT 3
struct pw_client; struct pw_client;

View file

@ -34,6 +34,8 @@ extern "C" {
#define PW_TYPE_INTERFACE_Core PW_TYPE_INFO_INTERFACE_BASE "Core" #define PW_TYPE_INTERFACE_Core PW_TYPE_INFO_INTERFACE_BASE "Core"
#define PW_TYPE_INTERFACE_Registry PW_TYPE_INFO_INTERFACE_BASE "Registry" #define PW_TYPE_INTERFACE_Registry PW_TYPE_INFO_INTERFACE_BASE "Registry"
#define PW_CORE_PERM_MASK PW_PERM_R|PW_PERM_X|PW_PERM_M
#define PW_VERSION_CORE 4 #define PW_VERSION_CORE 4
struct pw_core; struct pw_core;
#define PW_VERSION_REGISTRY 3 #define PW_VERSION_REGISTRY 3

View file

@ -25,6 +25,8 @@ extern "C" {
#define PW_TYPE_INTERFACE_Device PW_TYPE_INFO_INTERFACE_BASE "Device" #define PW_TYPE_INTERFACE_Device PW_TYPE_INFO_INTERFACE_BASE "Device"
#define PW_DEVICE_PERM_MASK PW_PERM_RWX
#define PW_VERSION_DEVICE 3 #define PW_VERSION_DEVICE 3
struct pw_device; struct pw_device;

View file

@ -21,6 +21,8 @@ extern "C" {
*/ */
#define PW_TYPE_INTERFACE_Metadata PW_TYPE_INFO_INTERFACE_BASE "Metadata" #define PW_TYPE_INTERFACE_Metadata PW_TYPE_INFO_INTERFACE_BASE "Metadata"
#define PW_METADATA_PERM_MASK PW_PERM_RWX
#define PW_VERSION_METADATA 3 #define PW_VERSION_METADATA 3
struct pw_metadata; struct pw_metadata;

View file

@ -26,6 +26,8 @@ struct pw_profiler;
#define PW_EXTENSION_MODULE_PROFILER PIPEWIRE_MODULE_PREFIX "module-profiler" #define PW_EXTENSION_MODULE_PROFILER PIPEWIRE_MODULE_PREFIX "module-profiler"
#define PW_PROFILER_PERM_MASK PW_PERM_R
#define PW_PROFILER_EVENT_PROFILE 0 #define PW_PROFILER_EVENT_PROFILE 0
#define PW_PROFILER_EVENT_NUM 1 #define PW_PROFILER_EVENT_NUM 1

View file

@ -21,18 +21,22 @@ extern "C" {
*/ */
#define PW_TYPE_INTERFACE_Session PW_TYPE_INFO_INTERFACE_BASE "Session" #define PW_TYPE_INTERFACE_Session PW_TYPE_INFO_INTERFACE_BASE "Session"
#define PW_SESSION_PERM_MASK PW_PERM_RWX
#define PW_VERSION_SESSION 0 #define PW_VERSION_SESSION 0
struct pw_session; struct pw_session;
#define PW_TYPE_INTERFACE_Endpoint PW_TYPE_INFO_INTERFACE_BASE "Endpoint" #define PW_TYPE_INTERFACE_Endpoint PW_TYPE_INFO_INTERFACE_BASE "Endpoint"
#define PW_ENDPOINT_PERM_MASK PW_PERM_RWX
#define PW_VERSION_ENDPOINT 0 #define PW_VERSION_ENDPOINT 0
struct pw_endpoint; struct pw_endpoint;
#define PW_TYPE_INTERFACE_EndpointStream PW_TYPE_INFO_INTERFACE_BASE "EndpointStream" #define PW_TYPE_INTERFACE_EndpointStream PW_TYPE_INFO_INTERFACE_BASE "EndpointStream"
#define PW_ENDPOINT_STREAM_PERM_MASK PW_PERM_RWX
#define PW_VERSION_ENDPOINT_STREAM 0 #define PW_VERSION_ENDPOINT_STREAM 0
struct pw_endpoint_stream; struct pw_endpoint_stream;
#define PW_TYPE_INTERFACE_EndpointLink PW_TYPE_INFO_INTERFACE_BASE "EndpointLink" #define PW_TYPE_INTERFACE_EndpointLink PW_TYPE_INFO_INTERFACE_BASE "EndpointLink"
#define PW_ENDPOINT_LINK_PERM_MASK PW_PERM_RWX
#define PW_VERSION_ENDPOINT_LINK 0 #define PW_VERSION_ENDPOINT_LINK 0
struct pw_endpoint_link; struct pw_endpoint_link;

View file

@ -27,6 +27,8 @@ extern "C" {
*/ */
#define PW_TYPE_INTERFACE_Factory PW_TYPE_INFO_INTERFACE_BASE "Factory" #define PW_TYPE_INTERFACE_Factory PW_TYPE_INFO_INTERFACE_BASE "Factory"
#define PW_FACTORY_PERM_MASK PW_PERM_R
#define PW_VERSION_FACTORY 3 #define PW_VERSION_FACTORY 3
struct pw_factory; struct pw_factory;

View file

@ -25,10 +25,10 @@ struct impl {
SPA_EXPORT SPA_EXPORT
uint32_t pw_global_get_permissions(struct pw_global *global, struct pw_impl_client *client) uint32_t pw_global_get_permissions(struct pw_global *global, struct pw_impl_client *client)
{ {
if (client->permission_func == NULL) uint32_t permissions = global->permission_mask;
return PW_PERM_ALL; if (client->permission_func != NULL)
permissions &= client->permission_func(global, client, client->permission_data);
return client->permission_func(global, client, client->permission_data); return permissions;
} }
/** Create a new global /** Create a new global
@ -47,6 +47,7 @@ struct pw_global *
pw_global_new(struct pw_context *context, pw_global_new(struct pw_context *context,
const char *type, const char *type,
uint32_t version, uint32_t version,
uint32_t permission_mask,
struct pw_properties *properties, struct pw_properties *properties,
pw_global_bind_func_t func, pw_global_bind_func_t func,
void *object) void *object)
@ -71,6 +72,7 @@ pw_global_new(struct pw_context *context,
this->context = context; this->context = context;
this->type = type; this->type = type;
this->version = version; this->version = version;
this->permission_mask = permission_mask;
this->func = func; this->func = func;
this->object = object; this->object = object;
this->properties = properties; this->properties = properties;

View file

@ -65,6 +65,7 @@ struct pw_global *
pw_global_new(struct pw_context *context, /**< the context */ pw_global_new(struct pw_context *context, /**< the context */
const char *type, /**< the interface type of the global */ const char *type, /**< the interface type of the global */
uint32_t version, /**< the interface version of the global */ uint32_t version, /**< the interface version of the global */
uint32_t permission_mask, /**< mask of valid permissions */
struct pw_properties *properties, /**< extra properties */ struct pw_properties *properties, /**< extra properties */
pw_global_bind_func_t func, /**< function to bind */ pw_global_bind_func_t func, /**< function to bind */
void *object /**< global object */); void *object /**< global object */);

View file

@ -514,6 +514,7 @@ int pw_impl_client_register(struct pw_impl_client *client,
client->global = pw_global_new(context, client->global = pw_global_new(context,
PW_TYPE_INTERFACE_Client, PW_TYPE_INTERFACE_Client,
PW_VERSION_CLIENT, PW_VERSION_CLIENT,
PW_CLIENT_PERM_MASK,
properties, properties,
global_bind, global_bind,
client); client);

View file

@ -588,6 +588,7 @@ int pw_impl_core_register(struct pw_impl_core *core,
core->global = pw_global_new(context, core->global = pw_global_new(context,
PW_TYPE_INTERFACE_Core, PW_TYPE_INTERFACE_Core,
PW_VERSION_CORE, PW_VERSION_CORE,
PW_CORE_PERM_MASK,
properties, properties,
global_bind, global_bind,
core); core);

View file

@ -560,6 +560,7 @@ int pw_impl_device_register(struct pw_impl_device *device,
device->global = pw_global_new(context, device->global = pw_global_new(context,
PW_TYPE_INTERFACE_Device, PW_TYPE_INTERFACE_Device,
PW_VERSION_DEVICE, PW_VERSION_DEVICE,
PW_DEVICE_PERM_MASK,
properties, properties,
global_bind, global_bind,
device); device);

View file

@ -174,6 +174,7 @@ int pw_impl_factory_register(struct pw_impl_factory *factory,
factory->global = pw_global_new(context, factory->global = pw_global_new(context,
PW_TYPE_INTERFACE_Factory, PW_TYPE_INTERFACE_Factory,
PW_VERSION_FACTORY, PW_VERSION_FACTORY,
PW_FACTORY_PERM_MASK,
properties, properties,
global_bind, global_bind,
factory); factory);

View file

@ -1462,6 +1462,7 @@ int pw_impl_link_register(struct pw_impl_link *link,
link->global = pw_global_new(context, link->global = pw_global_new(context,
PW_TYPE_INTERFACE_Link, PW_TYPE_INTERFACE_Link,
PW_VERSION_LINK, PW_VERSION_LINK,
PW_LINK_PERM_MASK,
properties, properties,
global_bind, global_bind,
link); link);

View file

@ -519,6 +519,7 @@ int pw_impl_metadata_register(struct pw_impl_metadata *metadata,
metadata->global = pw_global_new(context, metadata->global = pw_global_new(context,
PW_TYPE_INTERFACE_Metadata, PW_TYPE_INTERFACE_Metadata,
PW_VERSION_METADATA, PW_VERSION_METADATA,
PW_METADATA_PERM_MASK,
properties, properties,
global_bind, global_bind,
metadata); metadata);

View file

@ -222,6 +222,7 @@ pw_context_load_module(struct pw_context *context,
this->global = pw_global_new(context, this->global = pw_global_new(context,
PW_TYPE_INTERFACE_Module, PW_TYPE_INTERFACE_Module,
PW_VERSION_MODULE, PW_VERSION_MODULE,
PW_MODULE_PERM_MASK,
NULL, NULL,
global_bind, global_bind,
this); this);

View file

@ -773,6 +773,7 @@ int pw_impl_node_register(struct pw_impl_node *this,
this->global = pw_global_new(context, this->global = pw_global_new(context,
PW_TYPE_INTERFACE_Node, PW_TYPE_INTERFACE_Node,
PW_VERSION_NODE, PW_VERSION_NODE,
PW_NODE_PERM_MASK,
properties, properties,
global_bind, global_bind,
this); this);

View file

@ -1000,6 +1000,7 @@ int pw_impl_port_register(struct pw_impl_port *port,
port->global = pw_global_new(node->context, port->global = pw_global_new(node->context,
PW_TYPE_INTERFACE_Port, PW_TYPE_INTERFACE_Port,
PW_VERSION_PORT, PW_VERSION_PORT,
PW_PORT_PERM_MASK,
properties, properties,
global_bind, global_bind,
port); port);

View file

@ -31,6 +31,8 @@ extern "C" {
#define PW_TYPE_INTERFACE_Link PW_TYPE_INFO_INTERFACE_BASE "Link" #define PW_TYPE_INTERFACE_Link PW_TYPE_INFO_INTERFACE_BASE "Link"
#define PW_LINK_PERM_MASK PW_PERM_R
#define PW_VERSION_LINK 3 #define PW_VERSION_LINK 3
struct pw_link; struct pw_link;

View file

@ -24,6 +24,8 @@ extern "C" {
*/ */
#define PW_TYPE_INTERFACE_Module PW_TYPE_INFO_INTERFACE_BASE "Module" #define PW_TYPE_INTERFACE_Module PW_TYPE_INFO_INTERFACE_BASE "Module"
#define PW_MODULE_PERM_MASK PW_PERM_R
#define PW_VERSION_MODULE 3 #define PW_VERSION_MODULE 3
struct pw_module; struct pw_module;

View file

@ -29,6 +29,8 @@ extern "C" {
*/ */
#define PW_TYPE_INTERFACE_Node PW_TYPE_INFO_INTERFACE_BASE "Node" #define PW_TYPE_INTERFACE_Node PW_TYPE_INFO_INTERFACE_BASE "Node"
#define PW_NODE_PERM_MASK PW_PERM_RWXM
#define PW_VERSION_NODE 3 #define PW_VERSION_NODE 3
struct pw_node; struct pw_node;

View file

@ -30,7 +30,8 @@ extern "C" {
* present in order to call methods that modify the object. */ * present in order to call methods that modify the object. */
#define PW_PERM_M 0010 /**< metadata can be set on object, Since 0.3.9 */ #define PW_PERM_M 0010 /**< metadata can be set on object, Since 0.3.9 */
#define PW_PERM_RWX (PW_PERM_R|PW_PERM_W|PW_PERM_X) #define PW_PERM_RW (PW_PERM_R|PW_PERM_W)
#define PW_PERM_RWX (PW_PERM_RW|PW_PERM_X)
#define PW_PERM_RWXM (PW_PERM_RWX|PW_PERM_M) #define PW_PERM_RWXM (PW_PERM_RWX|PW_PERM_M)
#define PW_PERM_IS_R(p) (((p)&PW_PERM_R) == PW_PERM_R) #define PW_PERM_IS_R(p) (((p)&PW_PERM_R) == PW_PERM_R)

View file

@ -29,6 +29,8 @@ extern "C" {
#define PW_TYPE_INTERFACE_Port PW_TYPE_INFO_INTERFACE_BASE "Port" #define PW_TYPE_INTERFACE_Port PW_TYPE_INFO_INTERFACE_BASE "Port"
#define PW_PORT_PERM_MASK PW_PERM_R|PW_PERM_X|PW_PERM_M
#define PW_VERSION_PORT 3 #define PW_VERSION_PORT 3
struct pw_port; struct pw_port;

View file

@ -288,6 +288,7 @@ struct pw_global {
const char *type; /**< type of interface */ const char *type; /**< type of interface */
uint32_t version; /**< version of interface */ uint32_t version; /**< version of interface */
uint32_t permission_mask; /**< possible permissions */
pw_global_bind_func_t func; /**< bind function */ pw_global_bind_func_t func; /**< bind function */
void *object; /**< object associated with the interface */ void *object; /**< object associated with the interface */