2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/types.h>
28 #include <uuid/uuid.h>
30 #if 1 /* for turdfile code only */
37 static int chmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, kauth_filesec_t fsacl
);
38 static int fchmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, kauth_filesec_t fsacl
);
40 static int chmodx1(void *obj
,
41 int (* chmod_syscall
)(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
,
42 kauth_filesec_t fsacl
),
49 chmodx_np(const char *path
, filesec_t fsec
)
51 return(chmodx1((void *)&path
, chmodx_syscall
, fsec
));
55 fchmodx_np(int fd
, filesec_t fsec
)
57 return(chmodx1((void *)&fd
, fchmodx_syscall
, fsec
));
63 extern int __chmod_extended(char *, uid_t
, gid_t
, int, kauth_filesec_t
);
64 extern int __fchmod_extended(int, uid_t
, gid_t
, int, kauth_filesec_t
);
67 chmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, kauth_filesec_t fsacl
)
69 char *path
= *(char **)obj
;
71 return(__chmod_extended(path
, fsowner
, fsgrp
, mode
, fsacl
));
75 fchmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, kauth_filesec_t fsacl
)
78 return(__fchmod_extended(fd
, fsowner
, fsgrp
, mode
, fsacl
));
87 int (chmod_syscall
)(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, kauth_filesec_t fsacl
),
90 uid_t fsowner
= KAUTH_UID_NONE
;
91 gid_t fsgrp
= KAUTH_GID_NONE
;
97 kauth_filesec_t fsacl
= KAUTH_FILESEC_NONE
;
98 struct kauth_filesec static_filesec
;
105 /* regular properties */
106 if ((filesec_get_property(fsec
, FILESEC_OWNER
, &fsowner
) != 0) && (errno
!= ENOENT
))
108 if ((filesec_get_property(fsec
, FILESEC_GROUP
, &fsgrp
) != 0) && (errno
!= ENOENT
))
110 if ((filesec_get_property(fsec
, FILESEC_MODE
, &fsec_mode
)) != 0) {
119 * We can set any or all of the ACL and UUIDs, but the two are transported in one
120 * structure. If we have an ACL, we'll use its allocated structure, otherwise we
123 if (((filesec_get_property(fsec
, FILESEC_ACL_RAW
, &fsacl
) != 0) ||
124 (filesec_get_property(fsec
, FILESEC_ACL_ALLOCSIZE
, &size
) != 0)) &&
127 /* caller wants to delete ACL, must remember this */
128 if (fsacl
== _FILESEC_REMOVE_ACL
) {
133 /* no ACL, use local filesec */
134 if (fsacl
== KAUTH_FILESEC_NONE
) {
135 bzero(&static_filesec
, sizeof(static_filesec
));
136 fsacl
= &static_filesec
;
137 fsacl
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
138 fsacl
->fsec_entrycount
= KAUTH_FILESEC_NOACL
;
143 /* grab the owner and group UUID if present */
144 if (filesec_get_property(fsec
, FILESEC_UUID
, &fsacl
->fsec_owner
) != 0) {
147 bzero(&fsacl
->fsec_owner
, sizeof(fsacl
->fsec_owner
));
151 if (filesec_get_property(fsec
, FILESEC_GRPUUID
, &fsacl
->fsec_group
) != 0) {
154 bzero(&fsacl
->fsec_group
, sizeof(fsacl
->fsec_group
));
159 /* after all this, if we didn't find anything that needs it, don't pass it in */
162 * If the caller was trying to remove the ACL, and there are no UUIDs,
163 * we can tell the kernel to completely nuke the whole datastructure.
166 fsacl
= _FILESEC_REMOVE_ACL
;
168 fsacl
= KAUTH_FILESEC_NONE
;
172 return(chmod_syscall(obj
, fsowner
, fsgrp
, fsmode
, fsacl
));