From owner-svn-src-stable@freebsd.org Mon Dec 10 13:41:29 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9C13813266C1; Mon, 10 Dec 2018 13:41:29 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 42A1A79046; Mon, 10 Dec 2018 13:41:29 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2467A2093F; Mon, 10 Dec 2018 13:41:29 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBADfTr7031497; Mon, 10 Dec 2018 13:41:29 GMT (envelope-from eugen@FreeBSD.org) Received: (from eugen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBADfSGn031494; Mon, 10 Dec 2018 13:41:28 GMT (envelope-from eugen@FreeBSD.org) Message-Id: <201812101341.wBADfSGn031494@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eugen set sender to eugen@FreeBSD.org using -f From: Eugene Grosbein Date: Mon, 10 Dec 2018 13:41:28 +0000 (UTC) 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 X-SVN-Group: stable-12 X-SVN-Commit-Author: eugen X-SVN-Commit-Paths: stable/12/usr.sbin/jail X-SVN-Commit-Revision: 341788 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 42A1A79046 X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_SHORT(-0.97)[-0.966,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-0.99)[-0.990,0] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Dec 2018 13:41:29 -0000 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)