Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Nov 2001 22:40:06 +0700
From:      Igor M Podlesny <poige@morning.ru>
To:        freebsd-hackers@FreeBSD.ORG
Cc:        Dima Dorfman <dima@trit.org>
Subject:   jail.c.patch (allowing to use hostnames when invoking jail(8))
Message-ID:  <95121839796.20011124224006@morning.ru>

next in thread | raw e-mail | index | archive | help

A small patch allowing to use hostnames when invoking jail(8):

==========X-8==========X-8==========X-8==========X-8==========X-8==========

--- jail.c.org  Sat Nov 24 22:12:21 2001
+++ jail.c      Sat Nov 24 22:25:46 2001
@@ -10,13 +10,18 @@
  * 
  */
 
+#include <err.h>
+#include <netdb.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <err.h>
-#include <sys/types.h>
-#include <sys/jail.h>
+#include <unistd.h>
+
 #include <netinet/in.h>
+#include <sys/jail.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <arpa/inet.h>
 
 int
 main(int argc, char **argv)
@@ -26,7 +31,7 @@
        struct in_addr in;
 
        if (argc < 5) 
-               errx(1, "Usage: %s path hostname ip-number command ...\n",
+               errx(1, "Usage: %s path hostname hostname_or_ip_addr command ...\n",
                    argv[0]);
        i = chdir(argv[1]);
        if (i)
@@ -36,8 +41,23 @@
        j.path = argv[1];
        j.hostname = argv[2];
        i = inet_aton(argv[3], &in);
-       if (!i)
-               errx(1, "Couldn't make sense of ip-number\n");
+       if (!i) {
+               /* check if it is resolveable */
+               struct hostent *hp;
+               hp = gethostbyname(argv[3]);
+               if (hp == NULL) {
+                       errx(1, "Couldn't make sense of the jail address\n");
+               }
+               else {
+                       char **p = hp->h_addr_list;
+                       if (p[1] != NULL) {
+                               errx(1, "Jail should have only one ip-address associated with!\n");
+                       }
+                       else {
+                               memcpy(&in.s_addr, p[0], sizeof(in.s_addr));
+                       }
+               }
+       }
        j.ip_number = ntohl(in.s_addr);
        i = jail(&j);
        if (i)

==========X-8==========X-8==========X-8==========X-8==========X-8==========

I consider this useful, hope you do also...

-- 
Best regards,
 Igor                          mailto:poige@morning.ru
                               http://morning.ru/~poige


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?95121839796.20011124224006>