O_CREAT | O_TRUNC,
};
+#ifdef __APPLE__
+static FileIOPrivilegedOpener *privilegedOpenerFunc = NULL;
+#endif
+
/*
* Options for FileCoalescing performance optimization
*/
return useProxy ? ProxyOpen(pathName, flags, mode) :
Posix_Open(pathName, flags, mode);
}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * FileIO_SetPrivilegedOpener --
+ *
+ * Set the function to be used when opening files with privilege,
+ * overriding the default behavior. See FileIO_PrivilegedPosixOpen.
+ *
+ * Setting the privileged opener to NULL will restore default
+ * behavior.
+ *
+ * This function is not thread safe.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+FileIO_SetPrivilegedOpener(FileIOPrivilegedOpener *opener) // IN
+{
+ ASSERT(privilegedOpenerFunc == NULL || opener == NULL);
+ privilegedOpenerFunc = opener;
+}
#endif
int mode, // IN: mode_t for creation
uint32 maxWaitTimeMsec) // IN: Ignored
{
- uid_t uid = -1;
int fd = -1;
int flags = 0;
int error;
file->flags = access;
+#if defined(__APPLE__)
if (access & FILEIO_OPEN_PRIVILEGED) {
- uid = Id_BeginSuperUser();
+ // We only support privileged opens, not creates or truncations.
+ if ((flags & (O_CREAT | O_TRUNC)) != 0) {
+ fd = -1;
+ errno = EACCES;
+ } else {
+ fd = FileIO_PrivilegedPosixOpen(pathName, flags);
+ }
+ } else {
+ fd = PosixFileOpener(pathName, flags, mode);
}
+#else
+ {
+ uid_t uid = -1;
- fd = PosixFileOpener(pathName, flags, mode);
+ if (access & FILEIO_OPEN_PRIVILEGED) {
+ uid = Id_BeginSuperUser();
+ }
- error = errno;
+ fd = PosixFileOpener(pathName, flags, mode);
- if (access & FILEIO_OPEN_PRIVILEGED) {
- Id_EndSuperUser(uid);
- }
+ error = errno;
- errno = error;
+ if (access & FILEIO_OPEN_PRIVILEGED) {
+ Id_EndSuperUser(uid);
+ }
+
+ errno = error;
+ }
+#endif
if (fd == -1) {
ret = FileIOErrno2Result(errno);
int flags) // IN:
{
int fd;
- Bool suDone;
- uid_t uid = -1;
if (pathName == NULL) {
errno = EFAULT;
ASSERT((flags & (O_CREAT | O_TRUNC)) == 0);
- if (Id_IsSuperUser()) {
- suDone = FALSE;
- } else {
- uid = Id_BeginSuperUser();
- suDone = TRUE;
- }
+#if defined(__APPLE__)
+ if (privilegedOpenerFunc != NULL) {
+ fd = privilegedOpenerFunc(pathName, flags);
+ } else
+#endif
+ {
+ Bool suDone;
+ uid_t uid = -1;
+
+ if (Id_IsSuperUser()) {
+ suDone = FALSE;
+ } else {
+ uid = Id_BeginSuperUser();
+ suDone = TRUE;
+ }
- fd = Posix_Open(pathName, flags, 0);
+ fd = Posix_Open(pathName, flags, 0);
- if (suDone) {
- int error = errno;
+ if (suDone) {
+ int error = errno;
- Id_EndSuperUser(uid);
- errno = error;
+ Id_EndSuperUser(uid);
+ errno = error;
+ }
}
-
return fd;
}