Skip to content

Commit 8668d05

Browse files
committed
ipc: set gid on unix sockets
When creating a unix socket it's default gid is that of the parent directory. If the SOCKETDIR is owned by root:wheel with 1777 mode some of the pacemaker daemons end up unable to communicate with one another due to having insufficient permissions on the sockets. This can be fixed by setting the client sockets gid to the primary group of the server socket owner it's attempting to connect to. And, on the server side by setting the gid to the already captured gid stored in the connection info. This ensures that regardless of who owns the socket directory, as long as the applications have r/w access to it they should work.
1 parent 2671606 commit 8668d05

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/ipc_socket.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ set_sock_addr(struct sockaddr_un *address, const char *socket_name)
6060

6161
static int32_t
6262
qb_ipc_dgram_sock_setup(const char *base_name,
63-
const char *service_name, int32_t * sock_pt)
63+
const char *service_name, int32_t * sock_pt,
64+
gid_t gid)
6465
{
6566
int32_t request_fd;
6667
struct sockaddr_un local_address;
@@ -86,6 +87,7 @@ qb_ipc_dgram_sock_setup(const char *base_name,
8687
sizeof(local_address));
8788
#if !(defined(QB_LINUX) || defined(QB_CYGWIN))
8889
chmod(local_address.sun_path, 0660);
90+
chown(local_address.sun_path, getuid(), gid);
8991
#endif
9092
if (res < 0) {
9193
goto error_connect;
@@ -221,12 +223,12 @@ static int32_t
221223
qb_ipc_dgram_sock_connect(const char *base_name,
222224
const char *local_name,
223225
const char *remote_name,
224-
int32_t max_msg_size, int32_t * sock_pt)
226+
int32_t max_msg_size, int32_t * sock_pt, gid_t gid)
225227
{
226228
char sock_path[PATH_MAX];
227229
struct sockaddr_un remote_address;
228230
int32_t res = qb_ipc_dgram_sock_setup(base_name, local_name,
229-
sock_pt);
231+
sock_pt, gid);
230232
if (res < 0) {
231233
return res;
232234
}
@@ -547,14 +549,14 @@ qb_ipcc_us_connect(struct qb_ipcc_connection * c,
547549
fd_hdr = -1;
548550

549551
res = qb_ipc_dgram_sock_connect(r->response, "response", "request",
550-
r->max_msg_size, &c->request.u.us.sock);
552+
r->max_msg_size, &c->request.u.us.sock, c->egid);
551553
if (res != 0) {
552554
goto cleanup_hdr;
553555
}
554556
c->response.u.us.sock = c->request.u.us.sock;
555557

556558
res = qb_ipc_dgram_sock_connect(r->response, "event", "event-tx",
557-
r->max_msg_size, &c->event.u.us.sock);
559+
r->max_msg_size, &c->event.u.us.sock, c->egid);
558560
if (res != 0) {
559561
goto cleanup_hdr;
560562
}
@@ -776,7 +778,7 @@ qb_ipcs_us_connect(struct qb_ipcs_service *s,
776778

777779
/* request channel */
778780
res = qb_ipc_dgram_sock_setup(r->response, "request",
779-
&c->request.u.us.sock);
781+
&c->request.u.us.sock, c->egid);
780782
if (res < 0) {
781783
goto cleanup_hdr;
782784
}
@@ -790,7 +792,7 @@ qb_ipcs_us_connect(struct qb_ipcs_service *s,
790792

791793
/* event channel */
792794
res = qb_ipc_dgram_sock_setup(r->response, "event-tx",
793-
&c->event.u.us.sock);
795+
&c->event.u.us.sock, c->egid);
794796
if (res < 0) {
795797
goto cleanup_hdr;
796798
}

0 commit comments

Comments
 (0)