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>
26 #include <sys/syscall.h>
32 _mkfilex_np(int opcode
, const char *path
, int flags
, filesec_t fsec
)
34 uid_t owner
= KAUTH_UID_NONE
;
35 gid_t group
= KAUTH_GID_NONE
;
39 struct kauth_filesec
*fsacl
= NULL
;
40 struct kauth_filesec static_filesec
;
42 /* handle extended security data */
44 /* fetch basic parameters */
45 if ((filesec_get_property(fsec
, FILESEC_OWNER
, &owner
) != 0) && (errno
!= ENOENT
))
47 if ((filesec_get_property(fsec
, FILESEC_GROUP
, &group
) != 0) && (errno
!= ENOENT
))
49 if ((filesec_get_property(fsec
, FILESEC_MODE
, &mode
) != 0) && (errno
!= ENOENT
))
52 /* try to fetch the ACL */
53 if (((filesec_get_property(fsec
, FILESEC_ACL_RAW
, &fsacl
) != 0) ||
54 (filesec_get_property(fsec
, FILESEC_ACL_ALLOCSIZE
, &size
) != 0)) &&
58 /* only valid for chmod */
59 if (fsacl
== _FILESEC_REMOVE_ACL
) {
64 /* no ACL, use local filesec */
66 bzero(&static_filesec
, sizeof(static_filesec
));
67 fsacl
= &static_filesec
;
68 fsacl
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
69 fsacl
->fsec_entrycount
= KAUTH_FILESEC_NOACL
;
74 /* grab the owner and group UUID if present */
75 if (filesec_get_property(fsec
, FILESEC_UUID
, &fsacl
->fsec_owner
) != 0) {
78 bzero(&fsacl
->fsec_owner
, sizeof(fsacl
->fsec_owner
));
82 if (filesec_get_property(fsec
, FILESEC_GRPUUID
, &fsacl
->fsec_group
) != 0) {
85 bzero(&fsacl
->fsec_group
, sizeof(fsacl
->fsec_group
));
90 /* after all this, if we didn't find anything that needs it, don't pass it in */
95 if (opcode
== SYS_open_extended
) {
96 return(syscall(opcode
, path
, flags
, owner
, group
, mode
, fsacl
));
98 return(syscall(opcode
, path
, owner
, group
, mode
, fsacl
));
103 openx_np(const char *path
, int flags
, filesec_t fsec
)
105 /* optimise for the simple case */
106 if (!(flags
& O_CREAT
) || (fsec
== NULL
))
107 return(open(path
, flags
));
108 return(_mkfilex_np(SYS_open_extended
, path
, flags
, fsec
));
112 mkfifox_np(const char *path
, filesec_t fsec
)
114 return(_mkfilex_np(SYS_mkfifo_extended
, path
, 0, fsec
));
118 mkdirx_np(const char *path
, filesec_t fsec
)
120 return(_mkfilex_np(SYS_mkdir_extended
, path
, 0, fsec
));