Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Dec 2018 13:41:28 +0000 (UTC)
From:      Eugene Grosbein <eugen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r341788 - stable/12/usr.sbin/jail
Message-ID:  <201812101341.wBADfSGn031494@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eugen
Date: Mon Dec 10 13:41:28 2018
New Revision: 341788
URL: https://svnweb.freebsd.org/changeset/base/341788

Log:
  MFC r340319: jail(8): introduce new command option -e to exhibit
  a list of configured non-wildcard jails with their parameters,
  no matter running or not.
  
  The option -e takes separator argument that is used
  to separate printed parameters. It will be used with following
  additions to system periodic scripts to differentiate parts
  of directory tree belonging jails as opposed to host's.

Modified:
  stable/12/usr.sbin/jail/jail.8
  stable/12/usr.sbin/jail/jail.c
  stable/12/usr.sbin/jail/jailp.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/jail/jail.8
==============================================================================
--- stable/12/usr.sbin/jail/jail.8	Mon Dec 10 13:38:13 2018	(r341787)
+++ stable/12/usr.sbin/jail/jail.8	Mon Dec 10 13:41:28 2018	(r341788)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 17, 2018
+.Dd November 10, 2018
 .Dt JAIL 8
 .Os
 .Sh NAME
@@ -49,6 +49,7 @@
 .Nm
 .Op Fl qv
 .Op Fl f Ar conf_file
+.Op Fl e Ar separator
 .Op Fl rR
 .Op Cm * | Ar jail ...
 .Nm
@@ -63,6 +64,7 @@
 The
 .Nm
 utility creates new jails, or modifies or removes existing jails.
+It can also print a list of configured jails and their parameters.
 A jail
 .Pq or Dq prison
 is specified via parameters on the command line, or in the
@@ -71,6 +73,7 @@ file.
 .Pp
 At least one of the options
 .Fl c ,
+.Fl e ,
 .Fl m
 or
 .Fl r
@@ -86,6 +89,15 @@ and
 .Va name
 parameters (if specified on the command line)
 must not refer to an existing jail.
+.It Fl e Ar separator
+Exhibit a list of all configured non-wildcard jails and their parameters.
+No jail creation, modification or removal performed if this option is used.
+The
+.Ar separator
+string is used to separate parameters.
+Use
+.Xr jls 8
+utility to list running jails.
 .It Fl m
 Modify an existing jail.
 One of the

Modified: stable/12/usr.sbin/jail/jail.c
==============================================================================
--- stable/12/usr.sbin/jail/jail.c	Mon Dec 10 13:38:13 2018	(r341787)
+++ stable/12/usr.sbin/jail/jail.c	Mon Dec 10 13:41:28 2018	(r341788)
@@ -60,6 +60,7 @@ const char *cfname;
 int iflag;
 int note_remove;
 int verbose;
+const char *separator = "\t";
 
 static void clear_persist(struct cfjail *j);
 static int update_jail(struct cfjail *j);
@@ -69,8 +70,9 @@ static void jail_quoted_warnx(const struct cfjail *j, 
     const char *noname_msg);
 static int jailparam_set_note(const struct cfjail *j, struct jailparam *jp,
     unsigned njp, int flags);
-static void print_jail(FILE *fp, struct cfjail *j, int oldcl);
+static void print_jail(FILE *fp, struct cfjail *j, int oldcl, int running);
 static void print_param(FILE *fp, const struct cfparam *p, int sep, int doname);
+static void show_jails(void);
 static void quoted_print(FILE *fp, char *str);
 static void usage(void);
 
@@ -151,7 +153,7 @@ main(int argc, char **argv)
 	cfname = CONF_FILE;
 	JidFile = NULL;
 
-	while ((ch = getopt(argc, argv, "cdf:hiJ:lmn:p:qrRs:u:U:v")) != -1) {
+	while ((ch = getopt(argc, argv, "cde:f:hiJ:lmn:p:qrRs:u:U:v")) != -1) {
 		switch (ch) {
 		case 'c':
 			op |= JF_START;
@@ -159,6 +161,10 @@ main(int argc, char **argv)
 		case 'd':
 			dflag = 1;
 			break;
+		case 'e':
+			op |= JF_SHOW;
+			separator = optarg;
+			break;
 		case 'f':
 			cfname = optarg;
 			break;
@@ -276,7 +282,13 @@ main(int argc, char **argv)
 					    ? NULL : "false");
 			}
 		}
-	} else if (op == JF_STOP) {
+	} else if (op == JF_STOP || op == JF_SHOW) {
+		/* Just print list of all configured non-wildcard jails */
+		if (op == JF_SHOW) {
+			load_config();
+			show_jails();
+			exit(0);
+		}
 		/* Jail remove, perhaps using the config file */
 		if (!docf || argc == 0)
 			usage();
@@ -439,7 +451,7 @@ main(int argc, char **argv)
 		jail_create_done:
 			clear_persist(j);
 			if (jfp != NULL)
-				print_jail(jfp, j, oldcl);
+				print_jail(jfp, j, oldcl, 1);
 			dep_done(j, 0);
 			break;
 
@@ -918,16 +930,18 @@ jailparam_set_note(const struct cfjail *j, struct jail
  * Print a jail record.
  */
 static void
-print_jail(FILE *fp, struct cfjail *j, int oldcl)
+print_jail(FILE *fp, struct cfjail *j, int oldcl, int running)
 {
 	struct cfparam *p;
+	int printsep;
 
 	if (oldcl) {
-		fprintf(fp, "%d\t", j->jid);
+		if (running)
+			fprintf(fp, "%d%s", j->jid, separator);
 		print_param(fp, j->intparams[KP_PATH], ',', 0);
-		putc('\t', fp);
+		fputs(separator, fp);
 		print_param(fp, j->intparams[KP_HOST_HOSTNAME], ',', 0);
-		putc('\t', fp);
+		fputs(separator, fp);
 #ifdef INET
 		print_param(fp, j->intparams[KP_IP4_ADDR], ',', 0);
 #ifdef INET6
@@ -941,13 +955,20 @@ print_jail(FILE *fp, struct cfjail *j, int oldcl)
 #ifdef INET6
 		print_param(fp, j->intparams[KP_IP6_ADDR], ',', 0);
 #endif
-		putc('\t', fp);
+		fputs(separator, fp);
 		print_param(fp, j->intparams[IP_COMMAND], ' ', 0);
 	} else {
-		fprintf(fp, "jid=%d", j->jid);
+		printsep = 0;
+		if (running) {
+			fprintf(fp, "jid=%d", j->jid);
+			printsep = 1;
+		}
 		TAILQ_FOREACH(p, &j->params, tq)
 			if (strcmp(p->name, "jid")) {
-				putc(' ', fp);
+				if (printsep)
+					fputs(separator, fp);
+				else
+					printsep = 1;
 				print_param(fp, p, ',', 1);
 			}
 	}
@@ -955,6 +976,18 @@ print_jail(FILE *fp, struct cfjail *j, int oldcl)
 }
 
 /*
+ * Exhibit list of all configured non-wildcard jails
+ */
+static void
+show_jails(void)
+{
+	struct cfjail *j;
+	
+	TAILQ_FOREACH(j, &cfjails, tq)
+		print_jail(stdout, j, 0, 0);
+}
+
+/*
  * Print a parameter value, or a name=value pair.
  */
 static void
@@ -1007,7 +1040,7 @@ usage(void)
 	(void)fprintf(stderr,
 	    "usage: jail [-dhilqv] [-J jid_file] [-u username] [-U username]\n"
 	    "            -[cmr] param=value ... [command=command ...]\n"
-	    "       jail [-dqv] [-f file] -[cmr] [jail]\n"
+	    "       jail [-dqv] [-f file] [-e separator] -[cmr] [jail]\n"
 	    "       jail [-qv] [-f file] -[rR] ['*' | jail ...]\n"
 	    "       jail [-dhilqv] [-J jid_file] [-u username] [-U username]\n"
 	    "            [-n jailname] [-s securelevel]\n"

Modified: stable/12/usr.sbin/jail/jailp.h
==============================================================================
--- stable/12/usr.sbin/jail/jailp.h	Mon Dec 10 13:38:13 2018	(r341787)
+++ stable/12/usr.sbin/jail/jailp.h	Mon Dec 10 13:41:28 2018	(r341788)
@@ -67,6 +67,7 @@
 #define JF_TIMEOUT	0x0200	/* A command (or process kill) timed out */
 #define JF_SLEEPQ	0x0400	/* Waiting on a command and/or timeout */
 #define JF_FROM_RUNQ	0x0800	/* Has already been on the run queue */
+#define JF_SHOW		0x1000	/* -e Exhibit list of configured jails */
 
 #define JF_OP_MASK		(JF_START | JF_SET | JF_STOP)
 #define JF_RESTART		(JF_START | JF_STOP)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812101341.wBADfSGn031494>