Commit f2c32aad authored by Niels Möller's avatar Niels Möller
Browse files

* src/pty-helper.c (pty_send_message, pty_recv_message): Make

linux style ucred handling conditional on SCM_CREDENTIALS being
defined.

* src/pty-helper.h (struct pty_message): Don't depend on the
system to define struct ucred, instead, inline a struct with pid,
uid and gid.

Rev: src/pty-helper.c:1.3
Rev: src/pty-helper.h:1.3
parent fa5a266f
......@@ -65,12 +65,22 @@ pty_send_message(int socket, const struct pty_message *message)
{
cmsg = cmsg ? CMSG_NXTHDR(&hdr, cmsg) : CMSG_FIRSTHDR(&hdr);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_CREDENTIALS;
cmsg->cmsg_len = CMSG_LEN(sizeof(message->creds));
memcpy(CMSG_DATA(cmsg), &message->creds, sizeof(message->creds));
controllen += CMSG_SPACE(sizeof(message->creds));
#ifdef SCM_CREDENTIALS
{
struct ucred *creds;
/* Linux style credentials */
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_CREDENTIALS;
cmsg->cmsg_len = CMSG_LEN(sizeof(*creds));
creds = (struct ucred *) CMSG_DATA(cmsg);
creds->pid = message->creds.pid;
creds->uid = message->creds.uid;
creds->gid = message->creds.gid;
controllen += CMSG_SPACE(sizeof(*creds));
}
#endif
}
if (message->fd != -1)
{
......@@ -161,20 +171,27 @@ pty_recv_message(int socket, struct pty_message *message)
continue;
switch (cmsg->cmsg_type)
{
#ifdef SCM_CREDENTIALS
case SCM_CREDENTIALS:
if (cmsg->cmsg_len != CMSG_LEN(sizeof(message->creds)))
continue;
if (message->has_creds)
/* Shouldn't be multiple credentials, but if there are,
ignore all but the first. */
continue;
memcpy(&message->creds, CMSG_DATA(cmsg), sizeof(message->creds));
message->has_creds = 1;
{
struct ucred *creds;
if (cmsg->cmsg_len != CMSG_LEN(sizeof(*creds)))
continue;
if (message->has_creds)
/* Shouldn't be multiple credentials, but if there are,
ignore all but the first. */
continue;
creds = (struct ucred *) CMSG_DATA(cmsg);
message->creds.pid = creds->pid;
message->creds.uid = creds->uid;
message->creds.gid = creds->gid;
message->has_creds = 1;
}
break;
#endif
case SCM_RIGHTS:
{
int *fd = (int *) CMSG_DATA(cmsg);
......
......@@ -4,7 +4,7 @@
/* For pid_t */
#include <unistd.h>
/* For struct ucreds */
/* For struct ucred */
#include <sys/types.h>
#include <sys/socket.h>
......@@ -39,7 +39,13 @@ struct pty_message
/* Transferred credentials */
int has_creds;
struct ucred creds;
/* Same fields as linux' struct ucred */
struct {
pid_t pid;
uid_t uid;
gid_t gid;
} creds;
/* Transferred fd (-1 if none) */
int fd;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment