1 /* $FreeBSD$ */ 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/systm.h> 38 #include <sys/ipc.h> 39 #include <sys/proc.h> 40 #include <sys/ucred.h> 41 42 #if defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) 43 44 /* 45 * Check for ipc permission 46 */ 47 48 int 49 ipcperm(p, perm, mode) 50 struct proc *p; 51 struct ipc_perm *perm; 52 int mode; 53 { 54 struct ucred *cred = p->p_ucred; 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 (suser(p) == 0 ? 0 : 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 || suser(p) == 0 ? 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 __semctl(p, uap) 113 struct proc *p; 114 register struct __semctl_args *uap; 115 { 116 sysv_nosys(p, "SYSVSEM"); 117 return nosys(p, (struct nosys_args *)uap); 118 }; 119 120 int 121 semget(p, uap) 122 struct proc *p; 123 register struct semget_args *uap; 124 { 125 sysv_nosys(p, "SYSVSEM"); 126 return nosys(p, (struct nosys_args *)uap); 127 }; 128 129 int 130 semop(p, uap) 131 struct proc *p; 132 register struct semop_args *uap; 133 { 134 sysv_nosys(p, "SYSVSEM"); 135 return nosys(p, (struct nosys_args *)uap); 136 }; 137 138 /* called from kern_exit.c */ 139 void 140 semexit(p) 141 struct proc *p; 142 { 143 return; 144 } 145 146 #endif /* !defined(SYSVSEM) */ 147 148 149 #if !defined(SYSVMSG) 150 151 /* 152 * SYSVMSG stubs 153 */ 154 155 int 156 msgsys(p, uap) 157 struct proc *p; 158 /* XXX actually varargs. */ 159 struct msgsys_args *uap; 160 { 161 sysv_nosys(p, "SYSVMSG"); 162 return nosys(p, (struct nosys_args *)uap); 163 }; 164 165 int 166 msgctl(p, uap) 167 struct proc *p; 168 register struct msgctl_args *uap; 169 { 170 sysv_nosys(p, "SYSVMSG"); 171 return nosys(p, (struct nosys_args *)uap); 172 }; 173 174 int 175 msgget(p, uap) 176 struct proc *p; 177 register struct msgget_args *uap; 178 { 179 sysv_nosys(p, "SYSVMSG"); 180 return nosys(p, (struct nosys_args *)uap); 181 }; 182 183 int 184 msgsnd(p, uap) 185 struct proc *p; 186 register struct msgsnd_args *uap; 187 { 188 sysv_nosys(p, "SYSVMSG"); 189 return nosys(p, (struct nosys_args *)uap); 190 }; 191 192 int 193 msgrcv(p, uap) 194 struct proc *p; 195 register struct msgrcv_args *uap; 196 { 197 sysv_nosys(p, "SYSVMSG"); 198 return nosys(p, (struct nosys_args *)uap); 199 }; 200 201 #endif /* !defined(SYSVMSG) */ 202 203 204 #if !defined(SYSVSHM) 205 206 /* 207 * SYSVSHM stubs 208 */ 209 210 int 211 shmdt(p, uap) 212 struct proc *p; 213 struct shmdt_args *uap; 214 { 215 sysv_nosys(p, "SYSVSHM"); 216 return nosys(p, (struct nosys_args *)uap); 217 }; 218 219 int 220 shmat(p, uap) 221 struct proc *p; 222 struct shmat_args *uap; 223 { 224 sysv_nosys(p, "SYSVSHM"); 225 return nosys(p, (struct nosys_args *)uap); 226 }; 227 228 int 229 shmctl(p, uap) 230 struct proc *p; 231 struct shmctl_args *uap; 232 { 233 sysv_nosys(p, "SYSVSHM"); 234 return nosys(p, (struct nosys_args *)uap); 235 }; 236 237 int 238 shmget(p, uap) 239 struct proc *p; 240 struct shmget_args *uap; 241 { 242 sysv_nosys(p, "SYSVSHM"); 243 return nosys(p, (struct nosys_args *)uap); 244 }; 245 246 int 247 shmsys(p, uap) 248 struct proc *p; 249 /* XXX actually varargs. */ 250 struct shmsys_args *uap; 251 { 252 sysv_nosys(p, "SYSVSHM"); 253 return nosys(p, (struct nosys_args *)uap); 254 }; 255 256 /* called from kern_fork.c */ 257 void 258 shmfork(p1, p2) 259 struct proc *p1, *p2; 260 { 261 return; 262 } 263 264 /* called from kern_exit.c */ 265 void 266 shmexit(p) 267 struct proc *p; 268 { 269 return; 270 } 271 272 #endif /* !defined(SYSVSHM) */ 273 274 #endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */ 275