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

Collapse All | Expand All

(-)w/graphics/wayland/files/patch-src_wayland-server.c (-6 / +16 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,11 @@
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
+#endif
19
+#endif
20
+
20
+
21
 #include "wayland-util.h"
21
 #include "wayland-util.h"
22
 #include "wayland-private.h"
22
 #include "wayland-private.h"
23
 #include "wayland-server-private.h"
23
 #include "wayland-server-private.h"
24
@@ -79,7 +86,13 @@ struct wl_client {
24
@@ -79,7 +86,13 @@ struct wl_client {
25
 	struct wl_list link;
25
 	struct wl_list link;
26
 	struct wl_map objects;
26
 	struct wl_map objects;
27
 	struct wl_priv_signal destroy_signal;
27
 	struct wl_priv_signal destroy_signal;
28
+#ifdef HAVE_SYS_UCRED_H
28
+#ifdef HAVE_SYS_UCRED_H
29
+	/* FreeBSD */
29
+	/* FreeBSD */
30
+	struct xucred xucred;
30
+	struct xucred xucred;
31
+#else
31
+#else
32
+	/* Linux */
32
+	/* Linux */
33
 	struct ucred ucred;
33
 	struct ucred ucred;
34
+#endif
34
+#endif
35
 	int error;
35
 	int error;
36
 	struct wl_priv_signal resource_created_signal;
36
 	struct wl_priv_signal resource_created_signal;
37
 };
37
 };
38
@@ -315,7 +328,13 @@ wl_resource_post_error(struct wl_resource *resource,
38
@@ -315,7 +328,17 @@ wl_resource_post_error(struct wl_resource *resource,
39
 static void
39
 static void
40
 destroy_client_with_error(struct wl_client *client, const char *reason)
40
 destroy_client_with_error(struct wl_client *client, const char *reason)
41
 {
41
 {
42
+#ifdef HAVE_SYS_UCRED_H
42
+#ifdef HAVE_SYS_UCRED_H
43
+	/* FreeBSD */
43
+	/* FreeBSD */
44
+#ifdef cr_pid 
45
+	wl_log("%s (pid %u)\n", reason, client->xucred.cr_pid);
46
+#else
44
+	wl_log("%s\n", reason);
47
+	wl_log("%s\n", reason);
48
+#endif
45
+#else
49
+#else
46
+	/* Linux */
50
+	/* Linux */
47
 	wl_log("%s (pid %u)\n", reason, client->ucred.pid);
51
 	wl_log("%s (pid %u)\n", reason, client->ucred.pid);
48
+#endif
52
+#endif
49
 	wl_client_destroy(client);
53
 	wl_client_destroy(client);
50
 }
54
 }
51
 
55
 
52
@@ -529,10 +548,20 @@ wl_client_create(struct wl_display *display, int fd)
56
@@ -529,10 +552,20 @@ wl_client_create(struct wl_display *display, int fd)
53
 	if (!client->source)
57
 	if (!client->source)
54
 		goto err_client;
58
 		goto err_client;
55
 
59
 
56
+#if defined(SO_PEERCRED)
60
+#if defined(SO_PEERCRED)
57
+	/* Linux */
61
+	/* Linux */
58
 	len = sizeof client->ucred;
62
 	len = sizeof client->ucred;
59
 	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
63
 	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
60
 		       &client->ucred, &len) < 0)
64
 		       &client->ucred, &len) < 0)
61
 		goto err_source;
65
 		goto err_source;
62
+#elif defined(LOCAL_PEERCRED)
66
+#elif defined(LOCAL_PEERCRED)
63
+	/* FreeBSD */
67
+	/* FreeBSD */
64
+	len = sizeof client->xucred;
68
+	len = sizeof client->xucred;
65
+	if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED,
69
+	if (getsockopt(fd, 0, LOCAL_PEERCRED,
66
+		       &client->xucred, &len) < 0 ||
70
+		       &client->xucred, &len) < 0 ||
67
+		       client->xucred.cr_version != XUCRED_VERSION)
71
+		       client->xucred.cr_version != XUCRED_VERSION)
68
+		goto err_source;
72
+		goto err_source;
69
+#endif
73
+#endif
70
 
74
 
71
 	client->connection = wl_connection_create(fd);
75
 	client->connection = wl_connection_create(fd);
72
 	if (client->connection == NULL)
76
 	if (client->connection == NULL)
73
@@ -586,12 +615,23 @@ WL_EXPORT void
77
@@ -586,12 +619,29 @@ WL_EXPORT void
74
 wl_client_get_credentials(struct wl_client *client,
78
 wl_client_get_credentials(struct wl_client *client,
75
 			  pid_t *pid, uid_t *uid, gid_t *gid)
79
 			  pid_t *pid, uid_t *uid, gid_t *gid)
76
 {
80
 {
77
+#ifdef HAVE_SYS_UCRED_H
81
+#ifdef HAVE_SYS_UCRED_H
78
+	/* FreeBSD */
82
+	/* FreeBSD
83
+	 * PID available since 2019: https://reviews.freebsd.org/rS348419
84
+	 * conveniently, cr_pid is a macro */
79
 	if (pid)
85
 	if (pid)
80
+		*pid = 0; /* FIXME: not defined on FreeBSD */
86
+#ifdef cr_pid 
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