Home | History | Annotate | Line # | Download | only in kern
sysv_ipc.c revision 1.5
      1  1.1      cgd /*
      2  1.4  hpeyerl  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) novatel.ca>
      3  1.1      cgd  * All rights reserved.
      4  1.1      cgd  *
      5  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1      cgd  * modification, are permitted provided that the following conditions
      7  1.1      cgd  * are met:
      8  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.4  hpeyerl  * 2. The name of the author may not be used to endorse or promote products
     11  1.4  hpeyerl  *    derived from this software without specific prior written permission
     12  1.1      cgd  *
     13  1.4  hpeyerl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     14  1.4  hpeyerl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     15  1.4  hpeyerl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     16  1.4  hpeyerl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     17  1.4  hpeyerl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     18  1.4  hpeyerl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     19  1.4  hpeyerl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     20  1.4  hpeyerl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     21  1.4  hpeyerl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     22  1.4  hpeyerl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23  1.1      cgd  *
     24  1.1      cgd  */
     25  1.1      cgd 
     26  1.2  mycroft #include <sys/param.h>
     27  1.2  mycroft #include <sys/kernel.h>
     28  1.2  mycroft #include <sys/proc.h>
     29  1.2  mycroft #include <sys/ipc.h>
     30  1.4  hpeyerl #include <sys/systm.h>
     31  1.1      cgd 
     32  1.1      cgd /*
     33  1.4  hpeyerl  * Check for ipc permission
     34  1.1      cgd  */
     35  1.1      cgd 
     36  1.4  hpeyerl int
     37  1.5  mycroft ipcperm(cred, perm, mode)
     38  1.5  mycroft 	struct ucred *cred;
     39  1.4  hpeyerl 	struct ipc_perm *perm;
     40  1.1      cgd 	int mode;
     41  1.1      cgd {
     42  1.1      cgd 
     43  1.5  mycroft 	if (cred->cr_uid == 0)
     44  1.5  mycroft 		return (0);
     45  1.4  hpeyerl 
     46  1.5  mycroft 	/* Check for user match. */
     47  1.5  mycroft 	if (cred->cr_uid != perm->cuid && cred->cr_uid != perm->uid) {
     48  1.5  mycroft 		if (mode & IPC_M)
     49  1.5  mycroft 			return (EPERM);
     50  1.5  mycroft 		/* Check for group match. */
     51  1.5  mycroft 		mode >>= 3;
     52  1.5  mycroft 		if (!groupmember(perm->gid, cred) &&
     53  1.5  mycroft 		    !groupmember(perm->cgid, cred))
     54  1.5  mycroft 			/* Check for `other' match. */
     55  1.5  mycroft 			mode >>= 3;
     56  1.1      cgd 	}
     57  1.4  hpeyerl 
     58  1.5  mycroft 	if (mode & IPC_M)
     59  1.5  mycroft 		return (0);
     60  1.5  mycroft 	return ((mode & perm->mode) == mode ? 0 : EACCES);
     61  1.1      cgd }
     62