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