]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools/lxc-attach: add -u and -g arguments
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 9 Sep 2018 11:22:58 +0000 (13:22 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 11 Sep 2018 08:54:46 +0000 (10:54 +0200)
This lets users specify uids and gids to switch to.

Closes #2591.

Signed-off-by: Disassembler disassembler@dasm.cz
[christian.brauner@ubuntu.com: adapt coding style + commit message]

doc/lxc-attach.sgml.in
doc/lxc-execute.sgml.in
src/lxc/tools/lxc_attach.c

index 713a30e7fbc921c122e303b3a2f5713f4fe09e46..14fa77d7995c531fd942eaabf76970c6095c5830 100644 (file)
@@ -60,6 +60,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
       <arg choice="opt">--clear-env</arg>
       <arg choice="opt">-v, --set-var <replaceable>variable</replaceable></arg>
       <arg choice="opt">--keep-var <replaceable>variable</replaceable></arg>
+      <arg choice="opt">-u, --uid <replaceable>uid</replaceable></arg>
+      <arg choice="opt">-g, --gid <replaceable>gid</replaceable></arg>
       <arg choice="opt">-- <replaceable>command</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
@@ -282,6 +284,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
        </listitem>
       </varlistentry>
 
+      <varlistentry>
+       <term>
+         <option>--u, --uid <replaceable>uid</replaceable></option>
+       </term>
+       <listitem>
+         <para>
+           Executes the <replaceable>command</replaceable> with user ID
+          <replaceable>uid</replaceable> inside the container.
+         </para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
+       <term>
+         <option>--g, --gid <replaceable>gid</replaceable></option>
+       </term>
+       <listitem>
+         <para>
+           Executes the <replaceable>command</replaceable> with group ID
+          <replaceable>gid</replaceable> inside the container.
+         </para>
+       </listitem>
+      </varlistentry>
+
      </variablelist>
 
   </refsect1>
index 20814348d20cc82fb57f50522e2c1e291e279dec..8b249b3298853a1e7b27f8c179465a7c82d11a43 100644 (file)
@@ -53,6 +53,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
       <arg choice="opt">-d</arg>
       <arg choice="opt">-f <replaceable>config_file</replaceable></arg>
       <arg choice="opt">-s KEY=VAL</arg>
+      <arg choice="opt">-u, --uid <replaceable>uid</replaceable></arg>
+      <arg choice="opt">-g, --gid <replaceable>gid</replaceable></arg>
       <arg choice="opt">-- <replaceable>command</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
@@ -139,6 +141,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
        </listitem>
       </varlistentry>
 
+      <varlistentry>
+       <term>
+         <option>--u, --uid <replaceable>uid</replaceable></option>
+       </term>
+       <listitem>
+         <para>
+           Executes the <replaceable>command</replaceable> with user ID
+          <replaceable>uid</replaceable> inside the container.
+         </para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
+       <term>
+         <option>--g, --gid <replaceable>gid</replaceable></option>
+       </term>
+       <listitem>
+         <para>
+           Executes the <replaceable>command</replaceable> with group ID
+          <replaceable>gid</replaceable> inside the container.
+         </para>
+       </listitem>
+      </varlistentry>
+
       <varlistentry>
        <term><option>--</option></term>
        <listitem>
index e98f0a056e789cd8b830ffe698ed3ea3452a1646..551f9f39621e0cdd4b1e73b903b510f3a5357924 100644 (file)
@@ -72,6 +72,8 @@ static const struct option my_longopts[] = {
        {"set-var", required_argument, 0, 'v'},
        {"pty-log", required_argument, 0, 'L'},
        {"rcfile", required_argument, 0, 'f'},
+       {"uid", required_argument, 0, 'u'},
+       {"gid", required_argument, 0, 'g'},
        LXC_COMMON_OPTIONS
 };
 
@@ -122,6 +124,8 @@ Options :\n\
                     multiple times.\n\
   -f, --rcfile=FILE\n\
                     Load configuration file FILE\n\
+  -u, --uid=UID     Execute COMMAND with UID inside the container\n\
+  -g, --gid=GID     Execute COMMAND with GID inside the container\n\
 ",
        .options      = my_longopts,
        .parser       = my_parser,
@@ -187,6 +191,14 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
        case 'f':
                args->rcfile = arg;
                break;
+       case 'u':
+               if (lxc_safe_uint(arg, &args->uid) < 0)
+                       return -1;
+               break;
+       case 'g':
+               if (lxc_safe_uint(arg, &args->gid) < 0)
+                       return -1;
+               break;
        }
 
        return 0;
@@ -333,6 +345,12 @@ int main(int argc, char *argv[])
                        goto out;
        }
 
+       if (my_args.uid)
+               attach_options.uid = my_args.uid;
+
+       if (my_args.gid)
+               attach_options.gid = my_args.gid;
+
        if (command.program)
                ret = c->attach(c, lxc_attach_run_command, &command, &attach_options, &pid);
        else