diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-11-17 08:33:21 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-11-17 08:33:21 +0000 |
commit | 86e9e858ee299c3a1ddf26cc4b04b096b64c5bfa (patch) | |
tree | b79725acf621c42fff22206d783817419e99b52c | |
parent | 89beaef16d80be10b5ffa2940429c90b015c4d82 (diff) |
Make getpeereid() work on both sides of a connection. The client can now get
the euid/egid of the server it connects to. The euid and egid are captured in
the bind() call -- this is the equivalent of the client behaviour where the
same thing is done in connect().
tested and ok espie@, ok henning@, go for it deraadt@
-rw-r--r-- | sys/kern/uipc_usrreq.c | 13 | ||||
-rw-r--r-- | sys/sys/unpcb.h | 3 |
2 files changed, 13 insertions, 3 deletions
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 06dca0d58f1..0cca9aeb9d3 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.32 2006/10/31 16:24:55 markus Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.33 2006/11/17 08:33:20 claudio Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -434,6 +434,9 @@ unp_bind(struct unpcb *unp, struct mbuf *nam, struct proc *p) vp->v_socket = unp->unp_socket; unp->unp_vnode = vp; unp->unp_addr = m_copy(nam, 0, (int)M_COPYALL); + unp->unp_connid.unp_euid = p->p_ucred->cr_uid; + unp->unp_connid.unp_egid = p->p_ucred->cr_gid; + unp->unp_flags |= UNP_FEIDSBIND; VOP_UNLOCK(vp, 0, p); return (0); } @@ -444,7 +447,7 @@ unp_connect(struct socket *so, struct mbuf *nam, struct proc *p) struct sockaddr_un *soun = mtod(nam, struct sockaddr_un *); struct vnode *vp; struct socket *so2, *so3; - struct unpcb *unp2, *unp3; + struct unpcb *unp, *unp2, *unp3; int error; struct nameidata nd; @@ -478,6 +481,7 @@ unp_connect(struct socket *so, struct mbuf *nam, struct proc *p) error = ECONNREFUSED; goto bad; } + unp = sotounpcb(so); unp2 = sotounpcb(so2); unp3 = sotounpcb(so3); if (unp2->unp_addr) @@ -487,6 +491,11 @@ unp_connect(struct socket *so, struct mbuf *nam, struct proc *p) unp3->unp_connid.unp_egid = p->p_ucred->cr_gid; unp3->unp_flags |= UNP_FEIDS; so2 = so3; + if (unp2->unp_flags & UNP_FEIDSBIND) { + unp->unp_connid.unp_euid = unp2->unp_connid.unp_euid; + unp->unp_connid.unp_egid = unp2->unp_connid.unp_egid; + unp->unp_flags |= UNP_FEIDS; + } } error = unp_connect2(so, so2); bad: diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index 5ac2185ae0c..9dc004a1c66 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.6 2003/06/02 23:28:22 millert Exp $ */ +/* $OpenBSD: unpcb.h,v 1.7 2006/11/17 08:33:20 claudio Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -81,5 +81,6 @@ struct unpcb { * flag bits in unp_flags */ #define UNP_FEIDS 1 /* unp_connid contains information */ +#define UNP_FEIDSBIND 2 /* unp_connid was set by a bind */ #define sotounpcb(so) ((struct unpcb *)((so)->so_pcb)) |