mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-04 13:29:51 -05:00
Add wl_client_get_credentials() to get unix credentials for client
This commit is contained in:
parent
5536031bfb
commit
8503cd6859
2 changed files with 24 additions and 0 deletions
|
|
@ -63,6 +63,7 @@ struct wl_client {
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
struct wl_map objects;
|
struct wl_map objects;
|
||||||
|
struct ucred ucred;
|
||||||
int error;
|
int error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -286,6 +287,7 @@ WL_EXPORT struct wl_client *
|
||||||
wl_client_create(struct wl_display *display, int fd)
|
wl_client_create(struct wl_display *display, int fd)
|
||||||
{
|
{
|
||||||
struct wl_client *client;
|
struct wl_client *client;
|
||||||
|
socklen_t len;
|
||||||
|
|
||||||
client = malloc(sizeof *client);
|
client = malloc(sizeof *client);
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
|
|
@ -296,6 +298,14 @@ wl_client_create(struct wl_display *display, int fd)
|
||||||
client->source = wl_event_loop_add_fd(display->loop, fd,
|
client->source = wl_event_loop_add_fd(display->loop, fd,
|
||||||
WL_EVENT_READABLE,
|
WL_EVENT_READABLE,
|
||||||
wl_client_connection_data, client);
|
wl_client_connection_data, client);
|
||||||
|
|
||||||
|
len = sizeof client->ucred;
|
||||||
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
|
||||||
|
&client->ucred, &len) < 0) {
|
||||||
|
free(client);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
client->connection =
|
client->connection =
|
||||||
wl_connection_create(fd, wl_client_connection_update, client);
|
wl_connection_create(fd, wl_client_connection_update, client);
|
||||||
if (client->connection == NULL) {
|
if (client->connection == NULL) {
|
||||||
|
|
@ -318,6 +328,18 @@ wl_client_create(struct wl_display *display, int fd)
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WL_EXPORT void
|
||||||
|
wl_client_get_credentials(struct wl_client *client,
|
||||||
|
pid_t *pid, uid_t *uid, gid_t *gid)
|
||||||
|
{
|
||||||
|
if (pid)
|
||||||
|
*pid = client->ucred.pid;
|
||||||
|
if (uid)
|
||||||
|
*uid = client->ucred.uid;
|
||||||
|
if (gid)
|
||||||
|
*gid = client->ucred.gid;
|
||||||
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
wl_client_add_resource(struct wl_client *client,
|
wl_client_add_resource(struct wl_client *client,
|
||||||
struct wl_resource *resource)
|
struct wl_resource *resource)
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,8 @@ void wl_display_remove_global(struct wl_display *display,
|
||||||
struct wl_client *wl_client_create(struct wl_display *display, int fd);
|
struct wl_client *wl_client_create(struct wl_display *display, int fd);
|
||||||
void wl_client_destroy(struct wl_client *client);
|
void wl_client_destroy(struct wl_client *client);
|
||||||
void wl_client_flush(struct wl_client *client);
|
void wl_client_flush(struct wl_client *client);
|
||||||
|
void wl_client_get_credentials(struct wl_client *client,
|
||||||
|
pid_t *pid, uid_t *uid, gid_t *gid);
|
||||||
|
|
||||||
struct wl_resource *
|
struct wl_resource *
|
||||||
wl_client_add_object(struct wl_client *client,
|
wl_client_add_object(struct wl_client *client,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue