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>
30 enum {OPENX
, MKFIFOX
, MKDIRX
};
32 extern int __open_extended(const char *, int, uid_t
, gid_t
, int, struct kauth_filesec
*);
33 extern int __mkfifo_extended(const char *, uid_t
, gid_t
, int, struct kauth_filesec
*);
34 extern int __mkdir_extended(const char *, uid_t
, gid_t
, int, struct kauth_filesec
*);
37 _mkfilex_np(int opcode
, const char *path
, int flags
, filesec_t fsec
)
39 uid_t owner
= KAUTH_UID_NONE
;
40 gid_t group
= KAUTH_GID_NONE
;
44 struct kauth_filesec
*fsacl
= NULL
;
45 struct kauth_filesec static_filesec
;
47 /* handle extended security data */
49 /* fetch basic parameters */
50 if ((filesec_get_property(fsec
, FILESEC_OWNER
, &owner
) != 0) && (errno
!= ENOENT
))
52 if ((filesec_get_property(fsec
, FILESEC_GROUP
, &group
) != 0) && (errno
!= ENOENT
))
54 if ((filesec_get_property(fsec
, FILESEC_MODE
, &mode
) != 0) && (errno
!= ENOENT
))
57 /* try to fetch the ACL */
58 if (((filesec_get_property(fsec
, FILESEC_ACL_RAW
, &fsacl
) != 0) ||
59 (filesec_get_property(fsec
, FILESEC_ACL_ALLOCSIZE
, &size
) != 0)) &&
63 /* only valid for chmod */
64 if (fsacl
== _FILESEC_REMOVE_ACL
) {
69 /* no ACL, use local filesec */
71 bzero(&static_filesec
, sizeof(static_filesec
));
72 fsacl
= &static_filesec
;
73 fsacl
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
74 fsacl
->fsec_entrycount
= KAUTH_FILESEC_NOACL
;
79 /* grab the owner and group UUID if present */
80 if (filesec_get_property(fsec
, FILESEC_UUID
, &fsacl
->fsec_owner
) != 0) {
83 bzero(&fsacl
->fsec_owner
, sizeof(fsacl
->fsec_owner
));
87 if (filesec_get_property(fsec
, FILESEC_GRPUUID
, &fsacl
->fsec_group
) != 0) {
90 bzero(&fsacl
->fsec_group
, sizeof(fsacl
->fsec_group
));
95 /* after all this, if we didn't find anything that needs it, don't pass it in */
102 return(__open_extended(path
, flags
, owner
, group
, mode
, fsacl
));
104 return(__mkfifo_extended(path
, owner
, group
, mode
, fsacl
));
106 return(__mkdir_extended(path
, owner
, group
, mode
, fsacl
));
108 /* should never get here */
114 openx_np(const char *path
, int flags
, filesec_t fsec
)
116 /* optimise for the simple case */
117 if (!(flags
& O_CREAT
) || (fsec
== NULL
))
118 return(open(path
, flags
));
119 return(_mkfilex_np(OPENX
, path
, flags
, fsec
));
123 mkfifox_np(const char *path
, filesec_t fsec
)
125 return(_mkfilex_np(MKFIFOX
, path
, 0, fsec
));
129 mkdirx_np(const char *path
, filesec_t fsec
)
131 return(_mkfilex_np(MKDIRX
, path
, 0, fsec
));