Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / kern / sysv_ipc.c
CommitLineData
984263bc
MD
1/* $FreeBSD: src/sys/kern/sysv_ipc.c,v 1.13.2.2 2000/07/01 14:33:49 bsd Exp $ */
2/* $NetBSD: sysv_ipc.c,v 1.7 1994/06/29 06:33:11 cgd Exp $ */
3
4/*
5 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Herb Peyerl.
19 * 4. The name of Herb Peyerl may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include "opt_sysvipc.h"
35
36#include <sys/param.h>
37#include <sys/ipc.h>
38#include <sys/proc.h>
39#include <sys/ucred.h>
40
41#if defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
42
43/*
44 * Check for ipc permission
45 */
46
47int
48ipcperm(p, perm, mode)
49 struct proc *p;
50 struct ipc_perm *perm;
51 int mode;
52{
53 struct ucred *cred = p->p_ucred;
54
55 /* Check for user match. */
56 if (cred->cr_uid != perm->cuid && cred->cr_uid != perm->uid) {
57 if (mode & IPC_M)
58 return (suser(p) == 0 ? 0 : EPERM);
59 /* Check for group match. */
60 mode >>= 3;
61 if (!groupmember(perm->gid, cred) &&
62 !groupmember(perm->cgid, cred))
63 /* Check for `other' match. */
64 mode >>= 3;
65 }
66
67 if (mode & IPC_M)
68 return (0);
69 return ((mode & perm->mode) == mode || suser(p) == 0 ? 0 : EACCES);
70}
71
72#endif /* defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) */
73
74
75#if !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG)
76
77#include <sys/proc.h>
78#include <sys/sem.h>
79#include <sys/shm.h>
80#include <sys/syslog.h>
81#include <sys/sysproto.h>
82#include <sys/systm.h>
83
84static void sysv_nosys __P((struct proc *p, char *s));
85
86static void
87sysv_nosys(p, s)
88 struct proc *p;
89 char *s;
90{
91 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
92 p->p_comm, p->p_pid, s);
93}
94
95#if !defined(SYSVSEM)
96
97/*
98 * SYSVSEM stubs
99 */
100
101int
102semsys(p, uap)
103 struct proc *p;
104 struct semsys_args *uap;
105{
106 sysv_nosys(p, "SYSVSEM");
107 return nosys(p, (struct nosys_args *)uap);
108};
109
110int
111__semctl(p, uap)
112 struct proc *p;
113 register struct __semctl_args *uap;
114{
115 sysv_nosys(p, "SYSVSEM");
116 return nosys(p, (struct nosys_args *)uap);
117};
118
119int
120semget(p, uap)
121 struct proc *p;
122 register struct semget_args *uap;
123{
124 sysv_nosys(p, "SYSVSEM");
125 return nosys(p, (struct nosys_args *)uap);
126};
127
128int
129semop(p, uap)
130 struct proc *p;
131 register struct semop_args *uap;
132{
133 sysv_nosys(p, "SYSVSEM");
134 return nosys(p, (struct nosys_args *)uap);
135};
136
137/* called from kern_exit.c */
138void
139semexit(p)
140 struct proc *p;
141{
142 return;
143}
144
145#endif /* !defined(SYSVSEM) */
146
147
148#if !defined(SYSVMSG)
149
150/*
151 * SYSVMSG stubs
152 */
153
154int
155msgsys(p, uap)
156 struct proc *p;
157 /* XXX actually varargs. */
158 struct msgsys_args *uap;
159{
160 sysv_nosys(p, "SYSVMSG");
161 return nosys(p, (struct nosys_args *)uap);
162};
163
164int
165msgctl(p, uap)
166 struct proc *p;
167 register struct msgctl_args *uap;
168{
169 sysv_nosys(p, "SYSVMSG");
170 return nosys(p, (struct nosys_args *)uap);
171};
172
173int
174msgget(p, uap)
175 struct proc *p;
176 register struct msgget_args *uap;
177{
178 sysv_nosys(p, "SYSVMSG");
179 return nosys(p, (struct nosys_args *)uap);
180};
181
182int
183msgsnd(p, uap)
184 struct proc *p;
185 register struct msgsnd_args *uap;
186{
187 sysv_nosys(p, "SYSVMSG");
188 return nosys(p, (struct nosys_args *)uap);
189};
190
191int
192msgrcv(p, uap)
193 struct proc *p;
194 register struct msgrcv_args *uap;
195{
196 sysv_nosys(p, "SYSVMSG");
197 return nosys(p, (struct nosys_args *)uap);
198};
199
200#endif /* !defined(SYSVMSG) */
201
202
203#if !defined(SYSVSHM)
204
205/*
206 * SYSVSHM stubs
207 */
208
209int
210shmdt(p, uap)
211 struct proc *p;
212 struct shmdt_args *uap;
213{
214 sysv_nosys(p, "SYSVSHM");
215 return nosys(p, (struct nosys_args *)uap);
216};
217
218int
219shmat(p, uap)
220 struct proc *p;
221 struct shmat_args *uap;
222{
223 sysv_nosys(p, "SYSVSHM");
224 return nosys(p, (struct nosys_args *)uap);
225};
226
227int
228shmctl(p, uap)
229 struct proc *p;
230 struct shmctl_args *uap;
231{
232 sysv_nosys(p, "SYSVSHM");
233 return nosys(p, (struct nosys_args *)uap);
234};
235
236int
237shmget(p, uap)
238 struct proc *p;
239 struct shmget_args *uap;
240{
241 sysv_nosys(p, "SYSVSHM");
242 return nosys(p, (struct nosys_args *)uap);
243};
244
245int
246shmsys(p, uap)
247 struct proc *p;
248 /* XXX actually varargs. */
249 struct shmsys_args *uap;
250{
251 sysv_nosys(p, "SYSVSHM");
252 return nosys(p, (struct nosys_args *)uap);
253};
254
255/* called from kern_fork.c */
256void
257shmfork(p1, p2)
258 struct proc *p1, *p2;
259{
260 return;
261}
262
263/* called from kern_exit.c */
264void
265shmexit(p)
266 struct proc *p;
267{
268 return;
269}
270
271#endif /* !defined(SYSVSHM) */
272
273#endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */