jail.c revision 46520
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 * $Id: jail.c,v 1.2 1999/05/04 18:20:53 phk Exp $
10 *
11 */
12
13#include <stdio.h>
14#include <err.h>
15#include <sys/types.h>
16#include <sys/jail.h>
17#include <netinet/in.h>
18
19int
20main(int argc, char **argv)
21{
22	struct jail j;
23	int i;
24	struct in_addr in;
25
26	if (argc < 5)
27		errx(1, "Usage: %s path hostname ip-number command ...\n",
28		    argv[0]);
29	i = chdir(argv[1]);
30	if (i)
31		err(1, "chdir %s", argv[1]);
32	j.path = argv[1];
33	j.hostname = argv[2];
34	i = inet_aton(argv[3], &in);
35	if (!i)
36		errx(1, "Couldn't make sense of ip-number\n");
37	j.ip_number = ntohl(in.s_addr);
38	i = jail(&j);
39	if (i)
40		err(1, "Imprisonment failed");
41	i = execv(argv[4], argv + 4);
42	if (i)
43		err(1, "execv(%s)", argv[4]);
44	exit (0);
45}
46