1*21dab745Sjsg /* $OpenBSD: sysv_ipc.c,v 1.8 2015/03/14 03:38:50 jsg Exp $ */
2df930be7Sderaadt /* $NetBSD: sysv_ipc.c,v 1.10 1995/06/03 05:53:28 mycroft Exp $ */
3df930be7Sderaadt
4df930be7Sderaadt /*
5df930be7Sderaadt * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
6df930be7Sderaadt *
7df930be7Sderaadt * Redistribution and use in source and binary forms, with or without
8df930be7Sderaadt * modification, are permitted provided that the following conditions
9df930be7Sderaadt * are met:
10df930be7Sderaadt * 1. Redistributions of source code must retain the above copyright
11df930be7Sderaadt * notice, this list of conditions and the following disclaimer.
12df930be7Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
13df930be7Sderaadt * notice, this list of conditions and the following disclaimer in the
14df930be7Sderaadt * documentation and/or other materials provided with the distribution.
15df930be7Sderaadt * 3. All advertising materials mentioning features or use of this software
16df930be7Sderaadt * must display the following acknowledgement:
17df930be7Sderaadt * This product includes software developed by Charles M. Hannum.
18df930be7Sderaadt * 4. The name of the author may not be used to endorse or promote products
19df930be7Sderaadt * derived from this software without specific prior written permission.
20df930be7Sderaadt *
21df930be7Sderaadt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22df930be7Sderaadt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23df930be7Sderaadt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24df930be7Sderaadt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25df930be7Sderaadt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26df930be7Sderaadt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27df930be7Sderaadt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28df930be7Sderaadt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29df930be7Sderaadt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30df930be7Sderaadt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31df930be7Sderaadt */
32df930be7Sderaadt
33df930be7Sderaadt #include <sys/param.h>
34df930be7Sderaadt #include <sys/ipc.h>
35df930be7Sderaadt #include <sys/systm.h>
36df930be7Sderaadt #include <sys/mount.h>
37df930be7Sderaadt #include <sys/vnode.h>
38df930be7Sderaadt
39df930be7Sderaadt /*
40df930be7Sderaadt * Check for ipc permission
41df930be7Sderaadt */
42df930be7Sderaadt
43df930be7Sderaadt int
ipcperm(struct ucred * cred,struct ipc_perm * perm,int mode)44e1e39b7eSjsg ipcperm(struct ucred *cred, struct ipc_perm *perm, int mode)
45df930be7Sderaadt {
46df930be7Sderaadt
47df930be7Sderaadt if (mode == IPC_M) {
48df930be7Sderaadt if (cred->cr_uid == 0 ||
49df930be7Sderaadt cred->cr_uid == perm->uid ||
50df930be7Sderaadt cred->cr_uid == perm->cuid)
51df930be7Sderaadt return (0);
52df930be7Sderaadt return (EPERM);
53df930be7Sderaadt }
54df930be7Sderaadt
55141c07a8Smillert if (vaccess(VNON, perm->mode, perm->uid, perm->gid, mode, cred) == 0 ||
56141c07a8Smillert vaccess(VNON, perm->mode, perm->cuid, perm->cgid, mode, cred) == 0)
57df930be7Sderaadt return (0);
58df930be7Sderaadt return (EACCES);
59df930be7Sderaadt }
60