jail.c revision 46432
11573Srgrimes/* 21573Srgrimes * ---------------------------------------------------------------------------- 31573Srgrimes * "THE BEER-WARE LICENSE" (Revision 42): 41573Srgrimes * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 51573Srgrimes * can do whatever you want with this stuff. If we meet some day, and you think 61573Srgrimes * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 71573Srgrimes * ---------------------------------------------------------------------------- 81573Srgrimes * 91573Srgrimes * $Id$ 101573Srgrimes * 111573Srgrimes */ 121573Srgrimes 131573Srgrimes#include <stdio.h> 141573Srgrimes#include <err.h> 151573Srgrimes#include <sys/types.h> 161573Srgrimes#include <sys/jail.h> 171573Srgrimes#include <netinet/in.h> 181573Srgrimes 191573Srgrimesint 201573Srgrimesmain(int argc, char **argv) 211573Srgrimes{ 221573Srgrimes struct jail j; 231573Srgrimes int i; 241573Srgrimes struct in_addr in; 251573Srgrimes 261573Srgrimes if (argc < 5) 271573Srgrimes errx(1, "Usage: %s path hostname ip command ...\n", argv[0]); 281573Srgrimes i = chdir(argv[1]); 291573Srgrimes if (i) 301573Srgrimes err(1, "chdir %s", argv[1]); 311573Srgrimes j.path = argv[1]; 321573Srgrimes j.hostname = argv[2]; 331573Srgrimes i = inet_aton(argv[3], &in); 341573Srgrimes if (!i) 3517718Sache errx(1, "Couldn't make sense if ip number\n"); 3650476Speter j.ip_number = ntohl(in.s_addr); 371573Srgrimes i = jail(&j); 381573Srgrimes if (i) 391573Srgrimes err(1, "Imprisonment failed"); 401573Srgrimes i = execv(argv[4], argv + 4); 411573Srgrimes if (i) 421573Srgrimes err(1, "execv(%s)", argv[4]); 431573Srgrimes exit (0); 441573Srgrimes} 451573Srgrimes