Skip to content

Commit

Permalink
gotta setsockkopt before sending a passcred
Browse files Browse the repository at this point in the history
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
hallyn committed Nov 29, 2013
1 parent 0dbeff3 commit 72fca6c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions movepid.c
Expand Up @@ -134,8 +134,8 @@ void send_pid(int sock, int pid)
struct cmsghdr *cmsg;
struct ucred cred = {
.pid = pid,
.uid = getuid(),
.gid = getgid(),
.uid = geteuid(),
.gid = getegid(),
};
char cmsgbuf[CMSG_SPACE(sizeof(cred))];
char buf[1];
Expand All @@ -157,6 +157,7 @@ void send_pid(int sock, int pid)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;

nih_info("Sending pid %d", (int)cred.pid);
sendmsg(sock, &msg, 0);
}

Expand Down Expand Up @@ -193,6 +194,12 @@ main (int argc,

dbus_connection_get_unix_fd(conn, &fd);
send_message(conn);

int optval = 1;
if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) == -1) {
perror("setsockopt");
return -1;
}
send_pid(fd, pid);

dbus_connection_unref (conn);
Expand Down

0 comments on commit 72fca6c

Please sign in to comment.