summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libfshelp/fetch-root.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/libfshelp/fetch-root.c b/libfshelp/fetch-root.c
index 3c149e02..682197a4 100644
--- a/libfshelp/fetch-root.c
+++ b/libfshelp/fetch-root.c
@@ -29,7 +29,9 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
file_t dotdot,
uid_t *uids, int uids_len,
uid_t *gids, int gids_len,
- int flags, fshelp_callback_t callback,
+ int flags,
+ fshelp_fetch_root_callback1_t callback1,
+ fshelp_fetch_root_callback2_t callback2,
retry_type *retry, char *retryname,
file_t *root)
{
@@ -42,7 +44,6 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
assert ((box->flags & TRANSBOX_STARTING) == 0);
else
{
- mach_port_t underlying;
uid_t uid, gid;
char *argz;
int argz_len;
@@ -54,7 +55,7 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
int uidarray[2], gidarray[2];
mach_port_t
- reauth (mach_port_t port)
+ reauth (mach_port_t port, mach_msg_type_name_t port_type)
{
mach_port_t rend, ret;
error_t err;
@@ -67,6 +68,9 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
MACH_MSG_TYPE_MAKE_SEND);
assert_perror (err);
+ if (port_type == MACH_MSG_TYPE_MAKE_SEND)
+ mach_port_insert_right (mach_task_self (), port, port,port_type);
+
err = auth_user_authenticate (newauth, port, rend,
MACH_MSG_TYPE_MAKE_SEND,
&ret);
@@ -74,9 +78,24 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
ret = MACH_PORT_NULL;
mach_port_destroy (mach_task_self (), rend);
- mach_port_deallocate (mach_task_self (), port);
+ if (!err && port_type != MACH_MSG_TYPE_COPY_SEND)
+ mach_port_deallocate (mach_task_self (), port);
+
return ret;
}
+ error_t fetch_underlying (int flags, mach_port_t *underlying,
+ mach_msg_type_name_t *underlying_type)
+ {
+ error_t err =
+ (*callback2) (box->cookie, cookie, flags,
+ underlying, underlying_type);
+ if (!err)
+ {
+ *underlying = reauth (*underlying, *underlying_type);
+ *underlying_type = MACH_MSG_TYPE_MOVE_SEND;
+ }
+ return err;
+ }
if (box->flags & TRANSBOX_STARTING)
{
@@ -87,8 +106,7 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
box->flags |= TRANSBOX_STARTING;
mutex_unlock (box->lock);
- err = (*callback) (box->cookie, cookie, &underlying, &uid,
- &gid, &argz, &argz_len);
+ err = (*callback1) (box->cookie, cookie, &uid, &gid, &argz, &argz_len);
if (err)
goto return_error;
@@ -104,14 +122,14 @@ fshelp_fetch_root (struct transbox *box, void *cookie,
bzero (fds, (STDERR_FILENO + 1) * sizeof (mach_port_t));
bzero (ints, INIT_INT_MAX * sizeof (int));
- ports[INIT_PORT_CWDIR] = reauth (getcwdir ());
- ports[INIT_PORT_CRDIR] = reauth (getcrdir ());
+ ports[INIT_PORT_CWDIR] = reauth (getcwdir (), MACH_MSG_TYPE_MOVE_SEND);
+ ports[INIT_PORT_CRDIR] = reauth (getcrdir (), MACH_MSG_TYPE_MOVE_SEND);
ports[INIT_PORT_AUTH] = newauth;
- fds[STDERR_FILENO] = reauth (getdport (STDERR_FILENO));
+ fds[STDERR_FILENO] =
+ reauth (getdport (STDERR_FILENO), MACH_MSG_TYPE_MOVE_SEND);
- err = fshelp_start_translator_long (reauth (underlying),
- MACH_MSG_TYPE_MOVE_SEND,
+ err = fshelp_start_translator_long (fetch_underlying,
argz, argz, argz_len,
fds, MACH_MSG_TYPE_MOVE_SEND,
STDERR_FILENO + 1,