From 7c25d22d4146033cfb1e0775d06912b5c8f77e73 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sat, 30 Nov 2019 09:56:23 +0100 Subject: [PATCH] Add lxcid --- usr/bin/lxcid | 23 +++++++++++++++++++++++ usr/lib/python3.6/lxcmgr/lxcmgr.py | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 usr/bin/lxcid diff --git a/usr/bin/lxcid b/usr/bin/lxcid new file mode 100755 index 0000000..092d25e --- /dev/null +++ b/usr/bin/lxcid @@ -0,0 +1,23 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import argparse +import subprocess +import sys + +parser = argparse.ArgumentParser(description='Print shifted UID / GID of an LXC user') +parser.add_argument('--group', '-g', action='store_true', help='Get primary GID') +parser.add_argument('container', help='LXC container in which to lookup') +parser.add_argument('user', help='User to lookup') + +if len(sys.argv) < 2: + parser.print_usage() + sys.exit(1) +args = parser.parse_args() + +# Check if lxc-ls prints back the container name +is_running = subprocess.run(['lxc-ls', '--running', args.container], stdout=subprocess.PIPE, check=True) +lxc_command = 'lxc-attach' if is_running else 'lxc-execute' +# Run id command inside container +id = subprocess.run([lxc_command, args.container, '--', 'id', '-g' if args.group else '-u', args.user], stdout=subprocess.PIPE, check=True) +print(int(id.stdout) + 100000) diff --git a/usr/lib/python3.6/lxcmgr/lxcmgr.py b/usr/lib/python3.6/lxcmgr/lxcmgr.py index 1939921..e21a1b0 100644 --- a/usr/lib/python3.6/lxcmgr/lxcmgr.py +++ b/usr/lib/python3.6/lxcmgr/lxcmgr.py @@ -58,7 +58,7 @@ def create_container(container, image): uid = image['uid'] if 'uid' in image else '0' gid = image['gid'] if 'gid' in image else '0' cmd = image['cmd'] if 'cmd' in image else '/bin/sh' - cwd = image['cwd'] if 'cwd' in image else '/' + cwd = image['cwd'] if 'cwd' in image else '/root' halt = image['halt'] if 'halt' in image else 'SIGINT' # Lease the first unused IP to the container ipv4 = update_hosts_lease(container, True)