aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-08-06 15:21:46 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-08-06 15:21:46 +0000
commit2a0b8dc2cb22e39d566e30c03ed437d494f99821 (patch)
treed13932ae9157d52e9a4a70147150fdbf31eb5942 /sbin
parent526ad58e80386abf435e435d34ab2e535c6cf392 (diff)
downloadsrc-2a0b8dc2cb22e39d566e30c03ed437d494f99821.tar.gz
src-2a0b8dc2cb22e39d566e30c03ed437d494f99821.zip
bectl(8): Provide -u option to unset jail parameters
All but name, host.hostname, and path may be completely unset.
Notes
Notes: svn path=/projects/bectl/; revision=337380
Diffstat (limited to 'sbin')
-rw-r--r--sbin/bectl/bectl.826
-rw-r--r--sbin/bectl/bectl.c2
-rw-r--r--sbin/bectl/bectl_jail.c57
3 files changed, 78 insertions, 7 deletions
diff --git a/sbin/bectl/bectl.8 b/sbin/bectl/bectl.8
index a55e9af8aaf5..22baa0574c0b 100644
--- a/sbin/bectl/bectl.8
+++ b/sbin/bectl/bectl.8
@@ -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
diff --git a/sbin/bectl/bectl.c b/sbin/bectl/bectl.c
index 405edf5dfb8c..da01840ed196 100644
--- a/sbin/bectl/bectl.c
+++ b/sbin/bectl/bectl.c
@@ -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"
diff --git a/sbin/bectl/bectl_jail.c b/sbin/bectl/bectl_jail.c
index b012a906c5e2..1731af43514d 100644
--- a/sbin/bectl/bectl_jail.c
+++ b/sbin/bectl/bectl_jail.c
@@ -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)) {
@@ -149,6 +196,14 @@ bectl_cmd_jail(int argc, char *argv[])
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:
fprintf(stderr, "bectl jail: unknown option '-%c'\n",
optopt);