/* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * %sccs.include.redist.c% */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)chroot.c 8.1 (Berkeley) 06/09/93"; #endif /* not lint */ #include #include #include #include #include #include #include #include void usage __P((void)); int main(argc, argv) int argc; char *argv[]; { int ch; char *shell; while ((ch = getopt(argc, argv, "")) != EOF) switch(ch) { case '?': default: usage(); } argc -= optind; argv += optind; if (argc < 1) usage(); if (chdir(argv[0]) || chroot(".")) err(1, "%s", argv[0]); if (argv[1]) { execvp(argv[1], &argv[1]); err(1, "%s", argv[1]); } if (!(shell = getenv("SHELL"))) shell = _PATH_BSHELL; execlp(shell, shell, "-i", NULL); err(1, "%s", shell); /* NOTREACHED */ } void usage() { (void)fprintf(stderr, "usage: chroot newroot [command]\n"); exit(1); }