From owner-svn-src-projects@freebsd.org Mon Aug 6 15:21:48 2018 Return-Path: Delivered-To: svn-src-projects@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 33893105C180 for ; Mon, 6 Aug 2018 15:21:48 +0000 (UTC) (envelope-from kevans@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 D906D7C201; Mon, 6 Aug 2018 15:21:47 +0000 (UTC) (envelope-from kevans@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 BB2EA6C84; Mon, 6 Aug 2018 15:21:47 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w76FLlr1038580; Mon, 6 Aug 2018 15:21:47 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w76FLltR038578; Mon, 6 Aug 2018 15:21:47 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808061521.w76FLltR038578@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 6 Aug 2018 15:21:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337380 - projects/bectl/sbin/bectl X-SVN-Group: projects X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: projects/bectl/sbin/bectl X-SVN-Commit-Revision: 337380 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Aug 2018 15:21:48 -0000 Author: kevans Date: Mon Aug 6 15:21:46 2018 New Revision: 337380 URL: https://svnweb.freebsd.org/changeset/base/337380 Log: bectl(8): Provide -u option to unset jail parameters All but name, host.hostname, and path may be completely unset. Modified: projects/bectl/sbin/bectl/bectl.8 projects/bectl/sbin/bectl/bectl.c projects/bectl/sbin/bectl/bectl_jail.c Modified: projects/bectl/sbin/bectl/bectl.8 ============================================================================== --- projects/bectl/sbin/bectl/bectl.8 Mon Aug 6 14:40:45 2018 (r337379) +++ projects/bectl/sbin/bectl/bectl.8 Mon Aug 6 15:21:46 2018 (r337380) @@ -40,7 +40,7 @@ destroy .Ao Ar beName | beName@snapshot Ac .Nm jail -.Op Fl o Ar key Ns = Ns Ar value Oc Ns ... +.Oo Fl o Ar key Ns = Ns Ar value | Fl u Ar key Oc Ns ... .Ao Ar jailID | jailName Ac .Ao Ar bootenv Ac .Nm @@ -124,15 +124,32 @@ Specifying will automatically unmount without confirmation. .Pp .It Ic jail -.Op Fl o Ar key Ns = Ns Ar value Oc Ns ... +.Oo Fl o Ar key Ns = Ns Ar value | Fl u Ar key Oc Ns ... .Ao Ar jailID | jailName Ac .Ao Ar bootenv Ac .Pp Creates a jail of the given boot environment. Multiple .Fl o +and +.Fl u arguments may be specified. -Al +.Fl o +will set a jail parameter, and +.Fl u +will unset a jail parameter. +.Pp +The +.Va name , +.Va host.hostname , +and +.Va path +may not actually be unset. +Attempts to unset any of these will revert them to the default values specified +below, if they have been overwritten by +.Fl o . +.Pp +All .Ar key , .Ar value pairs are interpreted as jail parameters as described in @@ -148,9 +165,8 @@ The following default parameters are provided: Set to a path in /tmp generated by .Xr libbe 8 . .El -.pp -All default parameters may be overwritten. .Pp +All default parameters may be overwritten. .It Ic list .Op Fl a .Op Fl D Modified: projects/bectl/sbin/bectl/bectl.c ============================================================================== --- projects/bectl/sbin/bectl/bectl.c Mon Aug 6 14:40:45 2018 (r337379) +++ projects/bectl/sbin/bectl/bectl.c Mon Aug 6 15:21:46 2018 (r337380) @@ -70,7 +70,7 @@ usage(bool explicit) "\tbectl export sourceBe\n" "\tbectl import targetBe\n" "\tbectl add (path)*\n" - "\tbectl jail [ -o key=value ]... bootenv\n" + "\tbectl jail [ -o key=value | -u key ]... bootenv\n" "\tbectl list [-a] [-D] [-H] [-s]\n" "\tbectl mount beName [mountpoint]\n" "\tbectl rename origBeName newBeName\n" Modified: projects/bectl/sbin/bectl/bectl_jail.c ============================================================================== --- projects/bectl/sbin/bectl/bectl_jail.c Mon Aug 6 14:40:45 2018 (r337379) +++ projects/bectl/sbin/bectl/bectl_jail.c Mon Aug 6 15:21:46 2018 (r337380) @@ -43,7 +43,9 @@ static void jailparam_grow(void); static void jailparam_add(const char *name, const char *val); +static void jailparam_del(const char *name); static bool jailparam_addarg(char *arg); +static bool jailparam_delarg(char *arg); static int bectl_search_jail_paths(const char *mnt); static int bectl_locate_jail(const char *ident); @@ -89,6 +91,34 @@ jailparam_add(const char *name, const char *val) ++jpused; } +static void +jailparam_del(const char *name) +{ + int i; + char *val; + + for (i = 0; i < jpused; ++i) { + if (strcmp(name, jp[i].jp_name) == 0) + break; + } + + /* Not found... technically successful */ + if (i == jpused) + return; + + for (; i < jpused - 1; ++i) { + val = jailparam_export(&jp[i + 1]); + + jailparam_free(&jp[i], 1); + jailparam_init(&jp[i], jp[i + 1].jp_name); + jailparam_import(&jp[i], val); + free(val); + } + + jailparam_free(&jp[i], 1); + --jpused; +} + static bool jailparam_addarg(char *arg) { @@ -117,6 +147,23 @@ jailparam_addarg(char *arg) return (true); } +static bool +jailparam_delarg(char *arg) +{ + char *name, *val; + + if (arg == NULL) + return (false); + name = arg; + if ((val = strchr(name, '=')) != NULL) + *val++ = '\0'; + + if (strcmp(name, "path") == 0) + *mnt_loc = '\0'; + jailparam_del(name); + return (true); +} + int bectl_cmd_jail(int argc, char *argv[]) { @@ -135,7 +182,7 @@ bectl_cmd_jail(int argc, char *argv[]) jailparam_add("allow.mount.devfs", "true"); jailparam_add("enforce_statfs", "1"); - while ((opt = getopt(argc, argv, "o:")) != -1) { + while ((opt = getopt(argc, argv, "o:u:")) != -1) { switch (opt) { case 'o': if (jailparam_addarg(optarg)) { @@ -147,6 +194,14 @@ bectl_cmd_jail(int argc, char *argv[]) default_name = false; if (strcmp(optarg, "host.hostname") == 0) default_hostname = false; + } + break; + case 'u': + if (jailparam_delarg(optarg)) { + if (strcmp(optarg, "name") == 0) + default_name = true; + if (strcmp(optarg, "host.hostname") == 0) + default_hostname = true; } break; default: