Changeset View
Changeset View
Standalone View
Standalone View
sbin/bectl/bectl_jail.c
Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | if (strcmp(name, "path") == 0) | ||||
*mnt_loc = '\0'; | *mnt_loc = '\0'; | ||||
return (jailparam_del(name)); | return (jailparam_del(name)); | ||||
} | } | ||||
int | int | ||||
bectl_cmd_jail(int argc, char *argv[]) | bectl_cmd_jail(int argc, char *argv[]) | ||||
{ | { | ||||
char *bootenv, *mountpoint; | char *bootenv, *mountpoint; | ||||
int jid, opt, ret; | int jid, mntflags, opt, ret; | ||||
bool default_hostname, interactive, unjail; | bool default_hostname, interactive, unjail; | ||||
pid_t pid; | pid_t pid; | ||||
mntflags = BE_MNT_DEEP; | |||||
default_hostname = interactive = unjail = true; | default_hostname = interactive = unjail = true; | ||||
jpcnt = INIT_PARAMCOUNT; | jpcnt = INIT_PARAMCOUNT; | ||||
jp = malloc(jpcnt * sizeof(*jp)); | jp = malloc(jpcnt * sizeof(*jp)); | ||||
if (jp == NULL) | if (jp == NULL) | ||||
err(2, "malloc"); | err(2, "malloc"); | ||||
jailparam_add("persist", "true"); | jailparam_add("persist", "true"); | ||||
jailparam_add("allow.mount", "true"); | jailparam_add("allow.mount", "true"); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | bectl_cmd_jail(int argc, char *argv[]) | ||||
/* | /* | ||||
* XXX TODO: if its already mounted, perhaps there should be a flag to | * XXX TODO: if its already mounted, perhaps there should be a flag to | ||||
* indicate its okay to proceed?? | * indicate its okay to proceed?? | ||||
*/ | */ | ||||
if (*mnt_loc == '\0') | if (*mnt_loc == '\0') | ||||
mountpoint = NULL; | mountpoint = NULL; | ||||
else | else | ||||
mountpoint = mnt_loc; | mountpoint = mnt_loc; | ||||
if (be_mount(be, bootenv, mountpoint, 0, mnt_loc) != BE_ERR_SUCCESS) { | if (be_mount(be, bootenv, mountpoint, mntflags, mnt_loc) != BE_ERR_SUCCESS) { | ||||
fprintf(stderr, "could not mount bootenv\n"); | fprintf(stderr, "could not mount bootenv\n"); | ||||
return (1); | return (1); | ||||
} | } | ||||
if (default_hostname) | if (default_hostname) | ||||
jailparam_add("host.hostname", bootenv); | jailparam_add("host.hostname", bootenv); | ||||
/* | /* | ||||
Show All 34 Lines | case 0: | ||||
_exit(1); | _exit(1); | ||||
default: | default: | ||||
/* Wait for the child to get back, see if we need to unjail */ | /* Wait for the child to get back, see if we need to unjail */ | ||||
waitpid(pid, NULL, 0); | waitpid(pid, NULL, 0); | ||||
} | } | ||||
if (unjail) { | if (unjail) { | ||||
jail_remove(jid); | jail_remove(jid); | ||||
unmount(mnt_loc, 0); | be_unmount(be, bootenv, 0); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
bectl_search_jail_paths(const char *mnt) | bectl_search_jail_paths(const char *mnt) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | bectl_cmd_unjail(int argc, char *argv[]) | ||||
if (be_mounted_at(be, path, NULL) != 0) { | if (be_mounted_at(be, path, NULL) != 0) { | ||||
fprintf(stderr, "bectl %s: jail requested by '%s' not a BE\n", | fprintf(stderr, "bectl %s: jail requested by '%s' not a BE\n", | ||||
cmd, target); | cmd, target); | ||||
return (1); | return (1); | ||||
} | } | ||||
jail_remove(jid); | jail_remove(jid); | ||||
unmount(path, 0); | be_unmount(be, target, 0); | ||||
return (0); | return (0); | ||||
} | } |