From 887d8b57c4aa291919c8eec6b2af5a5f5259ac6d Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 17 May 2004 17:52:45 +0000 Subject: Initial 5.2.x files --- srcx/jstart.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 srcx/jstart.c (limited to 'srcx/jstart.c') diff --git a/srcx/jstart.c b/srcx/jstart.c new file mode 100644 index 0000000..76bdaae --- /dev/null +++ b/srcx/jstart.c @@ -0,0 +1,107 @@ + +/* A lot of code from jail.c in */ +/* TODO: Attribute properly */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" + +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif + +int main(int argc, char* argv[]) +{ +#include + int ch, jid; + struct jail j; + int printjid = 0; + int console = 0; + struct in_addr in; + + while((ch = getopt(argc, argv, "ic")) != -1) + { + switch(ch) + { + case 'i': + printjid = 1; + break; + + case 'c': + console = 1; + break; + + case '?': + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if(argc != 3) + usage(); + + if(getuid() != 0) + errx(1, "must be run as root"); + + if(chdir(argv[0]) != 0) + err(1, "couldn't change to jail directory: %s", argv[0]); + + if(inet_aton(argv[2], &in) != 0) + errx(1, "invalid ip address: %s", argv[2]); + + memset(&j, 0, sizeof(j)); + j.version = 0; + j.path = argv[0]; +#include + j.hostname = argv[1]; + j.ip_number = ntohl(in.s_addr); + + /* Here's where we actually go into the jail */ + jid = jail(&j); + if(jid == -1) + err(1, "couldn't create jail"); + + if(console) + { + + + } + + if(printjid) + { + printf("%d\n", jid); + fflush(stdout); + } + + if(!check_jail_command("/etc/rc")) + exit(1); + + run_jail_command("/etc/rc"); + return 0; +} + +static void usage() +{ + fprintf(stderr, "usage: jstart [-ic] path hostname ip-number\n"); + exit(2); +} -- cgit v1.2.3