From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 13 11:09:08 2011 Received: (at submit) by debbugs.gnu.org; 13 Jul 2011 15:09:08 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qh13j-0006VY-8O for submit@debbugs.gnu.org; Wed, 13 Jul 2011 11:09:08 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qgwxc-0002dP-Sa for submit@debbugs.gnu.org; Wed, 13 Jul 2011 06:46:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QgwxT-0008Ro-Jn for submit@debbugs.gnu.org; Wed, 13 Jul 2011 06:46:27 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:56716) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgwxT-0008Ra-5b for submit@debbugs.gnu.org; Wed, 13 Jul 2011 06:46:23 -0400 Received: from eggs.gnu.org ([140.186.70.92]:50238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgwxO-0008Lp-QY for bug-coreutils@gnu.org; Wed, 13 Jul 2011 06:46:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QgwxK-0008QZ-O1 for bug-coreutils@gnu.org; Wed, 13 Jul 2011 06:46:18 -0400 Received: from smtp-vbr14.xs4all.nl ([194.109.24.34]:2906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgwxK-0008QD-4g for bug-coreutils@gnu.org; Wed, 13 Jul 2011 06:46:14 -0400 Received: from webmail.xs4all.nl (dovemail9.xs4all.nl [194.109.26.11]) by smtp-vbr14.xs4all.nl (8.13.8/8.13.8) with ESMTP id p6DAkAig074142 for ; Wed, 13 Jul 2011 12:46:10 +0200 (CEST) (envelope-from zaerc@xs4all.nl) Received: from 194.109.161.58 (SquirrelMail authenticated user zaerc) by webmail.xs4all.nl with HTTP; Wed, 13 Jul 2011 12:46:10 +0200 Message-ID: <3f4f11d8122225dbfbdd253ede266531.squirrel@webmail.xs4all.nl> Date: Wed, 13 Jul 2011 12:46:10 +0200 Subject: Feature patch for chroot, adding --hostname parameter From: zaerc@xs4all.nl To: bug-coreutils@gnu.org User-Agent: SquirrelMail/1.4.18 MIME-Version: 1.0 Content-Type: multipart/mixed;boundary="----=_20110713124610_36628" X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-operating-system: by eggs.gnu.org: FreeBSD 4.6-4.9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -6.6 (------) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 13 Jul 2011 11:09:06 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.6 (------) ------=_20110713124610_36628 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Hello, Here is a small patch to chroot that adds the ability to run the chroot environment with a different namespace for the hostname. I am hoping that other people (besides myself) will find this feature useful, and that it will be considered for inclusion in the excellent coreutils suite. The additional code is plainly stolen from Michael Marineau's chname tool, so I reckon most of the credit should go to him. (see http://mike.marineau.org/blog/code/2007-07-23-giving-chroot-its-own-hostname-chname ) With kind regards, Zaerc Rene. ------=_20110713124610_36628 Content-Type: text/x-patch; name="coreutils_chroot-hostname.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="coreutils_chroot-hostname.patch" diff -ur coreutils-8.5.orig/src/chroot.c coreutils-8.5/src/chroot.c --- coreutils-8.5.orig/src/chroot.c 2010-04-20 21:52:04.000000000 +0200 +++ coreutils-8.5/src/chroot.c 2011-07-07 15:29:47.000000000 +0200 @@ -21,6 +21,7 @@ #include #include #include +#include #include "system.h" #include "error.h" @@ -37,16 +38,22 @@ # define MAXGID GID_T_MAX #endif +#ifndef CLONE_NEWUTS +# define CLONE_NEWUTS 0x04000000 +#endif + enum { GROUPS = UCHAR_MAX + 1, - USERSPEC + USERSPEC, + HOSTNAME }; static struct option const long_opts[] = { {"groups", required_argument, NULL, GROUPS}, {"userspec", required_argument, NULL, USERSPEC}, + {"hostname", required_argument, NULL, HOSTNAME}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} @@ -132,6 +139,7 @@ fputs (_("\ --userspec=USER:GROUP specify user and group (ID or name) to use\n\ --groups=G_LIST specify supplementary groups as g1,g2,..,gN\n\ + --hostname=HOSTNAME specify a different hostname\n\ "), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); @@ -151,6 +159,7 @@ int c; char const *userspec = NULL; char const *groups = NULL; + char const *hostname = NULL; initialize_main (&argc, &argv); set_program_name (argv[0]); @@ -173,6 +182,10 @@ groups = optarg; break; + case HOSTNAME: + hostname = optarg; + break; + case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); @@ -188,6 +201,18 @@ usage (EXIT_CANCELED); } + if (hostname) + { + // Use 'syscall' instead of unshare incase glibc doesn't have it. + // unshare(CLONE_NEWUTS); + if (syscall(__NR_unshare, CLONE_NEWUTS)) + error (EXIT_CANCELED, errno, _("new utsname namespace failed")); + + if (sethostname(hostname, strlen(hostname)+1)) + error (EXIT_CANCELED, errno, _("set hostname failed")); + } + + if (chroot (argv[optind]) != 0) error (EXIT_CANCELED, errno, _("cannot change root directory to %s"), argv[optind]); ------=_20110713124610_36628-- From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 15 09:33:21 2018 Received: (at 9067) by debbugs.gnu.org; 15 Oct 2018 13:33:21 +0000 Received: from localhost ([127.0.0.1]:49916 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gC2zp-0001id-3u for submit@debbugs.gnu.org; Mon, 15 Oct 2018 09:33:21 -0400 Received: from mail-pf1-f178.google.com ([209.85.210.178]:38054) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gC2zl-0001iK-UJ; Mon, 15 Oct 2018 09:33:18 -0400 Received: by mail-pf1-f178.google.com with SMTP id f29-v6so9701146pff.5; Mon, 15 Oct 2018 06:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=3eaDrVyCMesPQT8J9ma5fzIGWRlJfeA2/o88xcyN+LA=; b=kn5ougBqq6PYP+2YkOVqJ7Qw++8qP4/Bov4i0R7AYuWAt2nP27OwMTI9CDPnqNNhYe zw+4HC0dBvZIKgov0/Ke5ppJ0LuBubA6L+393roCcduD3qnZ1rtjvfmn3t+Ay0zTl4yf Z540ddDgziI60PkCsLcIY3gzvvuikw5+nkqcqcoZrfB/rtBhPr5vJnzzgHuo8/3F1Odj sJPh3ugMlKw7YiSsi4YcOLUGP1pH2juWx6Jng3/R4i6HvKtAa8VUQSZcoo6HRxrEb1Xq 5b1U/VSlMw+XdviKSmBKvFu/sEimC82tDSoJf7TZirlZGOfcwp5hC6Cujhgora59BtGp mU3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3eaDrVyCMesPQT8J9ma5fzIGWRlJfeA2/o88xcyN+LA=; b=Jsr9htxooqSfbh016z1Gzbj/qnVlqu7B81KYSwSKGhWlM9XXLj/ltJABlekJyKWqPB 2jia0PPzJf1oAPih651ySydidHo+Iby5t24ALaGFTcGwgdIRjzacUSFTzxpv7WXV5yx0 dIiukWp2eP0hwZJsMaYLHteolsgcQGZFtOYRQAfIccg6U6KyDYMLvnEuYR9rVZ17MJiF GYWceZfWgVsOlqgd+kqw6IrMWRSxZdyftHS7qALy2skaPJCWLZr/QMvr5d9Mv0MtALPy SP6q+71SN8zpXIJGZuZLcst/qrBSfNDTpu5dSHmBb065OI4dI3TRcUztPxlAYpBy7XkR c34w== X-Gm-Message-State: ABuFfohn6ZiqVZWgZi5xfml8vAe+ja9BUClK+KvEKumt8tYk6GFlBXWk N2rxK5J7GkaQ4dwhVt20QvtxPQuv X-Google-Smtp-Source: ACcGV63WzmHL259euLSgxx5CrBjY5fhsNLM2dc1NYsrZcnqfJLW2VukkO5X9Gcx4gVjAQMmyfJsiJA== X-Received: by 2002:a62:61c7:: with SMTP id v190-v6mr16664329pfb.232.1539610391345; Mon, 15 Oct 2018 06:33:11 -0700 (PDT) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id y10-v6sm17980895pgi.85.2018.10.15.06.33.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 06:33:10 -0700 (PDT) Subject: Re: bug#9067: Feature patch for chroot, adding --hostname parameter To: zaerc@xs4all.nl, 9067@debbugs.gnu.org References: <3f4f11d8122225dbfbdd253ede266531.squirrel@webmail.xs4all.nl> From: Assaf Gordon Message-ID: <586a2951-7dd8-cda7-8fa7-dc931ccf8ed9@gmail.com> Date: Mon, 15 Oct 2018 07:33:08 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <3f4f11d8122225dbfbdd253ede266531.squirrel@webmail.xs4all.nl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 9067 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) severity 9067 wishlist tags 9067 wontfix close 9067 (triaging old bugs) Hello, On 13/07/11 04:46 AM, zaerc@xs4all.nl wrote: > Here is a small patch to chroot that adds the ability to run the chroot > environment with a different namespace for the hostname. > > I am hoping that other people (besides myself) will find this feature > useful, and that it will be considered for inclusion in the excellent > coreutils suite. > > The additional code is plainly stolen from Michael Marineau's chname tool, > so I reckon most of the credit should go to him. (see > http://mike.marineau.org/blog/code/2007-07-23-giving-chroot-its-own-hostname-chname > ) Thank you for the patch, sorry it fell between the cracks and have not been responded to in so long. In the long time since your suggestion, the util-linux package gained unshare(1) and nsenter(1), as well as many other new 3rd-party tools to control namespaces. As such, I'm closing the bug. regards, - assaf From unknown Sun Jun 15 13:00:59 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 13 Nov 2018 12:24:11 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator