Skip to content

Commit 2671606

Browse files
committed
lib: store server peer credentials in qb_ipcc_connection
1 parent 888ef2e commit 2671606

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

lib/ipc_int.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ struct qb_ipcc_funcs {
9191
struct qb_ipcc_connection {
9292
char name[NAME_MAX];
9393
int32_t needs_sock_for_poll;
94+
pid_t pid;
95+
uid_t euid;
96+
gid_t egid;
9497
struct qb_ipc_one_way setup;
9598
struct qb_ipc_one_way request;
9699
struct qb_ipc_one_way response;

lib/ipc_setup.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ struct ipc_auth_ugp {
5151
struct ipc_auth_data {
5252
int32_t sock;
5353
struct qb_ipcs_service *s;
54-
struct qb_ipc_connection_request msg;
54+
union {
55+
struct qb_ipc_connection_request req;
56+
struct qb_ipc_connection_response res;
57+
} msg;
5558
struct msghdr msg_recv;
5659
struct iovec iov_recv;
5760
struct ipc_auth_ugp ugp;
@@ -441,6 +444,7 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
441444
{
442445
int32_t res;
443446
struct qb_ipc_connection_request request;
447+
struct ipc_auth_data *data;
444448
#ifdef QB_LINUX
445449
int off = 0;
446450
int on = 1;
@@ -464,21 +468,39 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
464468
qb_ipcc_us_sock_close(c->setup.u.us.sock);
465469
return res;
466470
}
471+
472+
data = init_ipc_auth_data(c->setup.u.us.sock, sizeof(struct qb_ipc_connection_response));
473+
if (data == NULL) {
474+
qb_ipcc_us_sock_close(c->setup.u.us.sock);
475+
return -1;
476+
}
477+
478+
qb_ipc_us_ready(&c->setup, NULL, -1, POLLIN);
479+
res = qb_ipc_us_recv_msghdr(data);
480+
467481
#ifdef QB_LINUX
468482
setsockopt(c->setup.u.us.sock, SOL_SOCKET, SO_PASSCRED, &off,
469483
sizeof(off));
470484
#endif
471485

472-
res =
473-
qb_ipc_us_recv(&c->setup, r,
474-
sizeof(struct qb_ipc_connection_response), -1);
475-
if (res < 0) {
486+
if (res != data->len) {
487+
destroy_ipc_auth_data(data);
476488
return res;
477489
}
478490

491+
memcpy(r, &data->msg.res, sizeof(struct qb_ipc_connection_response));
492+
493+
qb_ipc_auth_creds(data);
494+
c->pid = data->ugp.pid;
495+
c->euid = data->ugp.uid;
496+
c->egid = data->ugp.gid;
497+
479498
if (r->hdr.error != 0) {
499+
destroy_ipc_auth_data(data);
480500
return r->hdr.error;
481501
}
502+
503+
destroy_ipc_auth_data(data);
482504
return 0;
483505
}
484506

@@ -744,7 +766,7 @@ process_auth(int32_t fd, int32_t revents, void *d)
744766

745767
if (res < 0) {
746768
close(data->sock);
747-
} else if (data->msg.hdr.id == QB_IPC_MSG_AUTHENTICATE) {
769+
} else if (data->msg.req.hdr.id == QB_IPC_MSG_AUTHENTICATE) {
748770
(void)handle_new_connection(data->s, res, data->sock, &data->msg, data->len, &data->ugp);
749771
} else {
750772
close(data->sock);

0 commit comments

Comments
 (0)