2013-06-14 16:55:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void usage(void);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2013-07-20 11:19:32 +00:00
|
|
|
char *shell[] = {"/bin/sh", "-i", NULL}, *aux;
|
2013-07-20 05:27:42 +00:00
|
|
|
|
2013-10-06 19:35:30 +00:00
|
|
|
if((aux = getenv("SHELL")))
|
2013-07-20 11:19:32 +00:00
|
|
|
shell[0] = aux;
|
2013-06-14 16:55:25 +00:00
|
|
|
|
|
|
|
if(argc < 2)
|
|
|
|
usage();
|
2013-07-20 05:27:42 +00:00
|
|
|
|
2013-06-14 16:55:25 +00:00
|
|
|
if(chroot(argv[1]) == -1)
|
|
|
|
eprintf("chroot: '%s':", argv[1]);
|
2013-07-20 05:27:42 +00:00
|
|
|
|
2013-06-14 16:55:25 +00:00
|
|
|
if(chdir("/") == -1)
|
|
|
|
eprintf("chroot:");
|
|
|
|
|
|
|
|
if(argc == 2) {
|
|
|
|
execvp(*shell, shell);
|
|
|
|
} else {
|
|
|
|
execvp(argv[2], argv+2);
|
|
|
|
}
|
2013-07-20 05:27:42 +00:00
|
|
|
|
2013-06-14 16:55:25 +00:00
|
|
|
eprintf("chroot: '%s':", argv[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: chroot dir [command [arg...]]\n");
|
|
|
|
}
|