| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | #include "netfs.h" |
| 22 | #include "fsys_S.h" |
| 23 | #include "misc.h" |
| 24 | #include "callbacks.h" |
| 25 | #include <fcntl.h> |
| 26 | |
| 27 | error_t |
| 28 | netfs_S_fsys_getroot (mach_port_t cntl, |
| 29 | mach_port_t reply, |
| 30 | mach_msg_type_name_t reply_type, |
| 31 | mach_port_t dotdot, |
| 32 | uid_t *uids, mach_msg_type_number_t nuids, |
| 33 | uid_t *gids, mach_msg_type_number_t ngids, |
| 34 | int flags, |
| 35 | retry_type *do_retry, |
| 36 | char *retry_name, |
| 37 | mach_port_t *retry_port, |
| 38 | mach_msg_type_name_t *retry_port_type) |
| 39 | { |
| 40 | struct port_info *pt = ports_lookup_port (netfs_port_bucket, cntl, |
| 41 | netfs_control_class); |
| 42 | struct iouser *cred; |
| 43 | error_t err; |
| 44 | struct protid *newpi; |
| 45 | mode_t type; |
| 46 | struct peropen peropen_context = |
| 47 | { |
| 48 | root_parent: dotdot, |
| 49 | path: NULL((void*)0), |
| 50 | }; |
| 51 | |
| 52 | if (!pt) |
| 53 | return EOPNOTSUPP((0x10 << 26) | ((45) & 0x3fff)); |
| 54 | ports_port_deref (pt); |
| 55 | |
| 56 | err = iohelp_create_complex_iouser (&cred, uids, nuids, gids, ngids); |
| 57 | if (err) |
| 58 | return err; |
| 59 | |
| 60 | flags &= O_HURD(0xffff | 0x00040000 | 0x00020000); |
| 61 | |
| 62 | pthread_mutex_lock (&netfs_root_node->lock); |
| 63 | err = netfs_validate_stat (netfs_root_node, cred); |
| 64 | if (err) |
| 65 | goto out; |
| 66 | |
| 67 | type = netfs_root_node->nn_stat.st_mode & S_IFMT0170000; |
| 68 | |
| 69 | if (((netfs_root_node->nn_stat.st_mode & S_IPTRANS000010000000) |
| 70 | || fshelp_translated (&netfs_root_node->transbox)) |
| 71 | && !(flags & O_NOTRANS0x0080)) |
| 72 | { |
| 73 | err = fshelp_fetch_root (&netfs_root_node->transbox, |
| 74 | &peropen_context, dotdot, cred, flags, |
| 75 | _netfs_translator_callback1, |
| 76 | _netfs_translator_callback2, |
| 77 | do_retry, retry_name, retry_port); |
| 78 | if (err != ENOENT((0x10 << 26) | ((2) & 0x3fff))) |
| 79 | { |
| 80 | pthread_mutex_unlock (&netfs_root_node->lock); |
| 81 | iohelp_free_iouser (cred); |
| 82 | if (!err) |
| 83 | *retry_port_type = MACH_MSG_TYPE_MOVE_SEND17; |
| 84 | return err; |
| 85 | } |
| 86 | |
| 87 | err = 0; |
| Value stored to 'err' is never read |
| 88 | } |
| 89 | |
| 90 | if (type == S_IFLNK0120000 && !(flags & (O_NOLINK0x0040 | O_NOTRANS0x0080))) |
| 91 | { |
| 92 | char pathbuf[netfs_root_node->nn_stat.st_size + 1]; |
| 93 | |
| 94 | err = netfs_attempt_readlink (cred, netfs_root_node, pathbuf); |
| 95 | |
| 96 | if (err) |
| 97 | goto out; |
| 98 | |
| 99 | pthread_mutex_unlock (&netfs_root_node->lock); |
| 100 | iohelp_free_iouser (cred); |
| 101 | |
| 102 | if (pathbuf[0] == '/') |
| 103 | { |
| 104 | *do_retry = FS_RETRY_MAGICAL; |
| 105 | *retry_port = MACH_PORT_NULL((mach_port_t) 0); |
| 106 | *retry_port_type = MACH_MSG_TYPE_COPY_SEND19; |
| 107 | strcpy (retry_name, pathbuf); |
| 108 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), dotdot); |
| 109 | return 0; |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | *do_retry = FS_RETRY_REAUTH; |
| 114 | *retry_port = dotdot; |
| 115 | *retry_port_type = MACH_MSG_TYPE_MOVE_SEND17; |
| 116 | strcpy (retry_name, pathbuf); |
| 117 | return 0; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if ((type == S_IFSOCK0140000 || type == S_IFBLK0060000 || type == S_IFCHR0020000 |
| 122 | || type == S_IFIFO0010000) && (flags & (O_READ0x0001|O_WRITE0x0002|O_EXEC0x0004))) |
| 123 | { |
| 124 | err = EOPNOTSUPP((0x10 << 26) | ((45) & 0x3fff)); |
| 125 | goto out; |
| 126 | } |
| 127 | |
| 128 | err = netfs_check_open_permissions (cred, netfs_root_node, flags, 0); |
| 129 | if (err) |
| 130 | goto out; |
| 131 | |
| 132 | flags &= ~OPENONLY_STATE_MODES(0x0010|0x0020|0x0040|0x0080); |
| 133 | |
| 134 | newpi = netfs_make_protid (netfs_make_peropen (netfs_root_node, flags, |
| 135 | &peropen_context), |
| 136 | cred); |
| 137 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), dotdot); |
| 138 | |
| 139 | *do_retry = FS_RETRY_NORMAL; |
| 140 | *retry_port = ports_get_right (newpi); |
| 141 | *retry_port_type = MACH_MSG_TYPE_MAKE_SEND20; |
| 142 | retry_name[0] = '\0'; |
| 143 | ports_port_deref (newpi); |
| 144 | |
| 145 | out: |
| 146 | if (err) |
| 147 | iohelp_free_iouser (cred); |
| 148 | pthread_mutex_unlock (&netfs_root_node->lock); |
| 149 | return err; |
| 150 | } |