FreeBSD/Linux Kernel Cross Reference
sys/kern/sysv_ipc.c
1 /* $FreeBSD: src/sys/kern/sysv_ipc.c,v 1.4.4.2 2000/05/01 11:29:43 peter 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/kernel.h>
38 #include <sys/proc.h>
39 #include <sys/systm.h>
40 #include <sys/syslog.h>
41 #include <sys/sysproto.h>
42 #include <sys/ipc.h>
43 #include <sys/shm.h>
44 #include <sys/sem.h>
45
46 #if defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
47
48 /*
49 * Check for ipc permission
50 */
51
52 int
53 ipcperm(cred, perm, mode)
54 struct ucred *cred;
55 struct ipc_perm *perm;
56 int mode;
57 {
58
59 if (cred->cr_uid == 0)
60 return (0);
61
62 /* Check for user match. */
63 if (cred->cr_uid != perm->cuid && cred->cr_uid != perm->uid) {
64 if (mode & IPC_M)
65 return (EPERM);
66 /* Check for group match. */
67 mode >>= 3;
68 if (!groupmember(perm->gid, cred) &&
69 !groupmember(perm->cgid, cred))
70 /* Check for `other' match. */
71 mode >>= 3;
72 }
73
74 if (mode & IPC_M)
75 return (0);
76 return ((mode & perm->mode) == mode ? 0 : EACCES);
77 }
78
79 #endif /* defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) */
80
81
82 #if !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG)
83
84 static void sysv_nosys __P((struct proc *p, char *s));
85
86 static void
87 sysv_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
101 int
102 semsys(p, uap, retval)
103 struct proc *p;
104 struct semsys_args *uap;
105 int *retval;
106 {
107 sysv_nosys(p, "SYSVSEM");
108 return nosys(p, (struct nosys_args *)uap, retval);
109 };
110
111 int
112 __semctl(p, uap, retval)
113 struct proc *p;
114 register struct __semctl_args *uap;
115 int *retval;
116 {
117 sysv_nosys(p, "SYSVSEM");
118 return nosys(p, (struct nosys_args *)uap, retval);
119 };
120
121 int
122 semget(p, uap, retval)
123 struct proc *p;
124 register struct semget_args *uap;
125 int *retval;
126 {
127 sysv_nosys(p, "SYSVSEM");
128 return nosys(p, (struct nosys_args *)uap, retval);
129 };
130
131 int
132 semop(p, uap, retval)
133 struct proc *p;
134 register struct semop_args *uap;
135 int *retval;
136 {
137 sysv_nosys(p, "SYSVSEM");
138 return nosys(p, (struct nosys_args *)uap, retval);
139 };
140
141 /* called from kern_exit.c */
142 void
143 semexit(p)
144 struct proc *p;
145 {
146 return;
147 }
148
149 #endif /* !defined(SYSVSEM) */
150
151
152 #if !defined(SYSVMSG)
153
154 /*
155 * SYSVMSG stubs
156 */
157
158 int
159 msgsys(p, uap, retval)
160 struct proc *p;
161 /* XXX actually varargs. */
162 struct msgsys_args *uap;
163 int *retval;
164 {
165 sysv_nosys(p, "SYSVMSG");
166 return nosys(p, (struct nosys_args *)uap, retval);
167 };
168
169 int
170 msgctl(p, uap, retval)
171 struct proc *p;
172 register struct msgctl_args *uap;
173 int *retval;
174 {
175 sysv_nosys(p, "SYSVMSG");
176 return nosys(p, (struct nosys_args *)uap, retval);
177 };
178
179 int
180 msgget(p, uap, retval)
181 struct proc *p;
182 register struct msgget_args *uap;
183 int *retval;
184 {
185 sysv_nosys(p, "SYSVMSG");
186 return nosys(p, (struct nosys_args *)uap, retval);
187 };
188
189 int
190 msgsnd(p, uap, retval)
191 struct proc *p;
192 register struct msgsnd_args *uap;
193 int *retval;
194 {
195 sysv_nosys(p, "SYSVMSG");
196 return nosys(p, (struct nosys_args *)uap, retval);
197 };
198
199 int
200 msgrcv(p, uap, retval)
201 struct proc *p;
202 register struct msgrcv_args *uap;
203 int *retval;
204 {
205 sysv_nosys(p, "SYSVMSG");
206 return nosys(p, (struct nosys_args *)uap, retval);
207 };
208
209 #endif /* !defined(SYSVMSG) */
210
211
212 #if !defined(SYSVSHM)
213
214 /*
215 * SYSVSHM stubs
216 */
217
218 int
219 shmdt(p, uap, retval)
220 struct proc *p;
221 struct shmdt_args *uap;
222 int *retval;
223 {
224 sysv_nosys(p, "SYSVSHM");
225 return nosys(p, (struct nosys_args *)uap, retval);
226 };
227
228 int
229 shmat(p, uap, retval)
230 struct proc *p;
231 struct shmat_args *uap;
232 int *retval;
233 {
234 sysv_nosys(p, "SYSVSHM");
235 return nosys(p, (struct nosys_args *)uap, retval);
236 };
237
238 int
239 shmctl(p, uap, retval)
240 struct proc *p;
241 struct shmctl_args *uap;
242 int *retval;
243 {
244 sysv_nosys(p, "SYSVSHM");
245 return nosys(p, (struct nosys_args *)uap, retval);
246 };
247
248 int
249 shmget(p, uap, retval)
250 struct proc *p;
251 struct shmget_args *uap;
252 int *retval;
253 {
254 sysv_nosys(p, "SYSVSHM");
255 return nosys(p, (struct nosys_args *)uap, retval);
256 };
257
258 int
259 shmsys(p, uap, retval)
260 struct proc *p;
261 /* XXX actually varargs. */
262 struct shmsys_args *uap;
263 int *retval;
264 {
265 sysv_nosys(p, "SYSVSHM");
266 return nosys(p, (struct nosys_args *)uap, retval);
267 };
268
269 /* called from kern_fork.c */
270 void
271 shmfork(p1, p2)
272 struct proc *p1, *p2;
273 {
274 return;
275 }
276
277 /* called from kern_exit.c */
278 void
279 shmexit(p)
280 struct proc *p;
281 {
282 return;
283 }
284
285 #endif /* !defined(SYSVSHM) */
286
287 #endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */
Cache object: 4fe6063bc07326c17a5d696f97f6af0f
|