From owner-freebsd-hackers Mon Dec 10 6:48: 4 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from cs.bu.edu (CS.BU.EDU [128.197.10.2]) by hub.freebsd.org (Postfix) with ESMTP id DA63637B417 for ; Mon, 10 Dec 2001 06:47:58 -0800 (PST) Received: from csa.bu.edu (evms@csa [128.197.12.3]) by cs.bu.edu (8.10.1/8.10.1) with ESMTP id fBAElvF11825 for ; Mon, 10 Dec 2001 09:47:57 -0500 (EST) Received: (from evms@localhost) by csa.bu.edu (8.10.1/8.10.1) id fBAElrY25522; Mon, 10 Dec 2001 09:47:53 -0500 (EST) Date: Mon, 10 Dec 2001 09:47:53 -0500 (EST) Message-Id: <200112101447.fBAElrY25522@csa.bu.edu> From: Evan Sarmiento To: freebsd-hackers@freebsd.org Subject: jail.c patch 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 Hello, I've been reading this thread. I made the augustments to the patch so that it first checks if it is an IP address, if it is not, it then tries to see if it is a hostname. If neither are true it exits with an error. Hope this is what you're looking for, Evan --- jail.c Mon Jul 30 06:19:54 2001 +++ jail.mod Mon Dec 10 07:51:03 2001 @@ -10,9 +10,8 @@ * */ -#include +#include #include -#include #include #include #include @@ -21,12 +20,13 @@ 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) @@ -36,14 +36,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"); + 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] ); + + 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); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message