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