From owner-freebsd-hackers Sat Nov 24 7:38:27 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mars-gw.morning.ru (ns.morning.ru [195.161.98.5]) by hub.freebsd.org (Postfix) with ESMTP id AE80937B405 for ; Sat, 24 Nov 2001 07:38:22 -0800 (PST) Received: from NDNM ([195.161.98.250]) by mars-gw.morning.ru (8.11.5/8.11.5) with ESMTP id fAOFcKY39128; Sat, 24 Nov 2001 22:38:21 +0700 (KRAT) Date: Sat, 24 Nov 2001 22:40:06 +0700 From: Igor M Podlesny X-Mailer: The Bat! (v1.53d) Business Organization: Morning Network X-Priority: 3 (Normal) Message-ID: <95121839796.20011124224006@morning.ru> To: freebsd-hackers@FreeBSD.ORG Cc: Dima Dorfman Subject: jail.c.patch (allowing to use hostnames when invoking jail(8)) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 +#include #include #include #include -#include -#include -#include +#include + #include +#include +#include +#include +#include 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