sysv_ipc.c revision 1.15 1 1.15 lukem /* $NetBSD: sysv_ipc.c,v 1.15 2001/11/12 15:25:25 lukem Exp $ */
2 1.7 cgd
3 1.13 mycroft /*-
4 1.13 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.13 mycroft * All rights reserved.
6 1.13 mycroft *
7 1.13 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.13 mycroft * by Charles M. Hannum.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.6 hpeyerl * 2. Redistributions in binary form must reproduce the above copyright
16 1.6 hpeyerl * notice, this list of conditions and the following disclaimer in the
17 1.6 hpeyerl * documentation and/or other materials provided with the distribution.
18 1.6 hpeyerl * 3. All advertising materials mentioning features or use of this software
19 1.6 hpeyerl * must display the following acknowledgement:
20 1.14 christos * This product includes software developed by the NetBSD
21 1.14 christos * Foundation, Inc. and its contributors.
22 1.13 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.13 mycroft * contributors may be used to endorse or promote products derived
24 1.13 mycroft * from this software without specific prior written permission.
25 1.1 cgd *
26 1.13 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.13 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.13 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.13 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.13 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.13 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.13 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.13 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.13 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.13 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.13 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 cgd */
38 1.15 lukem
39 1.15 lukem #include <sys/cdefs.h>
40 1.15 lukem __KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.15 2001/11/12 15:25:25 lukem Exp $");
41 1.1 cgd
42 1.2 mycroft #include <sys/param.h>
43 1.2 mycroft #include <sys/kernel.h>
44 1.2 mycroft #include <sys/proc.h>
45 1.2 mycroft #include <sys/ipc.h>
46 1.4 hpeyerl #include <sys/systm.h>
47 1.10 mycroft #include <sys/mount.h>
48 1.10 mycroft #include <sys/vnode.h>
49 1.12 mycroft #include <sys/stat.h>
50 1.1 cgd
51 1.1 cgd /*
52 1.4 hpeyerl * Check for ipc permission
53 1.1 cgd */
54 1.1 cgd
55 1.4 hpeyerl int
56 1.5 mycroft ipcperm(cred, perm, mode)
57 1.5 mycroft struct ucred *cred;
58 1.4 hpeyerl struct ipc_perm *perm;
59 1.1 cgd int mode;
60 1.1 cgd {
61 1.12 mycroft mode_t mask;
62 1.12 mycroft
63 1.12 mycroft if (cred->cr_uid == 0)
64 1.12 mycroft return (0);
65 1.1 cgd
66 1.9 mycroft if (mode == IPC_M) {
67 1.12 mycroft if (cred->cr_uid == perm->uid ||
68 1.9 mycroft cred->cr_uid == perm->cuid)
69 1.9 mycroft return (0);
70 1.9 mycroft return (EPERM);
71 1.1 cgd }
72 1.4 hpeyerl
73 1.12 mycroft mask = 0;
74 1.12 mycroft
75 1.12 mycroft if (cred->cr_uid == perm->uid ||
76 1.12 mycroft cred->cr_uid == perm->cuid) {
77 1.12 mycroft if (mode & IPC_R)
78 1.12 mycroft mask |= S_IRUSR;
79 1.12 mycroft if (mode & IPC_W)
80 1.12 mycroft mask |= S_IWUSR;
81 1.12 mycroft return ((perm->mode & mask) == mask ? 0 : EACCES);
82 1.12 mycroft }
83 1.12 mycroft
84 1.12 mycroft if (cred->cr_gid == perm->gid || groupmember(perm->gid, cred) ||
85 1.12 mycroft cred->cr_gid == perm->cgid || groupmember(perm->cgid, cred)) {
86 1.12 mycroft if (mode & IPC_R)
87 1.12 mycroft mask |= S_IRGRP;
88 1.12 mycroft if (mode & IPC_W)
89 1.12 mycroft mask |= S_IWGRP;
90 1.12 mycroft return ((perm->mode & mask) == mask ? 0 : EACCES);
91 1.12 mycroft }
92 1.12 mycroft
93 1.12 mycroft if (mode & IPC_R)
94 1.12 mycroft mask |= S_IROTH;
95 1.12 mycroft if (mode & IPC_W)
96 1.12 mycroft mask |= S_IWOTH;
97 1.12 mycroft return ((perm->mode & mask) == mask ? 0 : EACCES);
98 1.1 cgd }
99