HAMMER 60I/Many: Mirroring
[dragonfly.git] / sys / kern / sysv_ipc.c
blob9d14be79443ad24c18bf8809371b4d2694c75db2
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.8 2005/10/08 14:31:26 corecode Exp $ */
3 /* $NetBSD: sysv_ipc.c,v 1.7 1994/06/29 06:33:11 cgd Exp $ */
5 /*
6 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
7 * All rights reserved.
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.
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.
35 #include "opt_sysvipc.h"
37 #include <sys/param.h>
38 #include <sys/ipc.h>
39 #include <sys/proc.h>
40 #include <sys/ucred.h>
42 #if defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
45 * Check for ipc permission
48 int
49 ipcperm(struct proc *p, struct ipc_perm *perm, int mode)
51 struct ucred *cred = p->p_ucred;
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_cred(cred, 0) == 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;
65 if (mode & IPC_M)
66 return (0);
67 return ((mode & perm->mode) == mode ||
68 suser_cred(cred, 0) == 0 ? 0 : EACCES);
71 #endif /* defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) */
74 #if !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG)
76 #include <sys/proc.h>
77 #include <sys/sem.h>
78 #include <sys/shm.h>
79 #include <sys/syslog.h>
80 #include <sys/sysproto.h>
81 #include <sys/systm.h>
83 static void sysv_nosys (char *s);
85 static void
86 sysv_nosys(char *s)
88 struct thread *td = curthread;
89 struct proc *p = td->td_proc;
91 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
92 (p ? p->p_comm : td->td_comm),
93 (p ? p->p_pid : -1), s);
96 #if !defined(SYSVSEM)
99 * SYSVSEM stubs
103 semsys(struct semsys_args *uap)
105 sysv_nosys("SYSVSEM");
106 return nosys((struct nosys_args *)uap);
110 __semctl(struct __semctl_args *uap)
112 sysv_nosys("SYSVSEM");
113 return nosys((struct nosys_args *)uap);
117 semget(struct semget_args *uap)
119 sysv_nosys("SYSVSEM");
120 return nosys((struct nosys_args *)uap);
124 semop(struct semop_args *uap)
126 sysv_nosys("SYSVSEM");
127 return nosys((struct nosys_args *)uap);
130 /* called from kern_exit.c */
131 void
132 semexit(struct proc *p)
134 /* empty */
137 #endif /* !defined(SYSVSEM) */
140 #if !defined(SYSVMSG)
143 * SYSVMSG stubs
145 * note: msgsys args actually var-args? YYYY
149 msgsys(struct msgsys_args *uap)
151 sysv_nosys("SYSVMSG");
152 return nosys((struct nosys_args *)uap);
156 msgctl(struct msgctl_args *uap)
158 sysv_nosys("SYSVMSG");
159 return nosys((struct nosys_args *)uap);
163 msgget(struct msgget_args *uap)
165 sysv_nosys("SYSVMSG");
166 return nosys((struct nosys_args *)uap);
170 msgsnd(struct msgsnd_args *uap)
172 sysv_nosys("SYSVMSG");
173 return nosys((struct nosys_args *)uap);
177 msgrcv(struct msgrcv_args *uap)
179 sysv_nosys("SYSVMSG");
180 return nosys((struct nosys_args *)uap);
183 #endif /* !defined(SYSVMSG) */
186 #if !defined(SYSVSHM)
189 * SYSVSHM stubs
193 shmdt(struct shmdt_args *uap)
195 sysv_nosys("SYSVSHM");
196 return nosys((struct nosys_args *)uap);
200 shmat(struct shmat_args *uap)
202 sysv_nosys("SYSVSHM");
203 return nosys((struct nosys_args *)uap);
207 shmctl(struct shmctl_args *uap)
209 sysv_nosys("SYSVSHM");
210 return nosys((struct nosys_args *)uap);
214 shmget(struct shmget_args *uap)
216 sysv_nosys("SYSVSHM");
217 return nosys((struct nosys_args *)uap);
220 /* XXX actually varargs. */
222 shmsys(struct shmsys_args *uap)
224 sysv_nosys("SYSVSHM");
225 return nosys((struct nosys_args *)uap);
228 /* called from kern_fork.c */
229 void
230 shmfork(struct proc *p1, struct proc *p2)
232 /* empty */
235 /* called from kern_exit.c */
236 void
237 shmexit(struct vmspace *vm)
239 /* empty */
242 #endif /* !defined(SYSVSHM) */
244 #endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */