Index: sys/sys/protosw.h =================================================================== RCS file: /cvs/src/sys/sys/protosw.h,v retrieving revision 1.3 diff -u -r1.3 protosw.h --- sys/sys/protosw.h 1996/04/21 22:31:54 1.3 +++ sys/sys/protosw.h 2000/07/29 23:54:12 @@ -148,8 +148,9 @@ #define PRU_SLOWTIMO 19 /* 500ms timeout */ #define PRU_PROTORCV 20 /* receive from below */ #define PRU_PROTOSEND 21 /* send to below */ +#define PRU_PEEREID 22 /* get local peer effective id */ -#define PRU_NREQ 21 +#define PRU_NREQ 22 #ifdef PRUREQUESTS char *prurequests[] = { @@ -158,7 +159,7 @@ "RCVD", "SEND", "ABORT", "CONTROL", "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", - "PROTORCV", "PROTOSEND", + "PROTORCV", "PROTOSEND", "PEEREID", }; #endif Index: sys/sys/socket.h =================================================================== RCS file: /cvs/src/sys/sys/socket.h,v retrieving revision 1.29 diff -u -r1.29 socket.h --- sys/sys/socket.h 1999/06/06 23:19:08 1.29 +++ sys/sys/socket.h 2000/07/29 23:54:15 @@ -388,6 +388,7 @@ int bind __P((int, const struct sockaddr *, socklen_t)); int connect __P((int, const struct sockaddr *, socklen_t)); int getpeername __P((int, struct sockaddr *, socklen_t *)); +int getpeereid __P((int, uid_t *, gid_t *)); int getsockname __P((int, struct sockaddr *, socklen_t *)); int getsockopt __P((int, int, int, void *, socklen_t *)); int listen __P((int, int)); Index: sys/sys/unpcb.h =================================================================== RCS file: /cvs/src/sys/sys/unpcb.h,v retrieving revision 1.4 diff -u -r1.4 unpcb.h --- sys/sys/unpcb.h 1997/11/17 19:21:48 1.4 +++ sys/sys/unpcb.h 2000/07/29 23:54:19 @@ -61,6 +61,10 @@ * so that changes in the sockbuf may be computed to modify * back pressure on the sender accordingly. */ +struct unpcbid { + uid_t unp_euid; + gid_t unp_egid; +}; struct unpcb { struct socket *unp_socket; /* pointer back to socket */ struct vnode *unp_vnode; /* if associated with file */ @@ -69,6 +73,8 @@ struct unpcb *unp_refs; /* referencing socket linked list */ struct unpcb *unp_nextref; /* link in unp_refs list */ struct mbuf *unp_addr; /* bound address of socket */ + int unp_eids; /* this unpcb contains peer eids */ + struct unpcbid unp_connid; /* id of peer process */ int unp_cc; /* copy of rcv.sb_cc */ int unp_mbcnt; /* copy of rcv.sb_mbcnt */ struct timespec unp_ctime; /* holds creation time */ Index: sys/kern/syscalls.master =================================================================== RCS file: /cvs/src/sys/kern/syscalls.master,v retrieving revision 1.37 diff -u -r1.37 syscalls.master --- sys/kern/syscalls.master 1999/06/07 07:17:42 1.37 +++ sys/kern/syscalls.master 2000/07/29 23:54:25 @@ -520,3 +520,5 @@ struct statfs *buf); } 262 STD { int sys_fstatfs(int fd, struct statfs *buf); } 263 STD { int sys_pipe(int *fdp); } +264 STD { int sys_getpeereid(int fdes, uid_t *euid, gid_t *egid); } + Index: sys/kern/uipc_syscalls.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.28 diff -u -r1.28 uipc_syscalls.c --- sys/kern/uipc_syscalls.c 1999/07/13 15:17:51 1.28 +++ sys/kern/uipc_syscalls.c 2000/07/29 23:54:40 @@ -48,6 +48,7 @@ #include #include #include +#include #include #ifdef KTRACE #include @@ -995,6 +996,52 @@ if (error == 0) error = copyout((caddr_t)&len, (caddr_t)SCARG(uap, alen), sizeof (len)); +bad: + m_freem(m); + return (error); +} + +/* + * Get eid of peer for connected socket. + */ +/* ARGSUSED */ +int +sys_getpeereid(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct sys_getpeereid_args /* { + syscallarg(int) fdes; + syscallarg(uid_t *) euid; + syscallarg(gid_t *) egid; + } */ *uap = v; + struct file *fp; + register struct socket *so; + struct mbuf *m; + struct unpcbid *id; + int error; + + if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0) + return (error); + so = (struct socket *)fp->f_data; + if (so->so_proto != pffindtype(AF_LOCAL,SOCK_STREAM)) + return (EOPNOTSUPP); + m = m_getclr(M_WAIT, MT_SONAME); + if (m == NULL) + return (ENOBUFS); + error = (*so->so_proto->pr_usrreq)(so, PRU_PEEREID, 0, m, 0); + if ((!error) && (m->m_len != sizeof(struct unpcbid))) + error = EOPNOTSUPP; + if (error) + goto bad; + id = mtod(m, struct unpcbid *); + error = copyout((caddr_t) &(id->unp_euid), + (caddr_t)SCARG(uap, euid), sizeof(uid_t)); + if (error) + goto bad; + error = copyout((caddr_t) &(id->unp_egid), + (caddr_t)SCARG(uap, egid), sizeof(gid_t)); bad: m_freem(m); return (error); Index: sys/kern/uipc_usrreq.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v retrieving revision 1.11 diff -u -r1.11 uipc_usrreq.c --- sys/kern/uipc_usrreq.c 1999/10/11 19:49:39 1.11 +++ sys/kern/uipc_usrreq.c 2000/07/29 23:54:47 @@ -290,6 +290,15 @@ nam->m_len = 0; break; + case PRU_PEEREID: + if (unp->unp_eids) { + nam->m_len = sizeof(struct unpcbid); + bcopy((caddr_t)(&(unp->unp_connid)), + mtod(nam, caddr_t), (unsigned)nam->m_len); + } else + nam->m_len = 0; + break; + case PRU_SLOWTIMO: break; @@ -486,6 +495,9 @@ if (unp2->unp_addr) unp3->unp_addr = m_copy(unp2->unp_addr, 0, (int)M_COPYALL); + unp3->unp_connid.unp_euid = p->p_ucred->cr_uid; + unp3->unp_connid.unp_egid = p->p_ucred->cr_gid; + unp3->unp_eids = 1; so2 = so3; } error = unp_connect2(so, so2); Index: lib/libc/sys/Makefile.inc =================================================================== RCS file: /cvs/src/lib/libc/sys/Makefile.inc,v retrieving revision 1.30 diff -u -r1.30 Makefile.inc --- lib/libc/sys/Makefile.inc 1999/06/07 07:17:56 1.30 +++ lib/libc/sys/Makefile.inc 2000/07/29 23:54:50 @@ -31,7 +31,8 @@ close.o connect.o dup.o dup2.o execve.o fchdir.o \ fchflags.o fchmod.o fchown.o fcntl.o flock.o fpathconf.o fstat.o \ fstatfs.o fsync.o futimes.o getdirentries.o getegid.o geteuid.o \ - getfh.o getfsstat.o getgid.o getgroups.o getitimer.o getpeername.o \ + getfh.o getfsstat.o getgid.o getgroups.o getitimer.o getpeereid.o \ + getpeername.o \ getpgid.o \ getpgrp.o getpid.o getppid.o getpriority.o getrlimit.o getrusage.o \ getsid.o \