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