mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-21 08:56:56 -05:00
protocol: add security label to a client
Don't pass the ucred to the client construct, just set the properties in the protocol. Use the client properties to get ucred. Add the security label to the client properties (from SO_PEERSEC)
This commit is contained in:
parent
4e70cddf1d
commit
a2bf4ce96e
5 changed files with 38 additions and 53 deletions
|
|
@ -251,24 +251,32 @@ static struct pw_client *client_new(struct server *s, int fd)
|
|||
struct pw_protocol *protocol = s->this.protocol;
|
||||
struct protocol_data *pd = protocol->user_data;
|
||||
socklen_t len;
|
||||
struct ucred ucred, *ucredp;
|
||||
struct ucred ucred;
|
||||
struct pw_core *core = protocol->core;
|
||||
struct pw_properties *props;
|
||||
|
||||
len = sizeof(ucred);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0) {
|
||||
pw_log_error("no peercred: %m");
|
||||
ucredp = NULL;
|
||||
} else {
|
||||
ucredp = &ucred;
|
||||
}
|
||||
char buffer[1024];
|
||||
|
||||
props = pw_properties_new(PW_CLIENT_PROP_PROTOCOL, "protocol-native", NULL);
|
||||
if (props == NULL)
|
||||
goto exit;
|
||||
|
||||
len = sizeof(ucred);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0) {
|
||||
pw_log_error("no peercred: %m");
|
||||
} else {
|
||||
pw_properties_setf(props, PW_CLIENT_PROP_UCRED_PID, "%d", ucred.pid);
|
||||
pw_properties_setf(props, PW_CLIENT_PROP_UCRED_UID, "%d", ucred.uid);
|
||||
pw_properties_setf(props, PW_CLIENT_PROP_UCRED_GID, "%d", ucred.gid);
|
||||
}
|
||||
|
||||
len = sizeof(buffer);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buffer, &len) < 0) {
|
||||
pw_log_error("no peersec: %m");
|
||||
} else {
|
||||
pw_properties_setf(props, PW_CLIENT_PROP_SEC_LABEL, "%s", buffer);
|
||||
}
|
||||
|
||||
client = pw_client_new(protocol->core,
|
||||
ucredp,
|
||||
props,
|
||||
sizeof(struct client_data));
|
||||
if (client == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue