From owner-freebsd-bugs Mon Dec 10 11:30:15 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id C61F037B41B for ; Mon, 10 Dec 2001 11:30:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id fBAJU1e16486; Mon, 10 Dec 2001 11:30:01 -0800 (PST) (envelope-from gnats) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id A3D3B37B41C for ; Mon, 10 Dec 2001 11:27:58 -0800 (PST) Received: (from nobody@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id fBAJRwG16169; Mon, 10 Dec 2001 11:27:58 -0800 (PST) (envelope-from nobody) Message-Id: <200112101927.fBAJRwG16169@freefall.freebsd.org> Date: Mon, 10 Dec 2001 11:27:58 -0800 (PST) From: Evan Sarmiento To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: misc/32680: [PATCH] Allows users to start jails by hostname as well as IP address Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 32680 >Category: misc >Synopsis: [PATCH] Allows users to start jails by hostname as well as IP address >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Dec 10 11:30:01 PST 2001 >Closed-Date: >Last-Modified: >Originator: Evan Sarmiento >Release: 5.0-CURRENT >Organization: >Environment: FreeBSD vaio 5.0-CURRENT FreeBSD 5.0-CURRENT #14: Wed Nov 28 20:01:56 EST 2001 kaworu@teqnix.sekt7.org:/FreeBSD/FreeBSD-current/src/sys/i386/compile/ARMITAGE i386 >Description: When you need to start a jail, you have to specify the IP address of the jail. This patch allows users to specify the name of the jail instead of the Ip address if they choose to. For example.. host mrq's ip is 169.69.6.1. jail /export/mrq mrq 169.69.6.1 /bin/sh /etc/rc with patch: jail /export/mrq mrq mrq /bin/sh /etc/rc Just uses gethostbyname(). >How-To-Repeat: >Fix: --- jail.c.orig Sun Jun 24 16:28:19 2001 +++ jail.c Mon Dec 10 14:21:19 2001 @@ -17,20 +17,20 @@ #include #include -#include +#include #include -#include #include int main(int argc, char **argv) { + struct hostent *hp; struct jail j; int i; struct in_addr in; if (argc < 5) - errx(1, "Usage: %s path hostname ip-number command ...\n", + errx(1, "Usage: %s path hostname address command ...\n", argv[0]); i = chdir(argv[1]); if (i) @@ -40,14 +40,26 @@ 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) { + hp = gethostbyname(argv[3]); + + if (hp == NULL) + errx(1, "gethostbyname(%s): %s (and) inet_aton(%s): Could not + make sense of ip-number", argv[3], hstrerror(h_errno), argv[3] ); + + else if (hp) + in = *(struct in_addr *)hp->h_addr; + + } + j.ip_number = ntohl(in.s_addr); i = jail(&j); if (i) - err(1, "Imprisonment failed"); + err(1, "Imprisonment failed"); i = execv(argv[4], argv + 4); if (i) - err(1, "execv(%s)", argv[4]); + err(1, "execv(%s)", argv[4]); + exit (0); } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message