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