summaryrefslogtreecommitdiff
path: root/srcx
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-05-02 17:37:49 +0000
committerStef Walter <stef@memberwebs.com>2008-05-02 17:37:49 +0000
commitf717d0236ff400eea0fe4bbd2e57db2f783a1713 (patch)
tree023d2f9cc93f1541be660de4870d86f490b7c872 /srcx
parent597d4be9d0dbb4e0ab159c491627767eddc7eb46 (diff)
- Support the multi-ip jail patch that's floating around.
Diffstat (limited to 'srcx')
-rw-r--r--srcx/jstart.c70
1 files changed, 64 insertions, 6 deletions
diff --git a/srcx/jstart.c b/srcx/jstart.c
index aa119f8..6360f06 100644
--- a/srcx/jstart.c
+++ b/srcx/jstart.c
@@ -53,6 +53,7 @@
#include <err.h>
#include <unistd.h>
#include <limits.h>
+#include <string.h>
#include "util.h"
@@ -65,12 +66,66 @@ static char* START_ARGS[] = { _PATH_BSHELL, START_SCRIPT, NULL };
static void usage();
+#ifdef JAIL_MULTIPATCH
+
+static void allocate_address(char* arg, struct jail* j)
+{
+ struct in_addr in;
+ char *ip;
+ int i = 0;
+
+ /* Count number of ips */
+ for(i = 1, ip = arg; *ip; ip++)
+ {
+ if(*ip == ',')
+ i++;
+ }
+
+ /* Allocate memory */
+ if((j->ips = (u_int32_t*)malloc(sizeof(u_int32_t) * i)) == NULL)
+ errx(1, "out of memory");
+
+ for(i = 0, ip = strtok(arg, ","); ip; i++, ip = strtok(NULL, ","))
+ {
+ if(inet_aton(ip, &in) == 0)
+ errx(1, "invalid ip address: %s", ip);
+ j->ips[i] = ntohl(in.s_addr);
+ }
+
+ j->nips = i;
+ j->version = 1;
+}
+
+static void free_address(struct jail* j)
+{
+ free(j->ips);
+}
+
+#else /* !JAIL_MULTIPATCH */
+
+static void allocate_address(char* arg, struct jail* j)
+{
+ struct in_addr in;
+
+ if(inet_aton(arg, &in) != 1)
+ errx(1, "invalid ip address: %s", arg);
+ j->ip_number = ntohl(in.s_addr);
+ j->version = 0;
+}
+
+static void free_address(struct jail* j)
+{
+ /* Nothing to do */
+}
+
+#endif /* !JAIL_MULTIPATCH */
+
+
int main(int argc, char* argv[])
{
int ch, jid;
struct jail j;
int printjid = 0;
- struct in_addr in;
while((ch = getopt(argc, argv, "i")) != -1)
{
@@ -98,20 +153,19 @@ int main(int argc, char* argv[])
if(chdir(argv[0]) != 0)
err(1, "couldn't change to jail directory: %s", argv[0]);
- if(inet_aton(argv[2], &in) != 1)
- errx(1, "invalid ip address: %s", argv[2]);
-
memset(&j, 0, sizeof(j));
- j.version = 0;
j.path = argv[0];
j.hostname = argv[1];
- j.ip_number = ntohl(in.s_addr);
+
+ allocate_address(argv[2], &j);
/* Here's where we actually go into the jail */
jid = jail(&j);
if(jid == -1)
err(1, "couldn't create jail");
+ free_address(&j);
+
if(printjid)
{
printf("%d\n", jid);
@@ -144,7 +198,11 @@ int main(int argc, char* argv[])
static void usage()
{
+#ifdef JAIL_MULTIPATCH
+ fprintf(stderr, "usage: jstart [-i] path hostname ip[,ip...] [command ...]\n");
+#else
fprintf(stderr, "usage: jstart [-i] path hostname ip-number [command ...]\n");
+#endif
exit(2);
}