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