View | Details | Raw Unified | Return to bug 246189 | Differences between
and this patch

Collapse All | Expand All

(-)i/graphics/wayland/files/patch-src_wayland-server.c (-8 / +18 lines)
Lines 1-96 Link Here
1
--- src/wayland-server.c.orig	2020-02-11 23:46:03 UTC
1
--- src/wayland-server.c.orig	2020-02-11 23:46:03 UTC
2
+++ src/wayland-server.c
2
+++ src/wayland-server.c
3
@@ -25,6 +25,8 @@
3
@@ -25,6 +25,8 @@
4
 
4
 
5
 #define _GNU_SOURCE
5
 #define _GNU_SOURCE
6
 
6
 
7
+#include "../config.h"
7
+#include "../config.h"
8
+
8
+
9
 #include <stdbool.h>
9
 #include <stdbool.h>
10
 #include <stdlib.h>
10
 #include <stdlib.h>
11
 #include <stdint.h>
11
 #include <stdint.h>
12
@@ -44,6 +46,11 @@
12
@@ -44,6 +46,12 @@
13
 #include <sys/file.h>
13
 #include <sys/file.h>
14
 #include <sys/stat.h>
14
 #include <sys/stat.h>
15
 
15
 
16
+#ifdef HAVE_SYS_UCRED_H
16
+#ifdef HAVE_SYS_UCRED_H
17
+#include <sys/types.h>
17
+#include <sys/types.h>
18
+#include <sys/ucred.h>
18
+#include <sys/ucred.h>
19
+#include <sys/param.h>
19
+#endif
20
+#endif
20
+
21
+
21
 #include "wayland-util.h"
22
 #include "wayland-util.h"
22
 #include "wayland-private.h"
23
 #include "wayland-private.h"
23
 #include "wayland-server-private.h"
24
 #include "wayland-server-private.h"
24
@@ -79,7 +86,13 @@ struct wl_client {
25
@@ -79,7 +87,13 @@ struct wl_client {
25
 	struct wl_list link;
26
 	struct wl_list link;
26
 	struct wl_map objects;
27
 	struct wl_map objects;
27
 	struct wl_priv_signal destroy_signal;
28
 	struct wl_priv_signal destroy_signal;
28
+#ifdef HAVE_SYS_UCRED_H
29
+#ifdef HAVE_SYS_UCRED_H
29
+	/* FreeBSD */
30
+	/* FreeBSD */
30
+	struct xucred xucred;
31
+	struct xucred xucred;
31
+#else
32
+#else
32
+	/* Linux */
33
+	/* Linux */
33
 	struct ucred ucred;
34
 	struct ucred ucred;
34
+#endif
35
+#endif
35
 	int error;
36
 	int error;
36
 	struct wl_priv_signal resource_created_signal;
37
 	struct wl_priv_signal resource_created_signal;
37
 };
38
 };
38
@@ -315,7 +328,13 @@ wl_resource_post_error(struct wl_resource *resource,
39
@@ -315,7 +329,17 @@ wl_resource_post_error(struct wl_resource *resource,
39
 static void
40
 static void
40
 destroy_client_with_error(struct wl_client *client, const char *reason)
41
 destroy_client_with_error(struct wl_client *client, const char *reason)
41
 {
42
 {
42
+#ifdef HAVE_SYS_UCRED_H
43
+#ifdef HAVE_SYS_UCRED_H
43
+	/* FreeBSD */
44
+	/* FreeBSD */
45
+#if __FreeBSD_version >= 1300030
46
+	wl_log("%s (pid %u)\n", reason, client->xucred.cr_pid);
47
+#else
44
+	wl_log("%s\n", reason);
48
+	wl_log("%s\n", reason);
49
+#endif
45
+#else
50
+#else
46
+	/* Linux */
51
+	/* Linux */
47
 	wl_log("%s (pid %u)\n", reason, client->ucred.pid);
52
 	wl_log("%s (pid %u)\n", reason, client->ucred.pid);
48
+#endif
53
+#endif
49
 	wl_client_destroy(client);
54
 	wl_client_destroy(client);
50
 }
55
 }
51
 
56
 
52
@@ -529,10 +548,20 @@ wl_client_create(struct wl_display *display, int fd)
57
@@ -529,10 +553,20 @@ wl_client_create(struct wl_display *display, int fd)
53
 	if (!client->source)
58
 	if (!client->source)
54
 		goto err_client;
59
 		goto err_client;
55
 
60
 
56
+#if defined(SO_PEERCRED)
61
+#if defined(SO_PEERCRED)
57
+	/* Linux */
62
+	/* Linux */
58
 	len = sizeof client->ucred;
63
 	len = sizeof client->ucred;
59
 	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
64
 	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
60
 		       &client->ucred, &len) < 0)
65
 		       &client->ucred, &len) < 0)
61
 		goto err_source;
66
 		goto err_source;
62
+#elif defined(LOCAL_PEERCRED)
67
+#elif defined(LOCAL_PEERCRED)
63
+	/* FreeBSD */
68
+	/* FreeBSD */
64
+	len = sizeof client->xucred;
69
+	len = sizeof client->xucred;
65
+	if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED,
70
+	if (getsockopt(fd, 0, LOCAL_PEERCRED,
66
+		       &client->xucred, &len) < 0 ||
71
+		       &client->xucred, &len) < 0 ||
67
+		       client->xucred.cr_version != XUCRED_VERSION)
72
+		       client->xucred.cr_version != XUCRED_VERSION)
68
+		goto err_source;
73
+		goto err_source;
69
+#endif
74
+#endif
70
 
75
 
71
 	client->connection = wl_connection_create(fd);
76
 	client->connection = wl_connection_create(fd);
72
 	if (client->connection == NULL)
77
 	if (client->connection == NULL)
73
@@ -586,12 +615,23 @@ WL_EXPORT void
78
@@ -586,12 +620,28 @@ WL_EXPORT void
74
 wl_client_get_credentials(struct wl_client *client,
79
 wl_client_get_credentials(struct wl_client *client,
75
 			  pid_t *pid, uid_t *uid, gid_t *gid)
80
 			  pid_t *pid, uid_t *uid, gid_t *gid)
76
 {
81
 {
77
+#ifdef HAVE_SYS_UCRED_H
82
+#ifdef HAVE_SYS_UCRED_H
78
+	/* FreeBSD */
83
+	/* FreeBSD
84
+	 * PID available since 2019: https://reviews.freebsd.org/rS348419 */
79
 	if (pid)
85
 	if (pid)
80
+		*pid = 0; /* FIXME: not defined on FreeBSD */
86
+#if __FreeBSD_version >= 1300030
87
+		*pid = client->xucred.cr_pid;
88
+#else
89
+		*pid = 0;
90
+#endif
81
+	if (uid)
91
+	if (uid)
82
+		*uid = client->xucred.cr_uid;
92
+		*uid = client->xucred.cr_uid;
83
+	if (gid)
93
+	if (gid)
84
+		*gid = client->xucred.cr_gid;
94
+		*gid = client->xucred.cr_gid;
85
+#else
95
+#else
86
+	/* Linux */
96
+	/* Linux */
87
+	if (pid)
97
+	if (pid)
88
 		*pid = client->ucred.pid;
98
 		*pid = client->ucred.pid;
89
 	if (uid)
99
 	if (uid)
90
 		*uid = client->ucred.uid;
100
 		*uid = client->ucred.uid;
91
 	if (gid)
101
 	if (gid)
92
 		*gid = client->ucred.gid;
102
 		*gid = client->ucred.gid;
93
+#endif
103
+#endif
94
 }
104
 }
95
 
105
 
96
 /** Get the file descriptor for the client
106
 /** Get the file descriptor for the client

Return to bug 246189