From nobody@FreeBSD.org  Sat Dec  3 13:02:05 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3EA8C16A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  3 Dec 2005 13:02:05 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id F1C2543D58
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  3 Dec 2005 13:02:04 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jB3D24TX095785
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 3 Dec 2005 13:02:04 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jB3D24lt095784;
	Sat, 3 Dec 2005 13:02:04 GMT
	(envelope-from nobody)
Message-Id: <200512031302.jB3D24lt095784@www.freebsd.org>
Date: Sat, 3 Dec 2005 13:02:04 GMT
From: "L. Jason Godsey" <lannygodsey@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Add -J to create a JidFile simular to PidFile used by syslogd containing jailid, path, hostname, ip and command used to start the jail.
X-Send-Pr-Version: www-2.3

>Number:         89883
>Category:       bin
>Synopsis:       jail(8): Add -J to create a JidFile simular to PidFile used by syslogd containing jailid, path, hostname, ip and command used to start the jail.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    philip
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 03 13:10:02 GMT 2005
>Closed-Date:    Sat Dec 03 17:34:35 GMT 2005
>Last-Modified:  Sat Dec 03 17:34:35 GMT 2005
>Originator:     L. Jason Godsey
>Release:        6.0-RELEASE
>Organization:
>Environment:
FreeBSD ne1.yournix.com 6.0-RELEASE FreeBSD 6.0-RELEASE #1: Fri Dec  2 22:30:00 EST 2005     root@ne1.yournix.com:/usr/obj/usr/src/sys/YOURNIX  i386
>Description:
Add -P to jail command to write something like a PidFile, only containing jailid, path, hostname, and command to start the jail.

>How-To-Repeat:
              
>Fix:
Changes to /usr/src/usr.sbin/jail/jail.c

--- jail.c.orig Sat Dec  3 07:06:21 2005
+++ jail.c      Sat Dec  3 07:58:50 2005
@@ -54,19 +54,25 @@
        struct passwd *pwd = NULL;
        struct in_addr in;
        gid_t groups[NGROUPS];
-       int ch, i, iflag, lflag, ngroups, uflag, Uflag;
-       char path[PATH_MAX], *username;
+       int ch, i, iflag, Jflag, lflag, ngroups, uflag, Uflag;
+       char path[PATH_MAX], *username, *JidFile;
        static char *cleanenv;
        const char *shell, *p = NULL;
+       FILE *fp;

-       iflag = lflag = uflag = Uflag = 0;
-       username = cleanenv = NULL;
+       iflag = Jflag = lflag = uflag = Uflag = 0;
+       username = JidFile = cleanenv = NULL;
+       fp = NULL;

-       while ((ch = getopt(argc, argv, "ilu:U:")) != -1) {
+       while ((ch = getopt(argc, argv, "ilu:U:J:")) != -1) {
                switch (ch) {
                case 'i':
                        iflag = 1;
                        break;
+               case 'J':
+                       JidFile = optarg;
+                       Jflag = 1;
+                       break;
                case 'u':
                        username = optarg;
                        uflag = 1;
@@ -103,6 +109,11 @@
        if (inet_aton(argv[2], &in) == 0)
                errx(1, "Could not make sense of ip-number: %s", argv[2]);
        j.ip_number = ntohl(in.s_addr);
+       if (Jflag) {
+               fp = fopen(JidFile, "w");
+               if (fp == NULL)
+                       errx(1, "Could not create JidFile: %s", JidFile);
+       }
        i = jail(&j);
        if (i == -1)
                err(1, "jail");
@@ -110,6 +121,14 @@
                printf("%d\n", i);
                fflush(stdout);
        }
+       if (Jflag) {
+               if (fp != NULL) {
+                       fprintf(fp, "%d\t%s\t%s\t%s\t%s\n", i, j.path, j.hostname, argv[2], argv[3]);
+                       (void)fclose(fp);
+               } else {
+                       errx(1, "Could not write to JidFile: %s", JidFile);
+               }
+       }
        if (username != NULL) {
                if (Uflag)
                        GET_USER_INFO;
@@ -149,7 +168,7 @@
 {

        (void)fprintf(stderr, "%s%s\n",
-            "usage: jail [-i] [-l -u username | -U username]",
+            "usage: jail [-J jid_file] [-i] [-l -u username | -U username]",
             " path hostname ip-number command ...");
        exit(1);
 }

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->philip 
Responsible-Changed-By: philip 
Responsible-Changed-When: Sat Dec 3 15:44:17 GMT 2005 
Responsible-Changed-Why:  
I like this idea.  Grab. :-) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=89883 
State-Changed-From-To: open->closed 
State-Changed-By: philip 
State-Changed-When: Sat Dec 3 17:34:33 GMT 2005 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=89883 
>Unformatted:
