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