jail.c revision 46432
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$ 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 command ...\n", argv[0]); 28 i = chdir(argv[1]); 29 if (i) 30 err(1, "chdir %s", argv[1]); 31 j.path = argv[1]; 32 j.hostname = argv[2]; 33 i = inet_aton(argv[3], &in); 34 if (!i) 35 errx(1, "Couldn't make sense if ip number\n"); 36 j.ip_number = ntohl(in.s_addr); 37 i = jail(&j); 38 if (i) 39 err(1, "Imprisonment failed"); 40 i = execv(argv[4], argv + 4); 41 if (i) 42 err(1, "execv(%s)", argv[4]); 43 exit (0); 44} 45