summaryrefslogtreecommitdiff
path: root/srcx/jstart.c
diff options
context:
space:
mode:
Diffstat (limited to 'srcx/jstart.c')
-rw-r--r--srcx/jstart.c107
1 files changed, 107 insertions, 0 deletions
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 <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+
+#include <paths.h>
+#include <signal.h>
+#include <stdio.h>
+#include <syslog.h>
+#include <err.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <kvm.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#include "util.h"
+
+#ifdef HAVE_CONFIG_H
+#include "../config.h"
+#endif
+
+int main(int argc, char* argv[])
+{
+#include <signal.h>
+ 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 <signal.h>
+ 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);
+}