1 /* $NetBSD: acl.c,v 1.1.1.1 2011/04/13 18:14:35 elric Exp $ */
4 * Copyright (c) 2005, PADL Software Pty Ltd.
7 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of PADL Software nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 kcm_access(krb5_context context
,
50 KCM_ASSERT_VALID(ccache
);
53 case KCM_OP_INITIALIZE
:
56 case KCM_OP_REMOVE_CRED
:
57 case KCM_OP_SET_FLAGS
:
60 case KCM_OP_GET_INITIAL_TICKET
:
61 case KCM_OP_GET_TICKET
:
62 case KCM_OP_MOVE_CACHE
:
63 case KCM_OP_SET_DEFAULT_CACHE
:
64 case KCM_OP_SET_KDC_OFFSET
:
73 case KCM_OP_GET_PRINCIPAL
:
74 case KCM_OP_GET_CRED_UUID_LIST
:
75 case KCM_OP_GET_CRED_BY_UUID
:
76 case KCM_OP_GET_CACHE_UUID_LIST
:
77 case KCM_OP_GET_CACHE_BY_UUID
:
78 case KCM_OP_GET_DEFAULT_CACHE
:
79 case KCM_OP_GET_KDC_OFFSET
:
88 if (ccache
->flags
& KCM_FLAGS_OWNER_IS_SYSTEM
) {
89 /* System caches cannot be reinitialized or destroyed by users */
90 if (opcode
== KCM_OP_INITIALIZE
||
91 opcode
== KCM_OP_DESTROY
||
92 opcode
== KCM_OP_REMOVE_CRED
||
93 opcode
== KCM_OP_MOVE_CACHE
) {
98 /* Let root always read system caches */
99 if (CLIENT_IS_ROOT(client
)) {
105 /* start out with "other" mask */
106 mask
= S_IROTH
|S_IWOTH
;
108 /* root can do anything */
109 if (CLIENT_IS_ROOT(client
)) {
111 mask
|= S_IRUSR
|S_IRGRP
|S_IROTH
;
113 mask
|= S_IWUSR
|S_IWGRP
|S_IWOTH
;
115 /* same session same as owner */
116 if (kcm_is_same_session(client
, ccache
->uid
, ccache
->session
)) {
123 if (client
->uid
== ccache
->uid
) {
130 if (client
->gid
== ccache
->gid
) {
137 ret
= (ccache
->mode
& mask
) ? 0 : KRB5_FCC_PERM
;
141 kcm_log(2, "Process %d is not permitted to call %s on cache %s",
142 client
->pid
, kcm_op2string(opcode
), ccache
->name
);
149 kcm_chmod(krb5_context context
,
154 KCM_ASSERT_VALID(ccache
);
156 /* System cache mode can only be set at startup */
157 if (ccache
->flags
& KCM_FLAGS_OWNER_IS_SYSTEM
)
158 return KRB5_FCC_PERM
;
160 if (ccache
->uid
!= client
->uid
)
161 return KRB5_FCC_PERM
;
163 if (ccache
->gid
!= client
->gid
)
164 return KRB5_FCC_PERM
;
166 HEIMDAL_MUTEX_lock(&ccache
->mutex
);
170 HEIMDAL_MUTEX_unlock(&ccache
->mutex
);
176 kcm_chown(krb5_context context
,
182 KCM_ASSERT_VALID(ccache
);
184 /* System cache owner can only be set at startup */
185 if (ccache
->flags
& KCM_FLAGS_OWNER_IS_SYSTEM
)
186 return KRB5_FCC_PERM
;
188 if (ccache
->uid
!= client
->uid
)
189 return KRB5_FCC_PERM
;
191 if (ccache
->gid
!= client
->gid
)
192 return KRB5_FCC_PERM
;
194 HEIMDAL_MUTEX_lock(&ccache
->mutex
);
199 HEIMDAL_MUTEX_unlock(&ccache
->mutex
);