]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
8f6c56a5 | 11 | * |
6601e61a A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
21 | */ |
22 | /* $NetBSD: sysv_ipc.c,v 1.7 1994/06/29 06:33:11 cgd Exp $ */ | |
23 | ||
24 | /* | |
25 | * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca> | |
26 | * All rights reserved. | |
27 | * | |
28 | * Redistribution and use in source and binary forms, with or without | |
29 | * modification, are permitted provided that the following conditions | |
30 | * are met: | |
31 | * 1. Redistributions of source code must retain the above copyright | |
32 | * notice, this list of conditions and the following disclaimer. | |
33 | * 2. Redistributions in binary form must reproduce the above copyright | |
34 | * notice, this list of conditions and the following disclaimer in the | |
35 | * documentation and/or other materials provided with the distribution. | |
36 | * 3. All advertising materials mentioning features or use of this software | |
37 | * must display the following acknowledgement: | |
38 | * This product includes software developed by Herb Peyerl. | |
39 | * 4. The name of Herb Peyerl may not be used to endorse or promote products | |
40 | * derived from this software without specific prior written permission. | |
41 | * | |
42 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
43 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
44 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
45 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
46 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
47 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
48 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
49 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
50 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
51 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
52 | */ | |
53 | ||
54 | ||
55 | #include <sys/param.h> | |
56 | #include <sys/ipc.h> | |
57 | #include <sys/ucred.h> | |
91447636 | 58 | #include <sys/kauth.h> |
1c79356b A |
59 | |
60 | ||
61 | /* | |
62 | * Check for ipc permission | |
63 | * | |
64 | * XXX: Should pass proc argument so that we can pass | |
65 | * XXX: proc->p_acflag to suser() | |
66 | */ | |
67 | ||
68 | int | |
91447636 | 69 | ipcperm(kauth_cred_t cred, struct ipc_perm *perm, int mode) |
1c79356b A |
70 | { |
71 | ||
9bccf70c | 72 | if (!suser(cred, (u_short *)NULL)) |
1c79356b A |
73 | return (0); |
74 | ||
75 | /* Check for user match. */ | |
91447636 A |
76 | if (kauth_cred_getuid(cred) != perm->cuid && kauth_cred_getuid(cred) != perm->uid) { |
77 | int is_member; | |
78 | ||
1c79356b A |
79 | if (mode & IPC_M) |
80 | return (EPERM); | |
81 | /* Check for group match. */ | |
82 | mode >>= 3; | |
91447636 A |
83 | if ((kauth_cred_ismember_gid(cred, perm->gid, &is_member) || !is_member) && |
84 | (kauth_cred_ismember_gid(cred, perm->cgid, &is_member) || !is_member)) | |
1c79356b A |
85 | /* Check for `other' match. */ |
86 | mode >>= 3; | |
87 | } | |
88 | ||
89 | if (mode & IPC_M) | |
90 | return (0); | |
91 | return ((mode & perm->mode) == mode ? 0 : EACCES); | |
92 | } |