From owner-freebsd-hackers Sun Dec 9 12:54:48 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from bazooka.trit.org (bazooka.trit.org [63.198.170.138]) by hub.freebsd.org (Postfix) with ESMTP id 16C7737B405; Sun, 9 Dec 2001 12:54:43 -0800 (PST) Received: by bazooka.trit.org (Postfix, from userid 1000) id C8D0A3E2F; Sun, 9 Dec 2001 20:54:42 +0000 (UTC) Received: from bazooka (localhost [127.0.0.1]) by bazooka.trit.org (Postfix) with ESMTP id C75383C12E; Sun, 9 Dec 2001 20:54:42 +0000 (UTC) To: chris@FreeBSD.ORG, Igor M Podlesny , freebsd-hackers@FreeBSD.ORG Subject: Re: jail.c.patch (allowing to use hostnames when invoking jail(8)) Date: Sun, 09 Dec 2001 20:54:37 +0000 From: Dima Dorfman Message-Id: <20011209205442.C8D0A3E2F@bazooka.trit.org> 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 Dima Dorfman wrote: > Chris Costello wrote: > > I'd rewrite the above (`i = inet_aton' all the way down) as > > > > hp = gethostbyname(argv[3]); > > if (hp == NULL) { > > errx(1, "%s: %s", argv[3], hstrerror(h_errno)); > > } > > in = *(struct in_addr *)hp->h_addr_list[0]; > > > > This makes the call to inet_aton() unnecessary (and really > > shortens the code!). > > As discussed off-list, this is a good idea. Attached is the final > patch that I plan to commit unless I hear objections. Please review. Here's an updated patch which is a result of comments from a few people. The changes are: (a) deconfuse the usage message by not naming two arguments as "hostname" (that was sloppiness on my part), and (b) remove a redundant inet_aton call (gethostbyname(3) will DTRT with an IP address) [1]. [1] It probably shouldn't, since as others have pointed out to me, "1.1.1.1" is a valid DNS name. The correct solution would be to have a flag which makes it explicit whether the argument is an IP address or DNS name, but few, if any, other programs in the system do this, and I don't think this is a good place to start. Index: jail.8 =================================================================== RCS file: /ref/cvsf/src/usr.sbin/jail/jail.8,v retrieving revision 1.30 diff -u -r1.30 jail.8 --- jail.8 2001/09/03 15:42:10 1.30 +++ jail.8 2001/12/09 20:45:53 @@ -43,13 +43,16 @@ .Nm .Ar path .Ar hostname -.Ar ip-number +.Ar address .Ar command .Ar ... .Sh DESCRIPTION The .Nm command imprisons a process and all future descendants. +The supplied +.Ar address +may either be a hostname or IPv4 address. .Pp Please see the .Xr jail 2 Index: jail.c =================================================================== RCS file: /ref/cvsf/src/usr.sbin/jail/jail.c,v retrieving revision 1.7 diff -u -r1.7 jail.c --- jail.c 2001/06/24 20:28:19 1.7 +++ jail.c 2001/12/09 20:50:20 @@ -14,23 +14,22 @@ #include #include -#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) @@ -39,9 +38,10 @@ j.version = 0; 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"); + hp = gethostbyname(argv[3]); + if (hp == NULL) + errx(1, "gethostbyname(%s): %s", argv[3], hstrerror(h_errno)); + in = *(struct in_addr *)hp->h_addr; j.ip_number = ntohl(in.s_addr); i = jail(&j); if (i) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message