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