From 594cfb7586089dfefab60574495baf6ed4048c1d Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 11 Nov 2020 10:04:27 +0100 Subject: pflocal: Record socket creator so io_stat can return it * pflocal/sock.h (struct sock): Add uid and gid fields. * pflocal/sock.c (sock_create): Set uid and gid to 0. * pflocal/mig-mutate.h (SOCKET_IMPORTS): Import ../libtrivfs/mig-decls.h. (PF_INTRAN, PF_INTRAN_PAYLOAD, PF_DESTRUCTOR): New macros. * pflocal/pf.c: Include hurd/trivfs.h. (S_socket_create): Update parameters. Set sock's uid and gid fields according to pf->user. * pflocal/io.c (S_io_stat): Set st_uid and st_gid according to pf. --- pflocal/io.c | 2 ++ pflocal/mig-mutate.h | 8 +++++++- pflocal/pf.c | 8 +++++++- pflocal/sock.c | 2 ++ pflocal/sock.h | 4 ++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pflocal/io.c b/pflocal/io.c index 23e71ea4..2a6b104c 100644 --- a/pflocal/io.c +++ b/pflocal/io.c @@ -327,6 +327,8 @@ S_io_stat (struct sock_user *user, struct stat *st) st->st_ino = sock->id; /* As we try to be clever with large transfers, ask for them. */ st->st_blksize = vm_page_size * 16; + st->st_uid = sock->uid; + st->st_gid = sock->gid; pthread_mutex_lock (&sock->lock); /* Make sure the pipes don't go away... */ diff --git a/pflocal/mig-mutate.h b/pflocal/mig-mutate.h index 0743f336..99be2a4f 100644 --- a/pflocal/mig-mutate.h +++ b/pflocal/mig-mutate.h @@ -39,4 +39,10 @@ #define ADDRPORT_INTRAN_PAYLOAD addr_t begin_using_addr_payload #define ADDRPORT_DESTRUCTOR end_using_addr_port (addr_t) -#define SOCKET_IMPORTS import "mig-decls.h"; +#define SOCKET_IMPORTS \ + import "mig-decls.h"; \ + import "../libtrivfs/mig-decls.h"; \ + +#define PF_INTRAN trivfs_protid_t trivfs_begin_using_protid (pf_t) +#define PF_INTRAN_PAYLOAD trivfs_protid_t trivfs_begin_using_protid_payload +#define PF_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t) diff --git a/pflocal/pf.c b/pflocal/pf.c index 35b3d8c3..c905f3bf 100644 --- a/pflocal/pf.c +++ b/pflocal/pf.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "sock.h" @@ -29,7 +30,7 @@ /* Create a new socket. Sock type is, for example, SOCK_STREAM, SOCK_DGRAM, or some such. */ error_t -S_socket_create (mach_port_t pf, +S_socket_create (trivfs_protid_t pf, int sock_type, int protocol, mach_port_t *port, mach_msg_type_name_t *port_type) { @@ -77,6 +78,11 @@ S_socket_create (mach_port_t pf, else *port_type = MACH_MSG_TYPE_MAKE_SEND; } + + if (pf->user->uids->num > 0) + sock->uid = pf->user->uids->ids[0]; + if (pf->user->gids->num > 0) + sock->gid = pf->user->gids->ids[0]; return err; } diff --git a/pflocal/sock.c b/pflocal/sock.c index 89ba16e2..e39e2932 100644 --- a/pflocal/sock.c +++ b/pflocal/sock.c @@ -123,6 +123,8 @@ sock_create (struct pipe_class *pipe_class, mode_t mode, struct sock **sock) new->connect_queue = NULL; new->pipe_class = pipe_class; new->addr = NULL; + new->uid = 0; + new->gid = 0; memset (&new->change_time, 0, sizeof (new->change_time)); pthread_mutex_init (&new->lock, NULL); diff --git a/pflocal/sock.h b/pflocal/sock.h index c1e73f9b..64b030e5 100644 --- a/pflocal/sock.h +++ b/pflocal/sock.h @@ -85,6 +85,10 @@ struct sock /* A connection queue we're attempting to connect through; a socket may only be attempting one connection at a time. */ struct connq *connect_queue; + + /* Effective identity of the creator of the socket */ + uid_t uid; + gid_t gid; }; /* Socket flags */ -- cgit v1.2.3