Date: Mon, 10 Dec 2001 09:47:53 -0500 (EST) From: Evan Sarmiento <evms@cs.bu.edu> To: freebsd-hackers@freebsd.org Subject: jail.c patch Message-ID: <200112101447.fBAElrY25522@csa.bu.edu>
index | next in thread | raw e-mail
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 <stdio.h>
+#include <netdb.h>
#include <stdlib.h>
-#include <string.h>
#include <err.h>
#include <sys/types.h>
#include <sys/jail.h>
@@ -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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200112101447.fBAElrY25522>
