From owner-svn-src-head@freebsd.org Sat Aug 18 01:12:46 2018 Return-Path: Delivered-To: svn-src-head@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 4B67C1080CCC; Sat, 18 Aug 2018 01:12:46 +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 EE83D7B27F; Sat, 18 Aug 2018 01:12:45 +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 CEDF1108B3; Sat, 18 Aug 2018 01:12:45 +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 w7I1CjnV094250; Sat, 18 Aug 2018 01:12:45 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7I1Cjkw094247; Sat, 18 Aug 2018 01:12:45 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808180112.w7I1Cjkw094247@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 18 Aug 2018 01:12:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337993 - head/sbin/bectl X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sbin/bectl X-SVN-Commit-Revision: 337993 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Aug 2018 01:12:46 -0000 Author: kevans Date: Sat Aug 18 01:12:44 2018 New Revision: 337993 URL: https://svnweb.freebsd.org/changeset/base/337993 Log: bectl(8): Allow running a custom command in the 'jail' subcommand Instead of always running /bin/sh, allow the user to specify the command to run. The jail is not removed when the command finishes. Meaning, `bectl unjail` will still need to be run. For example: ``` bectl jail newBE pkg upgrade bectl ujail newBE ``` Submitted by: Shawn Webb Obtained from: HardenedBSD (8b451014ab) Modified: head/sbin/bectl/bectl.8 head/sbin/bectl/bectl.c head/sbin/bectl/bectl_jail.c Modified: head/sbin/bectl/bectl.8 ============================================================================== --- head/sbin/bectl/bectl.8 Sat Aug 18 01:05:38 2018 (r337992) +++ head/sbin/bectl/bectl.8 Sat Aug 18 01:12:44 2018 (r337993) @@ -18,7 +18,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 16, 2018 +.Dd August 17, 2018 .Dt BECTL 8 .Os .Sh NAME @@ -54,6 +54,7 @@ jail .Oo Fl o Ar key Ns = Ns Ar value | Fl u Ar key Oc Ns ... .Ao Ar jailID | jailName Ac .Ao Ar bootenv Ac +.Op Ar utility Op Ar argument ... .Nm list .Op Fl a @@ -150,6 +151,7 @@ from .Oo Fl o Ar key Ns = Ns Ar value | Fl u Ar key Oc Ns ... .Ao Ar jailID | jailName Ac .Ao Ar bootenv Ac +.Op Ar utility Op Ar argument ... .Pp Creates a jail of the given boot environment. Multiple @@ -161,8 +163,16 @@ arguments may be specified. will set a jail parameter, and .Fl u will unset a jail parameter. -By default, jails are created in interactive mode, with a shell being +.Pp +By default, jails are created in interactive mode and +.Pa /bin/sh +is executed within the jail. +If +.Ar utility +is specified, it will be executed instead of +.Pa /bin/sh . +.Pp The .Fl b argument enables batch mode, thereby disabling interactive mode. Modified: head/sbin/bectl/bectl.c ============================================================================== --- head/sbin/bectl/bectl.c Sat Aug 18 01:05:38 2018 (r337992) +++ head/sbin/bectl/bectl.c Sat Aug 18 01:12:44 2018 (r337993) @@ -77,7 +77,7 @@ usage(bool explicit) #if SOON "\tbectl add (path)*\n" #endif - "\tbectl jail [-b] [ -o key=value | -u key ]... bootenv\n" + "\tbectl jail [-b] [ -o key=value | -u key ]... bootenv [utility [argument ...]]\n" "\tbectl list [-a] [-D] [-H] [-s]\n" "\tbectl mount beName [mountpoint]\n" "\tbectl rename origBeName newBeName\n" Modified: head/sbin/bectl/bectl_jail.c ============================================================================== --- head/sbin/bectl/bectl_jail.c Sat Aug 18 01:05:38 2018 (r337992) +++ head/sbin/bectl/bectl_jail.c Sat Aug 18 01:12:44 2018 (r337993) @@ -238,10 +238,6 @@ bectl_cmd_jail(int argc, char *argv[]) fprintf(stderr, "bectl jail: missing boot environment name\n"); return (usage(false)); } - if (argc > 2) { - fprintf(stderr, "bectl jail: too many arguments\n"); - return (usage(false)); - } bootenv = argv[0]; @@ -284,7 +280,10 @@ bectl_cmd_jail(int argc, char *argv[]) if (interactive) { /* We're attached within the jail... good bye! */ chdir("/"); - execl("/bin/sh", "/bin/sh", NULL); + if (argc > 1) + execve(argv[1], &argv[1], NULL); + else + execl("/bin/sh", "/bin/sh", NULL); return (1); }