13d903220SDoug Rabson /* $Id$ */ 23d903220SDoug Rabson /* $NetBSD: sysv_ipc.c,v 1.7 1994/06/29 06:33:11 cgd Exp $ */ 33d903220SDoug Rabson 43d903220SDoug Rabson /* 53d903220SDoug Rabson * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca> 63d903220SDoug Rabson * All rights reserved. 73d903220SDoug Rabson * 83d903220SDoug Rabson * Redistribution and use in source and binary forms, with or without 93d903220SDoug Rabson * modification, are permitted provided that the following conditions 103d903220SDoug Rabson * are met: 113d903220SDoug Rabson * 1. Redistributions of source code must retain the above copyright 123d903220SDoug Rabson * notice, this list of conditions and the following disclaimer. 133d903220SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 143d903220SDoug Rabson * notice, this list of conditions and the following disclaimer in the 153d903220SDoug Rabson * documentation and/or other materials provided with the distribution. 163d903220SDoug Rabson * 3. All advertising materials mentioning features or use of this software 173d903220SDoug Rabson * must display the following acknowledgement: 183d903220SDoug Rabson * This product includes software developed by Herb Peyerl. 193d903220SDoug Rabson * 4. The name of Herb Peyerl may not be used to endorse or promote products 203d903220SDoug Rabson * derived from this software without specific prior written permission. 213d903220SDoug Rabson * 223d903220SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 233d903220SDoug Rabson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 243d903220SDoug Rabson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 253d903220SDoug Rabson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 263d903220SDoug Rabson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 273d903220SDoug Rabson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 283d903220SDoug Rabson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 293d903220SDoug Rabson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 303d903220SDoug Rabson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 313d903220SDoug Rabson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 323d903220SDoug Rabson */ 333d903220SDoug Rabson 343d903220SDoug Rabson #include <sys/param.h> 353d903220SDoug Rabson #include <sys/kernel.h> 363d903220SDoug Rabson #include <sys/proc.h> 373d903220SDoug Rabson #include <sys/ipc.h> 383d903220SDoug Rabson #include <sys/systm.h> 393d903220SDoug Rabson 403d903220SDoug Rabson /* 413d903220SDoug Rabson * Check for ipc permission 423d903220SDoug Rabson */ 433d903220SDoug Rabson 443d903220SDoug Rabson int 453d903220SDoug Rabson ipcperm(cred, perm, mode) 463d903220SDoug Rabson struct ucred *cred; 473d903220SDoug Rabson struct ipc_perm *perm; 483d903220SDoug Rabson int mode; 493d903220SDoug Rabson { 503d903220SDoug Rabson 513d903220SDoug Rabson if (cred->cr_uid == 0) 523d903220SDoug Rabson return (0); 533d903220SDoug Rabson 543d903220SDoug Rabson /* Check for user match. */ 553d903220SDoug Rabson if (cred->cr_uid != perm->cuid && cred->cr_uid != perm->uid) { 563d903220SDoug Rabson if (mode & IPC_M) 573d903220SDoug Rabson return (EPERM); 583d903220SDoug Rabson /* Check for group match. */ 593d903220SDoug Rabson mode >>= 3; 603d903220SDoug Rabson if (!groupmember(perm->gid, cred) && 613d903220SDoug Rabson !groupmember(perm->cgid, cred)) 623d903220SDoug Rabson /* Check for `other' match. */ 633d903220SDoug Rabson mode >>= 3; 643d903220SDoug Rabson } 653d903220SDoug Rabson 663d903220SDoug Rabson if (mode & IPC_M) 673d903220SDoug Rabson return (0); 683d903220SDoug Rabson return ((mode & perm->mode) == mode ? 0 : EACCES); 693d903220SDoug Rabson } 70