diff options
Diffstat (limited to 'libfshelp')
-rw-r--r-- | libfshelp/ChangeLog | 430 | ||||
-rw-r--r-- | libfshelp/Makefile | 15 | ||||
-rw-r--r-- | libfshelp/delegate.c | 18 | ||||
-rw-r--r-- | libfshelp/exec-reauth.c | 19 | ||||
-rw-r--r-- | libfshelp/fetch-root.c | 151 | ||||
-rw-r--r-- | libfshelp/fshelp.h | 110 | ||||
-rw-r--r-- | libfshelp/get-identity.c | 16 | ||||
-rw-r--r-- | libfshelp/lock-acquire.c | 14 | ||||
-rw-r--r-- | libfshelp/perms-access.c | 43 | ||||
-rw-r--r-- | libfshelp/perms-checkdirmod.c | 44 | ||||
-rw-r--r-- | libfshelp/perms-iscontroller.c | 38 | ||||
-rw-r--r-- | libfshelp/perms-isowner.c | 39 | ||||
-rw-r--r-- | libfshelp/return-buffer.c | 50 | ||||
-rw-r--r-- | libfshelp/set-options.c | 6 | ||||
-rw-r--r-- | libfshelp/start-translator-long.c | 166 | ||||
-rw-r--r-- | libfshelp/start-translator.c | 17 | ||||
-rw-r--r-- | libfshelp/touch.c | 49 | ||||
-rw-r--r-- | libfshelp/translated.c | 28 |
18 files changed, 544 insertions, 709 deletions
diff --git a/libfshelp/ChangeLog b/libfshelp/ChangeLog deleted file mode 100644 index fb6241bb..00000000 --- a/libfshelp/ChangeLog +++ /dev/null @@ -1,430 +0,0 @@ -Tue Jul 16 11:30:42 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * lock-acquire.c (EWOULDBLOCK): Define, to work around new libc - bug. - -Sun Jul 7 21:26:02 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * start-translator.c (fshelp_start_translator): Don't use unsafe - MOVE_SEND in call to fshelp_start_translator_long. - * fetch-root.c (fshelp_fetch_root): Don't use unsafe MOVE_SEND in - call to fshelp_start_translator_long. - -Thu Jul 4 15:38:36 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * get-identity.c (fshelp_get_identity): Bother to initialize - I->fileno. - -Wed Jul 3 11:29:49 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * get-identity.c: New file. - * fshelp.h (struct port_bucket): Mention name in global scope. - (fshelp_get_identity): New declaration. - * Makefile (SRCS): Add get-identity.c. - -Thu Jun 27 17:56:44 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * Makefile (LCLHDRS): Add trans.h. - -Mon Jun 24 16:00:48 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root): Deal properly with errors from - auth_makeauth. - -Fri Jun 21 00:07:26 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * set-options.c (fshelp_set_options): Add & use INPUT arg. - * fshelp.h (fshelp_set_options): Add INPUT argument. - (fshelp_return_malloced_buffer): New declaration. - * return-buffer.c: New file. - * Makefile (SRCS): Add return-buffer.c. - -Wed Jun 19 18:50:01 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * set-options.c: New file. - * fshelp.h: Add fshelp_set_options. - * Makefile (SRCS): Add set-options.c. - -Fri May 10 16:12:50 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * delegate.c (fshelp_delegate_translation): Don't cast ARGV when - calling arg_create. - -Thu May 9 11:17:08 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * exec-reauth.c (fshelp_exec_reauth): Provide new third arg to - proc_setowner. - - * delegate.c (fshelp_delegate_translation): Cast first arg to - argz_create appropriately. - - * fetch-root.c (fshelp_fetch_root) [reauth]: Use new args for - auth_user_authenticate. - -Fri Apr 26 18:51:07 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * start-translator-long.c (service_fsys_startup): Make mach_msg - calls interruptible. - -Wed Feb 21 17:09:12 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * set-active.c (fshelp_set_active): When EXCL, make sure the - active translator is really active. - - * fetch-root.c (fshelp_fetch_root): Make sure the returned fsys control - port is valid. - -Wed Feb 14 16:42:31 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * start-translator-long.c (fshelp_start_translator_long): - Terminate TASK if the exec fails. - -Mon Jan 29 15:32:54 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root): Use hurd_condition_wait - instead of condition_wait. - - * set-active.c (fshelp_set_active): Deal correctly with the case - where a passive translator is being started. - -Fri Jan 26 17:56:08 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root): If io_reauthenticate returns - an error, just return MACH_PORT_NULL instead of aborting (the - server probably died; not a good sign for the health of the - translator, but it's better than dying ourselves...). - -Tue Jan 2 15:36:28 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * exec-reauth.c (fshelp_exec_reauth): Don't setgid the uids. - -Mon Jan 1 17:13:25 1996 Miles Bader <miles@gnu.ai.mit.edu> - - * exec-reauth.c (fshelp_exec_reauth): New function. - * fshelp.h (fshelp_exec_reauth): New declaration. - * Makefile (SRCS): Added exec-reauth.c - -Mon Nov 6 13:37:52 1995 Miles Bader <miles@gnu.ai.mit.edu> - - * start-translator-long.c (service_fsys_startup): Don't pass the - address of reply.realnodeType.msgt_name -- it's not really an int, - although the compiler pretends it is. - - * fetch-root.c (fshelp_fetch_root): When PORT_TYPE is - MACH_MSG_TYPE_MAKE_SEND, make the right *before* using it. - (fshelp_fetch_root): Don't bother reauthenticating the underlying - node returned by CALLBACK2 -- it already has the right ids. This - also gets rid of a problem with giving away our auth port prematurely. - -Wed Nov 1 16:14:08 1995 Miles Bader <miles@gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root): Uses two callbacks now. Pass - an appropiate function to fshelp_start_translator_long instead of - the actual underlying node. - * fshelp.h (fshelp_fetch_root_callback1_t, - fshelp_fetch_root_callback2_t): New types replacing fshelp_callback_t. - (fshelp_fetch_root): Takes two callback args now. - - * start-translator.c (fshelp_start_translator): Change to use a - callback function instead of passing the actual node. - * start-translator-long.c (fshelp_start_translator_long, - service_fsys_startup): Ditto. - (service_fsys_startup): Support the open flags coming from the - translator. - (struct fsys_startup_request): Add the flags field. - (flagsCheck): New variable. - * fshelp.h (fshelp_open_fn_t): New type. - (fshelp_start_translator, fshelp_start_translator_long): Now take - a function that opens the underlying node instead of the node itself. - -Fri Oct 13 16:52:43 1995 Miles Bader <miles@gnu.ai.mit.edu> - - * start-translator-long.c (fshelp_start_translator_long): Undo - last change to file_exec args. - -Sat Oct 7 20:20:26 1995 Miles Bader <miles@gnu.ai.mit.edu> - - * start-translator-long.c (fshelp_start_translator_long): Add - values for the dealloc parameters to file_exec (all false). - Give away our send right to TASK when we do file_exec. - Initialize BOOTSTRAP & TASK so the cleanup code doesn't get confused. - -Fri Sep 29 17:44:00 1995 Miles Bader <miles@gnu.ai.mit.edu> - - * transbox-init.c (fshelp_transbox_init): Initialize the flags field. - -Tue Sep 5 18:25:24 1995 Miles Bader <miles@churchy.gnu.ai.mit.edu> - - * fshelp.h (fshelp_delegate_translation): New declaration. - * delegate.c (fshelp_delegate_translation): New file, new function. - -Fri Sep 1 12:01:06 1995 Miles Bader <miles@churchy.gnu.ai.mit.edu> - - * Makefile (SRCS): Add delegate.c. - (REMHDRS): Removed. - -Tue Jul 11 14:11:24 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * start-translator-long.c (fshelp_start_translator_long): If - PORTS_TYPE is MACH_MSG_TYPE_COPY_SEND, then drop our right on - bootstrap after the call, because we are pretending we haven't - changed the calling user's state. For the same reason, save the - old BOOTSTRAP port value, and restore it after the call. - -Thu Jul 6 15:35:23 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * Makefile: Removed dependencies that are now automatically - generated. - -Mon Jun 26 15:36:21 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root): Wakeup other blocked calls - *before* returning errors provided by fshelp_start_translator_long - or CALLBACK. - -Fri Jun 23 14:25:52 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root): Parenthesize assert test - correctly. - * start-translator-long.c (service_fsys_startup): Parenthesize - construction of flags arg correctly. - -Thu Jun 22 17:06:51 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root) [reauth]: If PORT is null, then - just return it. - - * fetch-root.c (fshelp_fetch_root): Pass type and length - parameters in the right order in calls to auth_makeauth and - fshelp_start_translator_long. - -Wed Jun 21 13:19:44 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * fetch-root.c (fshelp_fetch_root): Pass new third arg to - fshelp_set_active. - -Mon Jun 19 16:41:51 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * fetch-control.c (fshelp_fetch_control): Only frob refs if - control is non-null. - - * fshelp.h (fshelp_set_active): New parm EXCL. - * set-active.c (fshelp_set_active): Implement new interface. - - * fetch-control.c (fshelp_fetch_control): Don't frob obsolete - innerlock. - * transbox-init.c (fshelp_transbox_init): Don't init obsolete - innerlock. Do init TRANSBOX->wakeup. - * set-active.c (fshelp_set_active): Don't frob obsolete innerlock. - * fetch-root.c (fshelp_fetch_root): Reduce levels of loops. Only - change ACTIVE when we are holding the lock. Use condition - mechanism to serialize attempts to start the passive translator. - * fshelp.h (struct transbox): Delete member `innerlock'. Add - members `flags' and `wakeup'; and define values for flags. - -Wed Jun 14 13:06:17 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - * fshelp.h (fshelp_fetch_root): New arg COOKIE. - (fshelp_callback_t): COOKIE->COOKIE1. New arg COOKIE2. - * fetch-root.c (fshelp_fetch_root): Take new arg COOKIE and pass - it to CALLBACK. Free ARGZ after we're done with them. Never - consume the right on DOTDOT. - * Makefile (LCLHDRS): Removed trans.h. - * handle-startup.c, init-trans.c, start-trans.c, - transboot-clean.c, kill-trans.c, trans-iter.c, trans-cntl.c, - trans-drop.c, trans.h: Deleted files. - - * Makefile (SRCS): Remove translated.c. - * fshelp.h (fshelp_fetch_root): Don't actually need ROOT_TYPE. - UIDS and GIDS should be arrays. - (fshelp_callback_t): Should be error_t. - -Tue Jun 13 15:59:08 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu> - - Brand new translator support routines - * fshelp.h: Deleted `struct translink', fshelp_transboot_port_type, - fshelp_init_trans_link, fshelp_set_control, - fshelp_start_translator, fshelp_handle_fsys_startup, - fshelp_transboot_clean, fshelp_translator_iterate, - fshelp_translator_drop, fshelp_kill_translator. - * fshelp.h: Added fshelp_start_translator_long, - fshelp_start_translator, `struct transbox', fshelp_fetch_root, - fshelp_transbox_init, fshelp_callback_t, fshelp_translated, - fshelp_set_active, fshelp_fetch_control, fshelp_drop_transbox. - * Makefile (SRCS): Removed handle-startup.c, init-trans.c, - start-trans.c, transboot-clean.c, kill-trans.c, trans-iter.c, - trans-cntl.c, trans-drop.c. Added start-translator-long.c, - start-translator.c, fetch-root.c, transbox-init.c, translated.c, - set-active.c, fetch-control.c, and drop-transbox.c. - (OBJS): Replaced with computation from $(SRCS). - * start-translator.c, fetch-root.c, transbox-init.c, set-active.c, - fetch-control.c, drop-transbox.c: New files. - * start-translator-long.c: Adapted from ../lib/start-trans.c. - Include "fshelp.h" and <assert.h>. - (service_fsys_startup): Declare static. Only pass - MACH_RCV_TIMEOUT if TIMEOUT is nonzero. New parm `node_type'. - (fshelp_start_translator_long): Renamed from start_translator. - Lookup up executable at NAME instead of ARGZ. Delete vars - INIT_PORTS, FD_PORTS, INIT_INTS, I, and CHILD_PROC. Don't set any - of the ports, fds, or ints, with the exception of the bootstrap - port. Don't bother getting the child's proc server port. - Don't use __USEPORT. If we fail before calling file_exec, - then deallocate the ports ourselves, if they were MOVE_SEND. - -Fri Oct 28 18:37:56 1994 Roland McGrath <roland@churchy.gnu.ai.mit.edu> - - * start-trans.c: Change `assert (!err)' to `assert_perror (err)' - throughout. - (fshelp_start_translator): Add assert_perror for io_reauthenticate - return. - -Mon Sep 19 20:58:35 1994 Michael I Bushnell <mib@churchy.gnu.ai.mit.edu> - - * trans-iter.c (fshelp_translator_iterate): Bother to attach - ITEM onto LIST as it's constructed. - -Sat Sep 10 08:42:00 1994 Roland McGrath <roland@churchy.gnu.ai.mit.edu> - - * transboot-clean.c (fshelp_transboot_clean): Use EDIED, not EINVAL. - -Wed Sep 7 10:34:13 1994 Michael I Bushnell <mib@churchy.gnu.ai.mit.edu> - - * start-trans.c (fshelp_start_translator): RETRY label belongs - *after* initial lock of LINK. Unlock LINK before returning. - -Tue Sep 6 14:52:49 1994 Michael I Bushnell <mib@churchy.gnu.ai.mit.edu> - - * fshelp.h (struct trans_link): New member `lock'. - (fshelp_start_translator): Omit `lock' arg. - * trans.h (struct transboot): Omit member `lock'. - * init-trans.c (fshelp_init_trans_link): Initialize LINK->lock. - * start-trans.c (fshelp_start_translator): Don't set TB->lock. - Omit `lock' arg; use LINK->lock instead. - (fshelp_start_translator): Don't deallocate DIR. - * handle-startup.c (fshelp_handle_fsys_startup): Lock - TB->link->lock instead of TB->lock. - * transboot-clean.c (fshelp_transboot_clean): Likewise. - -Thu Sep 1 16:46:53 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> - - * fshelp.h (fshelp_start_translator): Doc fix. - * start-trans.c (fshelp_start_translator): Don't reauthenticate - NODE argument; expect fully authenticated node. - -Wed Aug 31 14:28:25 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> - - * start-trans.c (fshelp_start_translator): Before call to - proc_reauthenticate, CALL mach_reply_port, not just refer to - confusing CPP macro. - - * start-trans.c (fshelp_start_translator): Call proc_setowner - for new process. - -Tue Aug 30 16:19:45 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> - - * start-trans.c: Include <string.h>. - - * start-trans.c (fshelp_start_translator): Use new - reauthentication protocol throughout. - - * start-trans.c (fshelp_start_translator): Use - hurd_file_name_lookup instead of hurd_path_lookup. - -Wed Aug 17 16:03:49 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> - - * start-trans.c (fshelp_start_translator): Designate the new - process as our child; then make sure it's under its own - authentication. As long as we've gotten the proc port for - this operation, might as well pass it too. - (fshelp_start_translator): Zero init ints and init ports. - - * transboot-clean.c (fshelp_transboot_clean): Only set an error - if we haven't gotten fsys_startup yet. - -Mon Aug 15 12:24:47 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> - - * start-trans.c (fshelp_start_translator): Set LINK->starting - before blocking. - * handle-startup.c (fshelp_handle_fsys_startup): Clear - LINK->starting before waking up blocks. - - * fshelp.h (struct trans_link): New member `error'. - * transboot-clean.c (fshelp_transboot_clean): Wakeup blocked - users with error. - * trans-cntl.c (fshelp_set_control): Clear LINK->error. - * init-trans.c (fshelp_init_trans_link): Likewise. - - * start-trans.c (fshelp_start_translator): Fix - auth_user_authenticate to use the correct rendezvous port in - producing realnode from node.. - -Fri Jul 22 12:03:14 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> - - * Makefile: Rewritten in accord with new scheme. - -Wed Jul 20 13:31:39 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu> - - * start-trans.c (fshelp_start_translator): Missing first arg - to mach_port_deallocate of `dir'. - -Tue Jul 19 18:44:53 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) - - * fshelp.h (fshelp_start_translator): Doc fix. - (fshelp_handle_fsys_startup): Deleted dotdot args. - * trans.h (struct transboot): Removed member `dir'. - * start-trans.c (fshelp_start_translator): Don't initialize - TB->dir. - (fshelp_start_translator): Deallocate DIR arg when we're - done with it. - * handle-startup.c (fshelp_handle_fsys_startup): Deleted - dotdot args. - * transboot-clean.c (fshelp_transboot_clean): Don't free - no-longer-existent TB->dir. - -Fri Jul 8 12:58:54 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) - - * trans-cntl.c: Include <assert.h>. - -Thu Jul 7 18:08:49 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) - - * trans-drop.c: New file. - * fshelp.h (fshelp_translator_drop): New declaration. - * Makefile (OBJS): Added trans-drop.o. - (SRCS): ADded trans-drop.c. - -Tue Jul 5 14:14:53 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) - - * Makefile (DIST_FILES): New variable. - -Thu Jun 16 16:27:39 1994 Michael I Bushnell (mib@geech.gnu.ai.mit.edu) - - * fshelp.h (fshelp_get_node_port, fshelp_done_with_node): Deleted - prototypes. - (fshelp_start_translator): Changed types of DIR and NODE to be - file_t. - * trans.h (struct transboot): Deleted members UID and GID. - Changed types of DIR and NODE to be file_t. - * transboot-clean.c (fshelp_transboot_clean): Deallocate ports - TB->node and TB->dir instead of calling fshelp_done_with_node. - * start-trans.c (fshelp_start_translator): Changed types of - DIR and MODE to be file_t. Rewritten to behave correctly in - numerous ways. - * handle-startup.c (fshelp_handle_fsys_startup): Return REAL - and DIR from ports in TB instead of calling fshelp_get_node_port. - -Fri Jun 3 18:13:04 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu) - - * fshelp.h (fshelp_set_control): New declaration. - * trans-cntl.c: New file. - * Makefile (SRCS): Added trans-cntl.c. - (OBJS): Added trans-cntl.o. - trans-cntl.o: Depend on trans.h. - -Thu May 5 07:46:00 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) - - * Makefile: Change uses of $(headers) to $(includedir). - -Mon Feb 14 11:32:59 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) - - * Makefile (install): New target. - diff --git a/libfshelp/Makefile b/libfshelp/Makefile index ac2d0c9a..30879dc9 100644 --- a/libfshelp/Makefile +++ b/libfshelp/Makefile @@ -1,5 +1,5 @@ -# -# Copyright (C) 1994, 1995, 1996 Free Software Foundation +# +# Copyright (C) 1994, 95, 96, 98, 1999, 2006 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -22,17 +22,18 @@ libname = libfshelp SRCS = lock-acquire.c lock-init.c \ start-translator-long.c start-translator.c \ fetch-root.c transbox-init.c set-active.c fetch-control.c \ - drop-transbox.c \ + drop-transbox.c translated.c \ delegate.c \ exec-reauth.c \ set-options.c \ - return-buffer.c get-identity.c + get-identity.c \ + perms-isowner.c perms-iscontroller.c perms-access.c \ + perms-checkdirmod.c \ + touch.c LCLHDRS = fshelp.h locks.h trans.h installhdrs = fshelp.h +HURDLIBS = shouldbeinlibc threads iohelp ports OBJS = $(subst .c,.o,$(SRCS)) include ../Makeconf - -libfshelp.so: $(foreach lib,shouldbeinlibc threads,\ - ../lib$(lib)/lib$(lib).so) diff --git a/libfshelp/delegate.c b/libfshelp/delegate.c index cb8b8365..a44310f0 100644 --- a/libfshelp/delegate.c +++ b/libfshelp/delegate.c @@ -1,8 +1,7 @@ /* fshelp_delegate_translation - Copyright (C) 1995, 1996 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> + Copyright (C) 1995,96,99,2000,02 Free Software Foundation, Inc. + Written by Miles Bader <miles@gnu.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -30,7 +29,7 @@ ARGV is the command line. If SERVER_NAME is NULL, then a name is concocted by appending ARGV[0] to _SERVERS. */ error_t -fshelp_delegate_translation (char *server_name, +fshelp_delegate_translation (const char *server_name, mach_port_t requestor, char **argv) { error_t err; @@ -48,12 +47,15 @@ fshelp_delegate_translation (char *server_name, if (server != MACH_PORT_NULL) { char *argz; - int argz_len; + size_t argz_len; err = argz_create (argv, &argz, &argz_len); if (!err) - err = fsys_forward (server, - requestor, MACH_MSG_TYPE_COPY_SEND, - argz, argz_len); + { + err = fsys_forward (server, + requestor, MACH_MSG_TYPE_COPY_SEND, + argz, argz_len); + free (argz); + } } else err = errno; diff --git a/libfshelp/exec-reauth.c b/libfshelp/exec-reauth.c index e6009827..d9a82974 100644 --- a/libfshelp/exec-reauth.c +++ b/libfshelp/exec-reauth.c @@ -1,9 +1,9 @@ /* Setuid reauthentication for exec - Copyright (C) 1995, 1996 Free Software Foundation, Inc. + Copyright (C) 1995,96,97,2002 Free Software Foundation, Inc. - Written by Miles Bader <miles@gnu.ai.mit.edu>, - from the original by Michael I. Bushnell p/BSG <mib@gnu.ai.mit.edu> + Written by Miles Bader <miles@gnu.org>, + from the original by Michael I. Bushnell p/BSG <mib@gnu.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -83,7 +83,7 @@ fshelp_exec_reauth (int suid, uid_t uid, int sgid, gid_t gid, /* STEP 3: Attempt to create this new auth handle. */ err = auth_makeauth (auth, &ports[INIT_PORT_AUTH], - MACH_MSG_TYPE_COPY_SEND, 1, + MACH_MSG_TYPE_COPY_SEND, 1, eff_uids->ids, eff_uids->num, avail_uids->ids, avail_uids->num, eff_gids->ids, eff_gids->num, @@ -108,12 +108,12 @@ fshelp_exec_reauth (int suid, uid_t uid, int sgid, gid_t gid, if (suid && !err) err = idvec_setid (eff_uids, avail_uids, uid, &_secure); if (sgid && !err) - err = idvec_setid (eff_uids, avail_uids, gid, &_secure); + err = idvec_setid (eff_gids, avail_gids, gid, &_secure); if (err) goto abandon_suid; /* Trrrry again... */ - err = auth_makeauth (auth, 0, MACH_MSG_TYPE_COPY_SEND, 1, + err = auth_makeauth (auth, 0, MACH_MSG_TYPE_COPY_SEND, 1, eff_uids->ids, eff_uids->num, avail_uids->ids, avail_uids->num, eff_gids->ids, eff_gids->num, @@ -130,8 +130,9 @@ fshelp_exec_reauth (int suid, uid_t uid, int sgid, gid_t gid, /* Re-authenticate the exec parameters. */ exec_reauth (newauth, _secure, 0, ports, num_ports, fds, num_fds); - if (eff_uids->num > 0) - proc_setowner (ports[INIT_PORT_PROC], eff_uids->ids[0], 0); + proc_setowner (ports[INIT_PORT_PROC], + eff_uids->num > 0 ? eff_uids->ids[0] : 0, + !eff_uids->num); abandon_suid: if (eff_uids) @@ -144,7 +145,7 @@ fshelp_exec_reauth (int suid, uid_t uid, int sgid, gid_t gid, idvec_free (avail_gids); } - if (_secure && secure) + if (secure) *secure = _secure; return err; diff --git a/libfshelp/fetch-root.c b/libfshelp/fetch-root.c index b38b276d..54d3c0ca 100644 --- a/libfshelp/fetch-root.c +++ b/libfshelp/fetch-root.c @@ -1,5 +1,5 @@ -/* - Copyright (C) 1995, 1996 Free Software Foundation, Inc. +/* + Copyright (C) 1995,96,99,2000,02 Free Software Foundation, Inc. Written by Michael I. Bushnell. This file is part of the GNU Hurd. @@ -27,19 +27,18 @@ error_t fshelp_fetch_root (struct transbox *box, void *cookie, file_t dotdot, - uid_t *uids, int uids_len, - uid_t *gids, int gids_len, + struct iouser *user, int flags, fshelp_fetch_root_callback1_t callback1, fshelp_fetch_root_callback2_t callback2, - retry_type *retry, char *retryname, + retry_type *retry, char *retryname, file_t *root) { error_t err; mach_port_t control; int cancel; int i; - + start_over: if (box->active != MACH_PORT_NULL) @@ -48,50 +47,51 @@ fshelp_fetch_root (struct transbox *box, void *cookie, { uid_t uid, gid; char *argz; - int argz_len; + size_t argz_len; error_t err; mach_port_t ports[INIT_PORT_MAX]; int ints[INIT_INT_MAX]; mach_port_t fds[STDERR_FILENO + 1]; auth_t ourauth, newauth; - int uidarray[2], gidarray[2]; - - mach_port_t - reauth (mach_port_t port, mach_msg_type_name_t port_type) - { - mach_port_t rend, ret; - error_t err; - - if (port == MACH_PORT_NULL) - return port; - - if (port_type == MACH_MSG_TYPE_MAKE_SEND) - mach_port_insert_right (mach_task_self (), port, port,port_type); - - rend = mach_reply_port (); - - err = io_reauthenticate (port, rend, - MACH_MSG_TYPE_MAKE_SEND); - if (! err) - err = auth_user_authenticate (newauth, rend, - MACH_MSG_TYPE_MAKE_SEND, &ret); - if (err) - ret = MACH_PORT_NULL; - - mach_port_destroy (mach_task_self (), rend); - if (!err && port_type != MACH_MSG_TYPE_COPY_SEND) - mach_port_deallocate (mach_task_self (), port); - - return ret; - } + + mach_port_t reauth (mach_port_t port) /* Consumes PORT. */ + { + mach_port_t rend, ret; + error_t err; + + if (port == MACH_PORT_NULL) + return port; + + if (ourauth == MACH_PORT_NULL) + /* We have no auth server, so we aren't doing reauthentications. + Just pass on our own ports directly. */ + return port; + + rend = mach_reply_port (); + + /* MAKE_SEND is safe here because we destroy REND ourselves. */ + err = io_reauthenticate (port, rend, + MACH_MSG_TYPE_MAKE_SEND); + mach_port_deallocate (mach_task_self (), port); + if (! err) + err = auth_user_authenticate (newauth, rend, + MACH_MSG_TYPE_MAKE_SEND, &ret); + if (err) + ret = MACH_PORT_NULL; + + mach_port_destroy (mach_task_self (), rend); + + return ret; + } error_t fetch_underlying (int flags, mach_port_t *underlying, - mach_msg_type_name_t *underlying_type) + mach_msg_type_name_t *underlying_type, + task_t task, void *cookie) { return (*callback2) (box->cookie, cookie, flags, underlying, underlying_type); } - + if (box->flags & TRANSBOX_STARTING) { box->flags |= TRANSBOX_WANTED; @@ -102,50 +102,57 @@ fshelp_fetch_root (struct transbox *box, void *cookie, } box->flags |= TRANSBOX_STARTING; mutex_unlock (box->lock); - + err = (*callback1) (box->cookie, cookie, &uid, &gid, &argz, &argz_len); if (err) goto return_error; - + ourauth = getauth (); - uidarray[0] = uidarray[1] = uid; - gidarray[0] = gidarray[1] = gid; - err = auth_makeauth (ourauth, 0, MACH_MSG_TYPE_MAKE_SEND, 0, - uidarray, 1, uidarray, 2, - gidarray, 1, gidarray, 2, &newauth); - if (err) - goto return_error; - + if (ourauth == MACH_PORT_NULL) + newauth = ourauth; + else + { + uid_t uidarray[2] = { uid, uid }; + gid_t gidarray[2] = { gid, gid }; + err = auth_makeauth (ourauth, 0, MACH_MSG_TYPE_COPY_SEND, 0, + uidarray, 1, uidarray, 2, + gidarray, 1, gidarray, 2, &newauth); + if (err) + goto return_error; + } + bzero (ports, INIT_PORT_MAX * sizeof (mach_port_t)); bzero (fds, (STDERR_FILENO + 1) * sizeof (mach_port_t)); bzero (ints, INIT_INT_MAX * sizeof (int)); - - 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_CWDIR] = dotdot; + ports[INIT_PORT_CRDIR] = reauth (getcrdir ()); ports[INIT_PORT_AUTH] = newauth; - - fds[STDERR_FILENO] = - reauth (getdport (STDERR_FILENO), MACH_MSG_TYPE_MOVE_SEND); - - err = fshelp_start_translator_long (fetch_underlying, + + fds[STDERR_FILENO] = reauth (getdport (STDERR_FILENO)); + + err = fshelp_start_translator_long (fetch_underlying, NULL, argz, argz, argz_len, fds, MACH_MSG_TYPE_COPY_SEND, STDERR_FILENO + 1, ports, MACH_MSG_TYPE_COPY_SEND, - INIT_PORT_MAX, + INIT_PORT_MAX, ints, INIT_INT_MAX, + uid, 0, &control); for (i = 0; i <= STDERR_FILENO; i++) mach_port_deallocate (mach_task_self (), fds[i]); + for (i = 0; i < INIT_PORT_MAX; i++) - mach_port_deallocate (mach_task_self (), ports[i]); - + if (i != INIT_PORT_CWDIR) + mach_port_deallocate (mach_task_self (), ports[i]); + mutex_lock (box->lock); - + free (argz); return_error: - + box->flags &= ~TRANSBOX_STARTING; if (box->flags & TRANSBOX_WANTED) { @@ -162,19 +169,20 @@ fshelp_fetch_root (struct transbox *box, void *cookie, box->active = control; } - + control = box->active; - mach_port_mod_refs (mach_task_self (), control, + mach_port_mod_refs (mach_task_self (), control, MACH_PORT_RIGHT_SEND, 1); mutex_unlock (box->lock); - + /* Cancellation point XXX */ err = fsys_getroot (control, dotdot, MACH_MSG_TYPE_COPY_SEND, - uids, uids_len, gids, gids_len, flags, - retry, retryname, root); - + user->uids->ids, user->uids->num, + user->gids->ids, user->gids->num, + flags, retry, retryname, root); + mutex_lock (box->lock); - + if ((err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED) && control == box->active) fshelp_set_active (box, MACH_PORT_NULL, 0); @@ -182,9 +190,6 @@ fshelp_fetch_root (struct transbox *box, void *cookie, if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED) goto start_over; - + return err; } - - - diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h index 9461ae50..9f4fa677 100644 --- a/libfshelp/fshelp.h +++ b/libfshelp/fshelp.h @@ -1,5 +1,5 @@ /* FS helper library definitions - Copyright (C) 1994, 1995, 1996 Free Software Foundation + Copyright (C) 1994,95,96,97,98,99,2000,01,02 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ #define _HURD_FSHELP_ /* This library implements various things that are generic to - all or most implementors of the filesystem protocol. It + all or most implementors of the filesystem protocol. It presumes that you are using the iohelp library as well. It is divided into separate facilities which may be used independently. */ @@ -27,6 +27,9 @@ #include <mach.h> #include <hurd/hurd_types.h> #include <cthreads.h> +#include <hurd/iohelp.h> +#include <sys/stat.h> +#include <maptime.h> /* Passive translator linkage */ @@ -35,11 +38,12 @@ or the ports library. */ /* A callback used by the translator starting functions, which should be a - function that given some open flags, opens the appropiate file, and + function that given some open flags, opens the appropriate file, and returns the node port. */ typedef error_t (*fshelp_open_fn_t) (int flags, file_t *node, - mach_msg_type_name_t *node_type); + mach_msg_type_name_t *node_type, + task_t, void *cookie); /* Start a passive translator NAME with arguments ARGZ (length ARGZ_LEN). Initialize the initports to PORTS (length PORTS_LEN), @@ -47,15 +51,18 @@ typedef error_t (*fshelp_open_fn_t) (int flags, table to FDS (length FDS_LEN). Return the control port in *CONTROL. If the translator doesn't respond or die in TIMEOUT milliseconds (if TIMEOUT > 0), return an appropriate error. If the - translator dies before responding, return EDIED. */ + translator dies before responding, return EDIED. Set the new + task's owner to OWNER_UID (or, if OWNER_UID is -1, then clear the + new task's owner. */ error_t -fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, +fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, void *cookie, char *name, char *argz, int argz_len, - mach_port_t *fds, + mach_port_t *fds, mach_msg_type_name_t fds_type, int fds_len, - mach_port_t *ports, + mach_port_t *ports, mach_msg_type_name_t ports_type, int ports_len, int *ints, int ints_len, + uid_t owner_uid, int timeout, fsys_t *control); @@ -63,7 +70,7 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, are copied from our own state, fd[2] is copied from our own stderr, and the other fds are cleared. */ error_t -fshelp_start_translator (fshelp_open_fn_t underlying_open_fn, +fshelp_start_translator (fshelp_open_fn_t underlying_open_fn, void *cookie, char *name, char *argz, int argz_len, int timeout, fsys_t *control); @@ -75,7 +82,7 @@ fshelp_start_translator (fshelp_open_fn_t underlying_open_fn, use the passive translator routines above, but they don't require the ports library at all. */ -struct transbox +struct transbox { fsys_t active; struct mutex *lock; @@ -98,8 +105,8 @@ struct transbox then return ENOENT. COOKIE1 is the cookie passed in fshelp_transbox_init. COOKIE2 is the cookie passed in the call to fshelp_fetch_root. */ typedef error_t (*fshelp_fetch_root_callback1_t) (void *cookie1, void *cookie2, - uid_t *uid, gid_t *gid, - char **argz, int *argz_len); + uid_t *uid, gid_t *gid, + char **argz, size_t *argz_len); /* This routine is called by fshelp_fetch_root to fetch more information. Return an unauthenticated node for the file itself in *UNDERLYING and @@ -113,18 +120,16 @@ typedef error_t (*fshelp_fetch_root_callback2_t) (void *cookie1, void *cookie2, *underlying_type); /* Fetch the root from TRANSBOX. DOTDOT is an unauthenticated port - for the directory in which we are looking; UIDS (length UIDS_LEN) - and GIDS (length GIDS_LEN) are the ids of the user responsible for - the call. FLAGS are as for dir_pathtrans (but O_CREAT and O_EXCL - are not meaningful and are ignored). The trasnbox lock (as - set by fshelp_transbox_init) must be held before the call, and will - be held upon return, but may be released during the operation of - the call. */ + for the directory in which we are looking; USER specifies the ids + of the user responsible for the call. FLAGS are as for dir_lookup + (but O_CREAT and O_EXCL are not meaningful and are ignored). The + transbox lock (as set by fshelp_transbox_init) must be held before + the call, and will be held upon return, but may be released during + the operation of the call. */ error_t fshelp_fetch_root (struct transbox *transbox, void *cookie, - file_t dotdot, - uid_t *uids, int uids_len, - uid_t *gids, int gids_len, + file_t dotdot, + struct iouser *user, int flags, fshelp_fetch_root_callback1_t callback1, fshelp_fetch_root_callback2_t callback2, @@ -136,11 +141,7 @@ fshelp_transbox_init (struct transbox *transbox, void *cookie); /* Return true iff there is an active translator on this box */ -extern inline int -fshelp_translated (struct transbox *box) -{ - return (box->active != MACH_PORT_NULL); -} +int fshelp_translated (struct transbox *box); /* Atomically replace the existing active translator port for this box with NEWACTIVE. If EXCL is non-zero then don't frob an existing @@ -171,11 +172,11 @@ struct lock_box There should be one lock box per object and one int per open; these are passed as arguments BOX and USER respectively. FLAGS are as per file_lock. MUT is a mutex which will be held whenever this - routine is called, to lock BOX->wait. */ -error_t fshelp_acquire_lock (struct lock_box *box, int *user, + routine is called, to lock BOX->wait. */ +error_t fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut, int flags); - + /* Initialize lock_box BOX. (The user int passed to fshelp_acquire_lock should be initialized with LOCK_UN.). */ void fshelp_lock_init (struct lock_box *box); @@ -193,7 +194,7 @@ struct port_bucket; /* shut up C compiler */ notifications) are used. */ error_t fshelp_get_identity (struct port_bucket *bucket, - ino_t fileno, mach_port_t *pt); + ino64_t fileno, mach_port_t *pt); @@ -201,7 +202,7 @@ error_t fshelp_get_identity (struct port_bucket *bucket, the node SERVER_NAME. REQUESTOR is the translator's bootstrap port, and ARGV is the command line. If SERVER_NAME is NULL, then a name is concocted by appending ARGV[0] to _SERVERS. */ -error_t fshelp_delegate_translation (char *server_name, +error_t fshelp_delegate_translation (const char *server_name, mach_port_t requestor, char **argv); struct idvec; /* Include <idvec.h> to get the real thing. */ @@ -227,13 +228,44 @@ struct argp; /* Include <argp.h> to get the real thing. */ /* Invoke ARGP with data from DATA & LEN, in the standard way. */ error_t fshelp_set_options (struct argp *argp, int flags, - char *argz, size_t argz_len, void *input); + const char *argz, size_t argz_len, void *input); + -/* Puts data from the malloced buffer BUF, LEN bytes long, into RBUF & RLEN, - suitable for returning from a mach rpc. If LEN > 0, BUF is freed, - regardless of whether an error is returned or not. */ -error_t fshelp_return_malloced_buffer (char *buf, size_t len, - char **rbuf, - mach_msg_type_number_t *rlen); +/* Standardized filesystem permission checking */ +/* Check to see whether USER should be considered the owner of the + file identified by ST. If so, return zero; otherwise return an + appropriate error code. */ +error_t fshelp_isowner (io_statbuf_t *st, struct iouser *user); + +/* Check to see whether USER should be considered a controller of the + filesystem. Which is to say, check to see if we should give USER the + control port. ST is the stat of the root node. USER is the user + asking for a send right to the control port. */ +error_t +fshelp_iscontroller (io_statbuf_t *st, struct iouser *user); + +/* Check to see whether the user USER can operate on a file identified + by ST. OP is one of S_IREAD, S_IWRITE, and S_IEXEC. If the access + is permitted, return zero; otherwise return an appropriate error + code. */ +error_t fshelp_access (io_statbuf_t *st, int op, struct iouser *user); + +/* Check to see whether USER is allowed to modify DIR with respect to + existing file ST. (If there is no existing file, pass 0 for ST.) + If the access is permissible return 0; otherwise return an + appropriate error code. */ +error_t fshelp_checkdirmod (io_statbuf_t *dir, io_statbuf_t *st, + struct iouser *user); + + +/* Timestamps to change. */ +#define TOUCH_ATIME 0x1 +#define TOUCH_MTIME 0x2 +#define TOUCH_CTIME 0x4 + +/* Change the stat times of NODE as indicated by WHAT (from the set TOUCH_*) + to the current time. */ +void fshelp_touch (io_statbuf_t *st, unsigned what, + volatile struct mapped_time_value *maptime); #endif diff --git a/libfshelp/get-identity.c b/libfshelp/get-identity.c index 05d76491..51c5fb29 100644 --- a/libfshelp/get-identity.c +++ b/libfshelp/get-identity.c @@ -1,5 +1,5 @@ /* Helper function for io_identity - Copyright (C) 1996 Free Software Foundation, Inc. + Copyright (C) 1996, 1999 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -26,7 +26,7 @@ static struct port_class *idclass = 0; static struct mutex idlock = MUTEX_INITIALIZER; -struct idspec +struct idspec { struct port_info pi; ino_t fileno; @@ -50,7 +50,7 @@ fshelp_get_identity (struct port_bucket *bucket, error_t check_port (void *arg) { struct idspec *i = arg; - if (i->pi.class == idclass && i->fileno == fileno) + if (i->fileno == fileno) { *pt = ports_get_right (i); return 1; @@ -64,15 +64,15 @@ fshelp_get_identity (struct port_bucket *bucket, id_initialize (); *pt = MACH_PORT_NULL; - - ports_bucket_iterate (bucket, check_port); + + ports_class_iterate (idclass, check_port); if (*pt != MACH_PORT_NULL) { mutex_unlock (&idlock); return 0; } - + err = ports_create_port (idclass, bucket, sizeof (struct idspec), &i); if (err) { @@ -80,11 +80,9 @@ fshelp_get_identity (struct port_bucket *bucket, return err; } i->fileno = fileno; - + *pt = ports_get_right (i); ports_port_deref (i); mutex_unlock (&idlock); return 0; } - - diff --git a/libfshelp/lock-acquire.c b/libfshelp/lock-acquire.c index 9c81634a..bad1114d 100644 --- a/libfshelp/lock-acquire.c +++ b/libfshelp/lock-acquire.c @@ -42,9 +42,11 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut, if (flags & LOCK_UN) { if (*user & LOCK_UN) - return EBADF; + return 0; + assert (*user == box->type); assert (*user == LOCK_SH || *user == LOCK_EX); + if (*user == LOCK_SH) { if (!--box->shcount) @@ -80,7 +82,8 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut, if (flags & LOCK_NB) return EWOULDBLOCK; box->waiting = 1; - condition_wait (&box->wait, mut); + if (hurd_condition_wait (&box->wait, mut)) + return EINTR; } /* If we have a shared lock, release it. */ @@ -108,15 +111,16 @@ fshelp_acquire_lock (struct lock_box *box, int *user, struct mutex *mut, } else if (flags & LOCK_EX) { - /* Wait for any shared locks to finish. */ - while (box->type == LOCK_SH) + /* Wait for any shared (and exclusive) locks to finish. */ + while (box->type != LOCK_UN) { if (flags & LOCK_NB) return EWOULDBLOCK; else { box->waiting = 1; - condition_wait (&box->wait, mut); + if (hurd_condition_wait (&box->wait, mut)) + return EINTR; } } box->type = LOCK_EX; diff --git a/libfshelp/perms-access.c b/libfshelp/perms-access.c new file mode 100644 index 00000000..67e52812 --- /dev/null +++ b/libfshelp/perms-access.c @@ -0,0 +1,43 @@ +/* + Copyright (C) 1999 Free Software Foundation, Inc. + Written by Thomas Bushnell, BSG. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + + +#include "fshelp.h" + +/* Check to see whether the user USER can operate on a file identified + by ST. OP is one of S_IREAD, S_IWRITE, and S_IEXEC. If the access + is permitted, return zero; otherwise return an appropriate error + code. */ +error_t +fshelp_access (struct stat *st, int op, struct iouser *user) +{ + int gotit; + if (idvec_contains (user->uids, 0)) + gotit = (op != S_IEXEC) || !S_ISREG(st->st_mode) || (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)); + else if (user->uids->num == 0 && (st->st_mode & S_IUSEUNK)) + gotit = st->st_mode & (op << S_IUNKSHIFT); + else if (!fshelp_isowner (st, user)) + gotit = st->st_mode & op; + else if (idvec_contains (user->gids, st->st_gid)) + gotit = st->st_mode & (op >> 3); + else + gotit = st->st_mode & (op >> 6); + return gotit ? 0 : EACCES; +} diff --git a/libfshelp/perms-checkdirmod.c b/libfshelp/perms-checkdirmod.c new file mode 100644 index 00000000..823c9f63 --- /dev/null +++ b/libfshelp/perms-checkdirmod.c @@ -0,0 +1,44 @@ +/* + Copyright (C) 1999 Free Software Foundation, Inc. + Written by Thomas Bushnell, BSG. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + + +#include "fshelp.h" + +/* Check to see whether USER is allowed to modify DIR with respect to + existing file ST. (If there is no existing file, pass 0 for ST.) + If the access is permissible return 0; otherwise return an + appropriate error code. */ +error_t +fshelp_checkdirmod (struct stat *dir, struct stat *st, struct iouser *user) +{ + error_t err; + + /* The user must be able to write the directory. */ + err = fshelp_access (dir, S_IWRITE, user); + if (err) + return err; + + /* If the directory is sticky, the user must own either it or the file. */ + if ((dir->st_mode & S_ISVTX) && st + && fshelp_isowner (dir, user) && fshelp_isowner (st, user)) + return EACCES; + + return 0; +} diff --git a/libfshelp/perms-iscontroller.c b/libfshelp/perms-iscontroller.c new file mode 100644 index 00000000..0adfdf22 --- /dev/null +++ b/libfshelp/perms-iscontroller.c @@ -0,0 +1,38 @@ +/* see whether a user should be considered a controller of the filesystem + Copyright (C) 2001, 2008 Free Software Foundation, Inc. + Written by Neal H Walfield <neal@cs.uml.edu>. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include <unistd.h> +#include "fshelp.h" + +/* Check to see whether USER should be considered a controller of the + filesystem. Which is to say, check to see if we should give USER the + control port. ST is the stat of the root node. USER is the user + asking for a send right to the control port. */ +error_t +fshelp_iscontroller (struct stat *st, struct iouser *user) +{ + /* Permitted if USER has the superuser uid, the owner uid or if the + USER has authority over the process's effective id. */ + if (idvec_contains (user->uids, 0) + || idvec_contains (user->uids, st->st_uid) + || idvec_contains (user->uids, geteuid ())) + return 0; + return EPERM; +} diff --git a/libfshelp/perms-isowner.c b/libfshelp/perms-isowner.c new file mode 100644 index 00000000..d1975993 --- /dev/null +++ b/libfshelp/perms-isowner.c @@ -0,0 +1,39 @@ +/* + Copyright (C) 1999 Free Software Foundation, Inc. + Written by Thomas Bushnell, BSG. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "fshelp.h" + +/* Check to see whether USER should be considered the owner of the + file identified by ST. If so, return zero; otherwise return an + appropriate error code. */ +error_t +fshelp_isowner (struct stat *st, struct iouser *user) +{ + /* Permitted if the user has the owner UID, the superuser UID, or if + the user is in the group of the file and has the group ID as + their user ID. */ + if (idvec_contains (user->uids, st->st_uid) + || idvec_contains (user->uids, 0) + || (idvec_contains (user->gids, st->st_gid) + && idvec_contains (user->uids, st->st_gid))) + return 0; + else + return EPERM; +} diff --git a/libfshelp/return-buffer.c b/libfshelp/return-buffer.c deleted file mode 100644 index 58c704f3..00000000 --- a/libfshelp/return-buffer.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Make a malloced buffer suitable for returning from a mach rpc - - Copyright (C) 1996 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - The GNU Hurd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <string.h> -#include <mach.h> - -#include "fshelp.h" - -/* Puts data from the malloced buffer BUF, LEN bytes long, into RBUF & RLEN, - suitable for returning from a mach rpc. If LEN > 0, BUF is freed, - regardless of whether an error is returned or not. */ -error_t -fshelp_return_malloced_buffer (char *buf, size_t len, - char **rbuf, mach_msg_type_number_t *rlen) -{ - error_t err = 0; - - if (*rlen < len) - err = vm_allocate (mach_task_self (), (vm_address_t *)rbuf, len, 1); - if (! err) - { - if (len) - bcopy (buf, *rbuf, len); - *rlen = len; - } - - if (len > 0) - free (buf); - - return err; -} diff --git a/libfshelp/set-options.c b/libfshelp/set-options.c index ba1e50d5..13e4001f 100644 --- a/libfshelp/set-options.c +++ b/libfshelp/set-options.c @@ -1,6 +1,6 @@ /* Standard filesystem runtime option parsing - Copyright (C) 1996 Free Software Foundation, Inc. + Copyright (C) 1996, 1998, 1999 Free Software Foundation, Inc. Written by Miles Bader <miles@gnu.ai.mit.edu> @@ -32,12 +32,12 @@ /* Invoke ARGP with data from DATA & LEN, in the standard way. */ error_t fshelp_set_options (struct argp *argp, int flags, - char *argz, size_t argz_len, void *input) + const char *argz, size_t argz_len, void *input) { int argc = argz_count (argz, argz_len); char **argv = alloca (sizeof (char *) * (argc + 1)); - argz_extract (argz, argz_len, argv); + argz_extract ((char *) argz, argz_len, argv); return argp_parse (argp, argc, argv, diff --git a/libfshelp/start-translator-long.c b/libfshelp/start-translator-long.c index 34202f43..5bf14541 100644 --- a/libfshelp/start-translator-long.c +++ b/libfshelp/start-translator-long.c @@ -1,5 +1,5 @@ -/* - Copyright (C) 1995, 1996 Free Software Foundation, Inc. +/* + Copyright (C) 1995,96,99,2000,02, 04 Free Software Foundation, Inc. Written by Miles Bader and Michael I. Bushnell. This file is part of the GNU Hurd. @@ -48,67 +48,79 @@ struct fsys_startup_reply mach_port_t realnode; }; -static const mach_msg_type_t flagsCheck = { - MACH_MSG_TYPE_INTEGER_32, /* msgt_name = */ - 32, /* msgt_size = */ - 1, /* msgt_number = */ - TRUE, /* msgt_inline = */ - FALSE, /* msgt_longform = */ - FALSE, /* msgt_deallocate = */ - 0 /* msgt_unused = */ -}; - -static const mach_msg_type_t control_portCheck = -{ - 17, /* msgt_name = */ - 32, /* msgt_size = */ - 1, /* msgt_number = */ - TRUE, /* msgt_inline = */ - FALSE, /* msgt_longform = */ - FALSE, /* msgt_deallocate = */ - 0 /* msgt_unused = */ -}; - -static const mach_msg_type_t RetCodeType = { - MACH_MSG_TYPE_INTEGER_32, /* msgt_name = */ - 32, /* msgt_size = */ - 1, /* msgt_number = */ - TRUE, /* msgt_inline = */ - FALSE, /* msgt_longform = */ - FALSE, /* msgt_deallocate = */ - 0 /* msgt_unused = */ -}; - -static const mach_msg_type_t realnodeType = -{ - -1, /* msgt_name = */ - 32, /* msgt_size = */ - 1, /* msgt_number = */ - TRUE, /* msgt_inline = */ - FALSE, /* msgt_longform = */ - FALSE, /* msgt_deallocate = */ - 0 /* msgt_unused = */ -}; - - /* Wait around for an fsys_startup message on the port PORT from the translator on NODE (timing out after TIMEOUT milliseconds), and return a - send right for the resulting fsys control port in CONTROL. If a dead-name + send right for the resulting fsys control port in CONTROL. If a no-senders notification is received on PORT, then it will be assumed that the translator died, and EDIED will be returned. If an error occurs, the error code is returned, otherwise 0. */ static error_t -service_fsys_startup (fshelp_open_fn_t underlying_open_fn, - mach_port_t port, long timeout, - fsys_t *control) +service_fsys_startup (fshelp_open_fn_t underlying_open_fn, void *cookie, + mach_port_t port, long timeout, fsys_t *control, + task_t task) { - error_t err; - union + /* These should be optimized away to pure integer constants. */ + const mach_msg_type_t flagsCheck = + { + MACH_MSG_TYPE_INTEGER_32, /* msgt_name = */ + 32, /* msgt_size = */ + 1, /* msgt_number = */ + TRUE, /* msgt_inline = */ + FALSE, /* msgt_longform = */ + FALSE, /* msgt_deallocate = */ + 0 /* msgt_unused = */ + }; + const mach_msg_type_t control_portCheck = { - mach_msg_header_t head; - struct fsys_startup_request startup; - mach_dead_name_notification_t dead; + MACH_MSG_TYPE_PORT_SEND, /* msgt_name = */ + 32, /* msgt_size = */ + 1, /* msgt_number = */ + TRUE, /* msgt_inline = */ + FALSE, /* msgt_longform = */ + FALSE, /* msgt_deallocate = */ + 0 /* msgt_unused = */ + }; + const mach_msg_type_t RetCodeType = + { + MACH_MSG_TYPE_INTEGER_32, /* msgt_name = */ + 32, /* msgt_size = */ + 1, /* msgt_number = */ + TRUE, /* msgt_inline = */ + FALSE, /* msgt_longform = */ + FALSE, /* msgt_deallocate = */ + 0 /* msgt_unused = */ + }; + const mach_msg_type_t realnodeType = + { + -1, /* msgt_name = */ + 32, /* msgt_size = */ + 1, /* msgt_number = */ + TRUE, /* msgt_inline = */ + FALSE, /* msgt_longform = */ + FALSE, /* msgt_deallocate = */ + 0 /* msgt_unused = */ + }; + + /* Return true iff TYPE fails to match CHECK. */ + inline int type_check (const mach_msg_type_t *type, + const mach_msg_type_t *check) + { + union + { + unsigned32_t word; + mach_msg_type_t type; + } t, c; + t.type = *type; + c.type = *check; + return t.word != c.word; } + + error_t err; + union + { + mach_msg_header_t head; + struct fsys_startup_request startup; + } request; struct fsys_startup_reply reply; @@ -119,7 +131,7 @@ service_fsys_startup (fshelp_open_fn_t underlying_open_fn, if (err) return err; - /* Check whether we actually got a dead-name notification instead. */ + /* Check whether we actually got a no-senders notification instead. */ if (request.head.msgh_id == MACH_NOTIFY_NO_SENDERS) return EDIED; @@ -135,9 +147,8 @@ service_fsys_startup (fshelp_open_fn_t underlying_open_fn, if (request.head.msgh_id != 22000) reply.RetCode = MIG_BAD_ID; - else if ((*(int *)&request.startup.control_portType - != *(int *)&control_portCheck) - || (*(int *)&request.startup.flagsType != *(int *)&flagsCheck)) + else if (type_check (&request.startup.control_portType, &control_portCheck) + || type_check (&request.startup.flagsType, &flagsCheck)) reply.RetCode = MIG_BAD_ARGUMENTS; else { @@ -147,7 +158,8 @@ service_fsys_startup (fshelp_open_fn_t underlying_open_fn, reply.RetCode = (*underlying_open_fn) (request.startup.flags, - &reply.realnode, &realnode_type); + &reply.realnode, &realnode_type, task, + cookie); reply.realnodeType = realnodeType; reply.realnodeType.msgt_name = realnode_type; @@ -161,6 +173,11 @@ service_fsys_startup (fshelp_open_fn_t underlying_open_fn, sizeof(reply), 0, request.head.msgh_remote_port, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + if (err == MACH_SEND_INTERRUPTED + && reply.realnodeType.msgt_name == MACH_MSG_TYPE_MOVE_SEND) + /* For MACH_SEND_INTERRUPTED, we'll have pseudo-received the message + and might have to clean up a generated send right. */ + mach_port_deallocate (mach_task_self (), reply.realnode); if (reply.RetCode) /* Make our error return be the earlier one. */ @@ -172,19 +189,20 @@ service_fsys_startup (fshelp_open_fn_t underlying_open_fn, error_t fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, - char *name, char *argz, int argz_len, - mach_port_t *fds, + void *cookie, char *name, char *argz, + int argz_len, mach_port_t *fds, mach_msg_type_name_t fds_type, int fds_len, mach_port_t *ports, mach_msg_type_name_t ports_type, int ports_len, int *ints, int ints_len, + uid_t owner_uid, int timeout, fsys_t *control) { error_t err; file_t executable; mach_port_t bootstrap = MACH_PORT_NULL; mach_port_t task = MACH_PORT_NULL; - mach_port_t prev_notify, proc, saveport; + mach_port_t prev_notify, proc, saveport, childproc; int ports_moved = 0; /* Find the translator itself. Since argz has zero-separated elements, we @@ -192,7 +210,7 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, executable = file_name_lookup(name, O_EXEC, 0); if (executable == MACH_PORT_NULL) return errno; - + /* Create a bootstrap port for the translator. */ err = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &bootstrap); @@ -200,15 +218,26 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, goto lose; /* Create the task for the translator. */ - err = task_create (mach_task_self (), 0, &task); + err = task_create (mach_task_self (), +#ifdef KERN_INVALID_LEDGER + NULL, 0, /* OSF Mach */ +#endif + 0, &task); if (err) goto lose; - /* Designate TASK as our child. */ + /* Designate TASK as our child and set it's owner accordingly. */ proc = getproc (); proc_child (proc, task); + err = proc_task2proc (proc, task, &childproc); mach_port_deallocate (mach_task_self (), proc); - + if (err) + goto lose; + err = proc_setowner (childproc, owner_uid, owner_uid == (uid_t) -1); + mach_port_deallocate (mach_task_self (), childproc); + if (err) + goto lose; + assert (ports_len > INIT_PORT_BOOTSTRAP); switch (ports_type) { @@ -264,13 +293,14 @@ fshelp_start_translator_long (fshelp_open_fn_t underlying_open_fn, /* Ok, cool, we've got a running(?) program, now rendezvous with it if possible using the startup protocol on the bootstrap port... */ - err = service_fsys_startup(underlying_open_fn, bootstrap, timeout, control); + err = service_fsys_startup(underlying_open_fn, cookie, bootstrap, + timeout, control, task); lose: if (!ports_moved) { int i; - + if (fds_type == MACH_MSG_TYPE_MOVE_SEND) for (i = 0; i < fds_len; i++) mach_port_deallocate (mach_task_self (), fds[i]); diff --git a/libfshelp/start-translator.c b/libfshelp/start-translator.c index f5cc4072..ba5418ec 100644 --- a/libfshelp/start-translator.c +++ b/libfshelp/start-translator.c @@ -1,5 +1,5 @@ -/* - Copyright (C) 1995, 1996 Free Software Foundation, Inc. +/* + Copyright (C) 1995, 1996, 1999 Free Software Foundation, Inc. Written by Michael I. Bushnell. This file is part of the GNU Hurd. @@ -25,33 +25,34 @@ error_t fshelp_start_translator (fshelp_open_fn_t underlying_open_fn, - char *name, char *argz, int argz_len, - int timeout, fsys_t *control) + void *cookie, char *name, char *argz, + int argz_len, int timeout, fsys_t *control) { mach_port_t ports[INIT_PORT_MAX]; mach_port_t fds[STDERR_FILENO + 1]; int ints[INIT_INT_MAX]; int i; error_t err; - + for (i = 0; i < INIT_PORT_MAX; i++) ports[i] = MACH_PORT_NULL; for (i = 0; i < STDERR_FILENO + 1; i++) fds[i] = MACH_PORT_NULL; bzero (ints, INIT_INT_MAX * sizeof (int)); - + ports[INIT_PORT_CWDIR] = getcwdir (); ports[INIT_PORT_CRDIR] = getcrdir (); ports[INIT_PORT_AUTH] = getauth (); fds[STDERR_FILENO] = getdport (STDERR_FILENO); - - err = fshelp_start_translator_long (underlying_open_fn, + + err = fshelp_start_translator_long (underlying_open_fn, cookie, name, argz, argz_len, fds, MACH_MSG_TYPE_COPY_SEND, STDERR_FILENO + 1, ports, MACH_MSG_TYPE_COPY_SEND, INIT_PORT_MAX, ints, INIT_INT_MAX, + geteuid (), timeout, control); for (i = 0; i < INIT_PORT_MAX; i++) mach_port_deallocate (mach_task_self (), ports[i]); diff --git a/libfshelp/touch.c b/libfshelp/touch.c new file mode 100644 index 00000000..00d90edd --- /dev/null +++ b/libfshelp/touch.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 1999, 2007 Free Software Foundation, Inc. + + Written by Thomas Bushnell, BSG. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "fshelp.h" + +/* Change the stat times of NODE as indicated by WHAT (from the set TOUCH_*) + to the current time. */ +void +fshelp_touch (struct stat *st, unsigned what, + volatile struct mapped_time_value *maptime) +{ + struct timeval tv; + + maptime_read (maptime, &tv); + + if (what & TOUCH_ATIME) + { + st->st_atim.tv_sec = tv.tv_sec; + st->st_atim.tv_nsec = tv.tv_usec * 1000; + } + if (what & TOUCH_CTIME) + { + st->st_ctim.tv_sec = tv.tv_sec; + st->st_ctim.tv_nsec = tv.tv_usec * 1000; + } + if (what & TOUCH_MTIME) + { + st->st_mtim.tv_sec = tv.tv_sec; + st->st_mtim.tv_nsec = tv.tv_usec * 1000; + } +} diff --git a/libfshelp/translated.c b/libfshelp/translated.c new file mode 100644 index 00000000..2dc724b6 --- /dev/null +++ b/libfshelp/translated.c @@ -0,0 +1,28 @@ +/* + Copyright (C) 1999 Free Software Foundation, Inc. + Written by Thomas Bushnell, BSG. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "fshelp.h" + +/* Return true iff there is an active translator on this box */ +int +fshelp_translated (struct transbox *box) +{ + return (box->active != MACH_PORT_NULL); +} |