Allow kernel to be compile without SYSV[SHM|MSG|SEM]
[dragonfly.git] / sys / kern / sysv_ipc.c
CommitLineData
984263bc 1/* $FreeBSD: src/sys/kern/sysv_ipc.c,v 1.13.2.2 2000/07/01 14:33:49 bsd Exp $ */
2966ed3e 2/* $DragonFly: src/sys/kern/sysv_ipc.c,v 1.8 2005/10/08 14:31:26 corecode Exp $ */
984263bc
MD
3/* $NetBSD: sysv_ipc.c,v 1.7 1994/06/29 06:33:11 cgd Exp $ */
4
5/*
6 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
7 * All rights reserved.
8 *
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.
22 *
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.
33 */
34
35#include "opt_sysvipc.h"
36
37#include <sys/param.h>
38#include <sys/ipc.h>
39#include <sys/proc.h>
895c1f85 40#include <sys/priv.h>
984263bc
MD
41#include <sys/ucred.h>
42
cd10cbaf
SG
43#define SYSCALL_NOT_PRESENT_GEN(SC, str) \
44int sys_##SC (struct SC##_args *uap) \
45{ \
46 sysv_nosys(str); \
47 return sys_nosys((struct nosys_args *)uap); \
48}
49
984263bc
MD
50#if defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
51
52/*
53 * Check for ipc permission
54 */
55
56int
41c20dac 57ipcperm(struct proc *p, struct ipc_perm *perm, int mode)
984263bc
MD
58{
59 struct ucred *cred = p->p_ucred;
60
61 /* Check for user match. */
62 if (cred->cr_uid != perm->cuid && cred->cr_uid != perm->uid) {
63 if (mode & IPC_M)
895c1f85 64 return (priv_check_cred(cred, PRIV_ROOT, 0) == 0 ? 0 : EPERM);
984263bc
MD
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;
71 }
72
73 if (mode & IPC_M)
74 return (0);
dadab5e9 75 return ((mode & perm->mode) == mode ||
895c1f85 76 priv_check_cred(cred, PRIV_ROOT, 0) == 0 ? 0 : EACCES);
984263bc
MD
77}
78
79#endif /* defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) */
80
81
82#if !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG)
83
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>
90
402ed7e1 91static void sysv_nosys (char *s);
984263bc
MD
92
93static void
8976dead 94sysv_nosys(char *s)
984263bc 95{
8976dead
MD
96 struct thread *td = curthread;
97 struct proc *p = td->td_proc;
98
984263bc 99 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n",
2966ed3e
SS
100 (p ? p->p_comm : td->td_comm),
101 (p ? p->p_pid : -1), s);
984263bc
MD
102}
103
104#if !defined(SYSVSEM)
105
106/*
107 * SYSVSEM stubs
108 */
109
cd10cbaf
SG
110SYSCALL_NOT_PRESENT_GEN(semsys, "SYSVSEM");
111SYSCALL_NOT_PRESENT_GEN(__semctl, "SYSVSEM");
112SYSCALL_NOT_PRESENT_GEN(semget, "SYSVSEM");
113SYSCALL_NOT_PRESENT_GEN(semop, "SYSVSEM");
984263bc
MD
114
115/* called from kern_exit.c */
116void
8976dead 117semexit(struct proc *p)
984263bc 118{
8976dead 119 /* empty */
984263bc
MD
120}
121
122#endif /* !defined(SYSVSEM) */
123
124
125#if !defined(SYSVMSG)
126
127/*
128 * SYSVMSG stubs
8976dead
MD
129 *
130 * note: msgsys args actually var-args? YYYY
984263bc
MD
131 */
132
cd10cbaf
SG
133SYSCALL_NOT_PRESENT_GEN(msgsys, "SYSVMSG");
134SYSCALL_NOT_PRESENT_GEN(msgctl, "SYSVMSG");
135SYSCALL_NOT_PRESENT_GEN(msgget, "SYSVMSG");
136SYSCALL_NOT_PRESENT_GEN(msgsnd, "SYSVMSG");
137SYSCALL_NOT_PRESENT_GEN(msgrcv, "SYSVMSG");
984263bc
MD
138
139#endif /* !defined(SYSVMSG) */
140
141
142#if !defined(SYSVSHM)
143
144/*
145 * SYSVSHM stubs
146 */
147
cd10cbaf
SG
148SYSCALL_NOT_PRESENT_GEN(shmdt, "SYSVSHM");
149SYSCALL_NOT_PRESENT_GEN(shmat, "SYSVSHM");
150SYSCALL_NOT_PRESENT_GEN(shmctl, "SYSVSHM");
151SYSCALL_NOT_PRESENT_GEN(shmget, "SYSVSHM");
152SYSCALL_NOT_PRESENT_GEN(shmsys, "SYSVSHM");
984263bc
MD
153
154/* called from kern_fork.c */
155void
8976dead 156shmfork(struct proc *p1, struct proc *p2)
984263bc 157{
8976dead 158 /* empty */
984263bc
MD
159}
160
161/* called from kern_exit.c */
162void
fef0fdf2 163shmexit(struct vmspace *vm)
984263bc 164{
8976dead 165 /* empty */
984263bc
MD
166}
167
168#endif /* !defined(SYSVSHM) */
169
170#endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */