proc->thread stage 2: MAJOR revamping of system calls, ucred, jail API,
[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.3 2003/06/23 17:55:41 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() == 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 || suser() == 0 ? 0 : EACCES);
68 }
69
70 #endif /* defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) */
71
72
73 #if !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG)
74
75 #include <sys/proc.h>
76 #include <sys/sem.h>
77 #include <sys/shm.h>
78 #include <sys/syslog.h>
79 #include <sys/sysproto.h>
80 #include <sys/systm.h>
81
82 static void sysv_nosys __P((struct proc *p, char *s));
83
84 static void 
85 sysv_nosys(p, s)
86         struct proc *p;
87         char *s;
88 {
89         log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
90                         p->p_comm, p->p_pid, s);
91 }
92
93 #if !defined(SYSVSEM)
94
95 /*
96  * SYSVSEM stubs
97  */
98
99 int
100 semsys(p, uap)
101         struct proc *p;
102         struct semsys_args *uap;
103 {
104         sysv_nosys(p, "SYSVSEM");
105         return nosys(p, (struct nosys_args *)uap);
106 };
107
108 int
109 __semctl(p, uap)
110         struct proc *p;
111         register struct __semctl_args *uap;
112 {
113         sysv_nosys(p, "SYSVSEM");
114         return nosys(p, (struct nosys_args *)uap);
115 };
116
117 int
118 semget(p, uap)
119         struct proc *p;
120         register struct semget_args *uap;
121 {
122         sysv_nosys(p, "SYSVSEM");
123         return nosys(p, (struct nosys_args *)uap);
124 };
125
126 int
127 semop(p, uap)
128         struct proc *p;
129         register struct semop_args *uap;
130 {
131         sysv_nosys(p, "SYSVSEM");
132         return nosys(p, (struct nosys_args *)uap);
133 };
134
135 /* called from kern_exit.c */
136 void
137 semexit(p)
138         struct proc *p;
139 {
140         return;
141 }
142
143 #endif /* !defined(SYSVSEM) */
144
145
146 #if !defined(SYSVMSG)
147
148 /*
149  * SYSVMSG stubs
150  */
151
152 int
153 msgsys(p, uap)
154         struct proc *p;
155         /* XXX actually varargs. */
156         struct msgsys_args *uap;
157 {
158         sysv_nosys(p, "SYSVMSG");
159         return nosys(p, (struct nosys_args *)uap);
160 };
161
162 int
163 msgctl(p, uap)
164         struct proc *p;
165         register struct msgctl_args *uap;
166 {
167         sysv_nosys(p, "SYSVMSG");
168         return nosys(p, (struct nosys_args *)uap);
169 };
170
171 int
172 msgget(p, uap)
173         struct proc *p;
174         register struct msgget_args *uap;
175 {
176         sysv_nosys(p, "SYSVMSG");
177         return nosys(p, (struct nosys_args *)uap);
178 };
179
180 int
181 msgsnd(p, uap)
182         struct proc *p;
183         register struct msgsnd_args *uap;
184 {
185         sysv_nosys(p, "SYSVMSG");
186         return nosys(p, (struct nosys_args *)uap);
187 };
188
189 int
190 msgrcv(p, uap)
191         struct proc *p;
192         register struct msgrcv_args *uap;
193 {
194         sysv_nosys(p, "SYSVMSG");
195         return nosys(p, (struct nosys_args *)uap);
196 };
197
198 #endif /* !defined(SYSVMSG) */
199
200
201 #if !defined(SYSVSHM)
202
203 /*
204  * SYSVSHM stubs
205  */
206
207 int
208 shmdt(p, uap)
209         struct proc *p;
210         struct shmdt_args *uap;
211 {
212         sysv_nosys(p, "SYSVSHM");
213         return nosys(p, (struct nosys_args *)uap);
214 };
215
216 int
217 shmat(p, uap)
218         struct proc *p;
219         struct shmat_args *uap;
220 {
221         sysv_nosys(p, "SYSVSHM");
222         return nosys(p, (struct nosys_args *)uap);
223 };
224
225 int
226 shmctl(p, uap)
227         struct proc *p;
228         struct shmctl_args *uap;
229 {
230         sysv_nosys(p, "SYSVSHM");
231         return nosys(p, (struct nosys_args *)uap);
232 };
233
234 int
235 shmget(p, uap)
236         struct proc *p;
237         struct shmget_args *uap;
238 {
239         sysv_nosys(p, "SYSVSHM");
240         return nosys(p, (struct nosys_args *)uap);
241 };
242
243 int
244 shmsys(p, uap)
245         struct proc *p;
246         /* XXX actually varargs. */
247         struct shmsys_args *uap;
248 {
249         sysv_nosys(p, "SYSVSHM");
250         return nosys(p, (struct nosys_args *)uap);
251 };
252
253 /* called from kern_fork.c */
254 void
255 shmfork(p1, p2)
256         struct proc *p1, *p2;
257 {
258         return;
259 }
260
261 /* called from kern_exit.c */
262 void
263 shmexit(p)
264         struct proc *p;
265 {
266         return;
267 }
268
269 #endif /* !defined(SYSVSHM) */
270
271 #endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */