From owner-svn-src-projects@freebsd.org Thu Jul 26 04:07:38 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 D5C13103A088 for ; Thu, 26 Jul 2018 04:07:37 +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 82D657B629; Thu, 26 Jul 2018 04:07:37 +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 620B223D14; Thu, 26 Jul 2018 04:07:37 +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 w6Q47bYv033952; Thu, 26 Jul 2018 04:07:37 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6Q47biK033951; Thu, 26 Jul 2018 04:07:37 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201807260407.w6Q47biK033951@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 26 Jul 2018 04:07:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r336731 - 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: 336731 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: Thu, 26 Jul 2018 04:07:38 -0000 Author: kevans Date: Thu Jul 26 04:07:36 2018 New Revision: 336731 URL: https://svnweb.freebsd.org/changeset/base/336731 Log: bectl(8): Redo jail using jail(3) API The jail is created with allow.mount, allow.mount.devfs, and enforce_statfs=1. Upon creation, we immediately attach, chdir to "/", and drop the user into a shell inside the jail. The default IP for this is arbitrarily 10.20.30.40. Modified: projects/bectl/sbin/bectl/bectl.c Modified: projects/bectl/sbin/bectl/bectl.c ============================================================================== --- projects/bectl/sbin/bectl/bectl.c Thu Jul 26 03:14:58 2018 (r336730) +++ projects/bectl/sbin/bectl/bectl.c Thu Jul 26 04:07:36 2018 (r336731) @@ -356,8 +356,7 @@ bectl_cmd_jail(int argc, char *argv[]) { char *bootenv; char mnt_loc[BE_MAXPATHLEN]; - char buf[BE_MAXPATHLEN*2]; - int err; + int err, jid; /* struct jail be_jail = { 0 }; */ @@ -376,39 +375,30 @@ bectl_cmd_jail(int argc, char *argv[]) * XXX TODO: if its already mounted, perhaps there should be a flag to * indicate its okay to proceed?? */ - if ((err = be_mount(be, bootenv, NULL, 0, mnt_loc)) != BE_ERR_SUCCESS) + if ((err = be_mount(be, bootenv, NULL, 0, mnt_loc)) != BE_ERR_SUCCESS) { fprintf(stderr, "could not mount bootenv\n"); + return (1); + } - /* - * NOTE: this is not quite functional: - * see https://github.com/vermaden/beadm/blob/master/HOWTO.htm on - * neccesary modifications to correctly boot the jail - */ + /* XXX TODO: Make the IP/hostname configurable? */ + jid = jail_setv(JAIL_CREATE | JAIL_ATTACH, + "name", bootenv, + "path", mnt_loc, + "host.hostname", bootenv, + "persist", "true", + "ip4.addr", "10.20.30.40", + "allow.mount", "true", + "allow.mount.devfs", "true", + "enforce_statfs", "1", + NULL); + if (jid == -1) { + fprintf(stderr, "unable to create jail. error: %d\n", errno); + return (1); + } - /* - * snprintf(buf, BE_MAXPATHLEN*2, "jail %s %s %s /bin/sh /etc/rc", - * mnt_loc, bootenv, "192.168.1.123"); - */ - snprintf(buf, BE_MAXPATHLEN*2, "jail %s %s %s /bin/sh", mnt_loc, - bootenv, "192.168.1.123"); - system(buf); - - unmount(mnt_loc, 0); - - /* - * be_jail.version = JAIL_API_VERSION; - * be_jail.path = "/tmp/be_mount.hCCk"; - * be_jail.jailname = "sdfs"; - * - * if ((jid = jail(&be_jail)) != -1) { - * printf("jail %d created at %s\n", jid, mnt_loc); - * err = 0; - * } else { - * fprintf(stderr, "unable to create jail. error: %d\n", errno); - * err = errno; - * } - */ - + /* We're attached within the jail... good bye! */ + chdir("/"); + execl("/bin/sh", "/bin/sh", NULL); return (0); }