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>
24 #include <sys/syscall.h>
29 #include <uuid/uuid.h>
31 #if 1 /* for turdfile code only */
38 static int chmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, struct kauth_filesec
*fsacl
);
39 static int fchmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, struct kauth_filesec
*fsacl
);
41 static int chmodx1(void *obj
,
42 int (* chmod_syscall
)(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
,
43 struct kauth_filesec
*fsacl
),
50 chmodx_np(const char *path
, filesec_t fsec
)
52 return(chmodx1((void *)&path
, chmodx_syscall
, fsec
));
56 fchmodx_np(int fd
, filesec_t fsec
)
58 return(chmodx1((void *)&fd
, fchmodx_syscall
, fsec
));
65 chmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, struct kauth_filesec
*fsacl
)
67 char *path
= *(char **)obj
;
69 return(syscall(SYS_chmod_extended
, path
, fsowner
, fsgrp
, mode
, fsacl
));
73 fchmodx_syscall(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, struct kauth_filesec
*fsacl
)
76 return(syscall(SYS_fchmod_extended
, fd
, fsowner
, fsgrp
, mode
, fsacl
));
85 int (chmod_syscall
)(void *obj
, uid_t fsowner
, gid_t fsgrp
, int mode
, struct kauth_filesec
*fsacl
),
88 uid_t fsowner
= KAUTH_UID_NONE
;
89 gid_t fsgrp
= KAUTH_GID_NONE
;
95 struct kauth_filesec
*fsacl
= NULL
;
96 struct kauth_filesec static_filesec
;
103 /* regular properties */
104 if ((filesec_get_property(fsec
, FILESEC_OWNER
, &fsowner
) != 0) && (errno
!= ENOENT
))
106 if ((filesec_get_property(fsec
, FILESEC_GROUP
, &fsgrp
) != 0) && (errno
!= ENOENT
))
108 if ((filesec_get_property(fsec
, FILESEC_MODE
, &fsec_mode
)) != 0) {
117 * We can set any or all of the ACL and UUIDs, but the two are transported in one
118 * structure. If we have an ACL, we'll use its allocated structure, otherwise we
121 if (((filesec_get_property(fsec
, FILESEC_ACL_RAW
, &fsacl
) != 0) ||
122 (filesec_get_property(fsec
, FILESEC_ACL_ALLOCSIZE
, &size
) != 0)) &&
125 /* caller wants to delete ACL, must remember this */
126 if (fsacl
== _FILESEC_REMOVE_ACL
) {
131 /* no ACL, use local filesec */
133 bzero(&static_filesec
, sizeof(static_filesec
));
134 fsacl
= &static_filesec
;
135 fsacl
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
136 fsacl
->fsec_entrycount
= KAUTH_FILESEC_NOACL
;
141 /* grab the owner and group UUID if present */
142 if (filesec_get_property(fsec
, FILESEC_UUID
, &fsacl
->fsec_owner
) != 0) {
145 bzero(&fsacl
->fsec_owner
, sizeof(fsacl
->fsec_owner
));
149 if (filesec_get_property(fsec
, FILESEC_GRPUUID
, &fsacl
->fsec_group
) != 0) {
152 bzero(&fsacl
->fsec_group
, sizeof(fsacl
->fsec_group
));
157 /* after all this, if we didn't find anything that needs it, don't pass it in */
160 * If the caller was trying to remove the ACL, and there are no UUIDs,
161 * we can tell the kernel to completely nuke the whole datastructure.
164 fsacl
= _FILESEC_REMOVE_ACL
;
170 return(chmod_syscall(obj
, fsowner
, fsgrp
, fsmode
, fsacl
));