Date: Sun, 09 Dec 2001 20:54:37 +0000 From: Dima Dorfman <dima@trit.org> To: chris@FreeBSD.ORG, Igor M Podlesny <poige@morning.ru>, freebsd-hackers@FreeBSD.ORG Subject: Re: jail.c.patch (allowing to use hostnames when invoking jail(8)) Message-ID: <20011209205442.C8D0A3E2F@bazooka.trit.org>
index | next in thread | raw e-mail
Dima Dorfman <dima@bazooka> wrote:
> Chris Costello <chris@FreeBSD.ORG> 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 <sys/jail.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
#include <err.h>
-#include <stdio.h>
+#include <netdb.h>
#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011209205442.C8D0A3E2F>
