Merge branch 'vendor/OPENSSL'
[dragonfly.git] / sys / kern / sysv_ipc.c
blob203d0823dd8a3312be74cf1af230672002caba09
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/priv.h>
41 #include <sys/ucred.h>
43 #define SYSCALL_NOT_PRESENT_GEN(SC, str) \
44 int sys_##SC (struct SC##_args *uap) \
45 { \
46 sysv_nosys(str); \
47 return sys_nosys((struct nosys_args *)uap); \
50 #if defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
53 * Check for ipc permission
56 int
57 ipcperm(struct proc *p, struct ipc_perm *perm, int mode)
59 struct ucred *cred = p->p_ucred;
61 /* Check for user match. */
62 if (cred->cr_uid != perm->cuid && cred->cr_uid != perm->uid) {
63 if (mode & IPC_M)
64 return (priv_check_cred(cred, PRIV_ROOT, 0) == 0 ? 0 : EPERM);
65 /* Check for group match. */
66 mode >>= 3;
67 if (!groupmember(perm->gid, cred) &&
68 !groupmember(perm->cgid, cred))
69 /* Check for `other' match. */
70 mode >>= 3;
73 if (mode & IPC_M)
74 return (0);
75 return ((mode & perm->mode) == mode ||
76 priv_check_cred(cred, PRIV_ROOT, 0) == 0 ? 0 : EACCES);
79 #endif /* defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) */
82 #if !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG)
84 #include <sys/proc.h>
85 #include <sys/sem.h>
86 #include <sys/shm.h>
87 #include <sys/syslog.h>
88 #include <sys/sysproto.h>
89 #include <sys/systm.h>
91 static void sysv_nosys (char *s);
93 static void
94 sysv_nosys(char *s)
96 struct thread *td = curthread;
97 struct proc *p = td->td_proc;
99 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
100 (p ? p->p_comm : td->td_comm),
101 (p ? p->p_pid : -1), s);
104 #if !defined(SYSVSEM)
107 * SYSVSEM stubs
110 SYSCALL_NOT_PRESENT_GEN(semsys, "SYSVSEM");
111 SYSCALL_NOT_PRESENT_GEN(__semctl, "SYSVSEM");
112 SYSCALL_NOT_PRESENT_GEN(semget, "SYSVSEM");
113 SYSCALL_NOT_PRESENT_GEN(semop, "SYSVSEM");
115 /* called from kern_exit.c */
116 void
117 semexit(struct proc *p)
119 /* empty */
122 #endif /* !defined(SYSVSEM) */
125 #if !defined(SYSVMSG)
128 * SYSVMSG stubs
130 * note: msgsys args actually var-args? YYYY
133 SYSCALL_NOT_PRESENT_GEN(msgsys, "SYSVMSG");
134 SYSCALL_NOT_PRESENT_GEN(msgctl, "SYSVMSG");
135 SYSCALL_NOT_PRESENT_GEN(msgget, "SYSVMSG");
136 SYSCALL_NOT_PRESENT_GEN(msgsnd, "SYSVMSG");
137 SYSCALL_NOT_PRESENT_GEN(msgrcv, "SYSVMSG");
139 #endif /* !defined(SYSVMSG) */
142 #if !defined(SYSVSHM)
145 * SYSVSHM stubs
148 SYSCALL_NOT_PRESENT_GEN(shmdt, "SYSVSHM");
149 SYSCALL_NOT_PRESENT_GEN(shmat, "SYSVSHM");
150 SYSCALL_NOT_PRESENT_GEN(shmctl, "SYSVSHM");
151 SYSCALL_NOT_PRESENT_GEN(shmget, "SYSVSHM");
152 SYSCALL_NOT_PRESENT_GEN(shmsys, "SYSVSHM");
154 /* called from kern_fork.c */
155 void
156 shmfork(struct proc *p1, struct proc *p2)
158 /* empty */
161 /* called from kern_exit.c */
162 void
163 shmexit(struct vmspace *vm)
165 /* empty */
168 #endif /* !defined(SYSVSHM) */
170 #endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */