misc/89883: Add -J to create a JidFile simular to PidFile used by syslogd containing jailid, path, hostname, ip and command used to start the jail.

L. Jason Godsey lannygodsey at yahoo.com
Sat Dec 3 13:10:28 GMT 2005


>Number:         89883
>Category:       misc
>Synopsis:       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:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 03 13:10:02 GMT 2005
>Closed-Date:
>Last-Modified:
>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 at 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:
>Unformatted:


More information about the freebsd-bugs mailing list