diff options
Diffstat (limited to 'trans/identity.c')
-rw-r--r-- | trans/identity.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/trans/identity.c b/trans/identity.c new file mode 100644 index 00000000..875fc4f3 --- /dev/null +++ b/trans/identity.c @@ -0,0 +1,113 @@ +/* identity -- a translator interposing file RPCs. + Copyright (C) 2016 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 + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program 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-1307 USA */ + +#include <argp.h> +#include <error.h> +#include <fcntl.h> +#include <hurd/netfs.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <version.h> + +#include "chroot.h" + +const char *argp_program_version = STANDARD_HURD_VERSION (identity); + +char *netfs_server_name = "identity"; +char *netfs_server_version = HURD_VERSION; +int netfs_maxsymlinks = 16; /* arbitrary */ + +struct chroot_node +{ +}; + +void +chroot_node_norefs (struct node *np) +{ +} + + +static struct argp_option options[] = +{ + {0} +}; + +static char *args_doc = ""; +static char *doc = + "The identity translator relays file RPCs without changing them." + "\v" + "It can be used in conjunction with settrans --chroot to implement " + "a hurdish chroot utility."; + +static error_t +parse_opt (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +int +main (int argc, char **argv) +{ + error_t err; + mach_port_t bootstrap; + + struct argp argp = + { + .options = options, + .parser = parse_opt, + .args_doc = args_doc, + .doc = doc, + }; + + /* Parse our command line arguments (all none of them). */ + argp_parse (&argp, argc, argv, 0, 0, 0); + + task_get_bootstrap_port (mach_task_self (), &bootstrap); + if (! MACH_PORT_VALID (bootstrap)) + error (1, 0, "Must be started as a translator"); + + netfs_init (); + chroot_init (); + + /* Get our underlying node (we presume it's a directory) and use + that to make the root node of the filesystem. */ + err = chroot_new_node (netfs_startup (bootstrap, O_READ), + sizeof (struct chroot_node), &netfs_root_node); + if (err) + error (5, err, "Cannot create root node"); + + err = netfs_validate_stat (netfs_root_node, 0); + if (err) + error (6, err, "Cannot stat underlying node"); + + netfs_root_node->nn_stat.st_mode &= ~(S_IPTRANS | S_IATRANS); + netfs_root_node->nn_stat.st_mode |= S_IROOT; + pthread_mutex_unlock (&netfs_root_node->lock); + + netfs_server_loop (); /* Never returns. */ + + /*NOTREACHED*/ + return 0; +} |