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.7 2003/08/26 21:09:02 rob Exp $ */ 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> 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(struct proc *p, struct ipc_perm *perm, int mode) 50 { 51 struct ucred *cred = p->p_ucred; 52 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; 63 } 64 65 if (mode & IPC_M) 66 return (0); 67 return ((mode & perm->mode) == mode || 68 suser_cred(cred, 0) == 0 ? 0 : EACCES); 69 } 70 71 #endif /* defined(SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) */ 72 73 74 #if !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) 75 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> 82 83 static void sysv_nosys (char *s); 84 85 static void 86 sysv_nosys(char *s) 87 { 88 struct thread *td = curthread; 89 struct proc *p = td->td_proc; 90 91 log(LOG_ERR, "cmd %s pid %d tried to use non-present %s\n", 92 td->td_comm, (p ? p->p_pid : -1), s); 93 } 94 95 #if !defined(SYSVSEM) 96 97 /* 98 * SYSVSEM stubs 99 */ 100 101 int 102 semsys(struct semsys_args *uap) 103 { 104 sysv_nosys("SYSVSEM"); 105 return nosys((struct nosys_args *)uap); 106 }; 107 108 int 109 __semctl(struct __semctl_args *uap) 110 { 111 sysv_nosys("SYSVSEM"); 112 return nosys((struct nosys_args *)uap); 113 }; 114 115 int 116 semget(struct semget_args *uap) 117 { 118 sysv_nosys("SYSVSEM"); 119 return nosys((struct nosys_args *)uap); 120 }; 121 122 int 123 semop(struct semop_args *uap) 124 { 125 sysv_nosys("SYSVSEM"); 126 return nosys((struct nosys_args *)uap); 127 }; 128 129 /* called from kern_exit.c */ 130 void 131 semexit(struct proc *p) 132 { 133 /* empty */ 134 } 135 136 #endif /* !defined(SYSVSEM) */ 137 138 139 #if !defined(SYSVMSG) 140 141 /* 142 * SYSVMSG stubs 143 * 144 * note: msgsys args actually var-args? YYYY 145 */ 146 147 int 148 msgsys(struct msgsys_args *uap) 149 { 150 sysv_nosys("SYSVMSG"); 151 return nosys((struct nosys_args *)uap); 152 }; 153 154 int 155 msgctl(struct msgctl_args *uap) 156 { 157 sysv_nosys("SYSVMSG"); 158 return nosys((struct nosys_args *)uap); 159 }; 160 161 int 162 msgget(struct msgget_args *uap) 163 { 164 sysv_nosys("SYSVMSG"); 165 return nosys((struct nosys_args *)uap); 166 }; 167 168 int 169 msgsnd(struct msgsnd_args *uap) 170 { 171 sysv_nosys("SYSVMSG"); 172 return nosys((struct nosys_args *)uap); 173 }; 174 175 int 176 msgrcv(struct msgrcv_args *uap) 177 { 178 sysv_nosys("SYSVMSG"); 179 return nosys((struct nosys_args *)uap); 180 }; 181 182 #endif /* !defined(SYSVMSG) */ 183 184 185 #if !defined(SYSVSHM) 186 187 /* 188 * SYSVSHM stubs 189 */ 190 191 int 192 shmdt(struct shmdt_args *uap) 193 { 194 sysv_nosys("SYSVSHM"); 195 return nosys((struct nosys_args *)uap); 196 }; 197 198 int 199 shmat(struct shmat_args *uap) 200 { 201 sysv_nosys("SYSVSHM"); 202 return nosys((struct nosys_args *)uap); 203 }; 204 205 int 206 shmctl(struct shmctl_args *uap) 207 { 208 sysv_nosys("SYSVSHM"); 209 return nosys((struct nosys_args *)uap); 210 }; 211 212 int 213 shmget(struct shmget_args *uap) 214 { 215 sysv_nosys("SYSVSHM"); 216 return nosys((struct nosys_args *)uap); 217 }; 218 219 /* XXX actually varargs. */ 220 int 221 shmsys(struct shmsys_args *uap) 222 { 223 sysv_nosys("SYSVSHM"); 224 return nosys((struct nosys_args *)uap); 225 }; 226 227 /* called from kern_fork.c */ 228 void 229 shmfork(struct proc *p1, struct proc *p2) 230 { 231 /* empty */ 232 } 233 234 /* called from kern_exit.c */ 235 void 236 shmexit(struct vmspace *vm) 237 { 238 /* empty */ 239 } 240 241 #endif /* !defined(SYSVSHM) */ 242 243 #endif /* !defined(SYSVSEM) || !defined(SYSVSHM) || !defined(SYSVMSG) */ 244