From: Tim Beale Date: Tue, 2 Oct 2018 19:56:45 +0000 (+1300) Subject: provision: Fallback to assumption root-UID==zero X-Git-Tag: ldb-2.0.5~521 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2f0ebb073353196f381fe2e01e4001983710255;p=thirdparty%2Fsamba.git provision: Fallback to assumption root-UID==zero Which is not a terrible assumption to make. The super-user on linux will always have UID of zero, however, the super-user will not necessarily be called "root". This makes the provision/join commands work better when run in a container. (And while deploying Samba in a container is perhaps not the smartest move, this gives us some versatility when testing Samba). This is needed to get the provision commands working in the domain_backup tests when run with USE_NAMESPACES=1. Signed-off-by: Tim Beale Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/provision/__init__.py b/python/samba/provision/__init__.py index 2bb2614e629..14ab41be670 100644 --- a/python/samba/provision/__init__.py +++ b/python/samba/provision/__init__.py @@ -540,6 +540,16 @@ def findnss_gid(names): return findnss(grp.getgrnam, names)[2] +def get_root_uid(root, logger): + try: + root_uid = findnss_uid(root) + except KeyError as e: + logger.info(e) + logger.info("Assuming root user has UID zero") + root_uid = 0 + return root_uid + + def provision_paths_from_lp(lp, dnsdomain): """Set the default paths for provisioning. @@ -2152,7 +2162,7 @@ def provision(logger, session_info, smbconf=None, if domainsid is None: domainsid = security.random_sid() - root_uid = findnss_uid([root or "root"]) + root_uid = get_root_uid([root or "root"], logger) nobody_uid = findnss_uid([nobody or "nobody"]) users_gid = findnss_gid([users or "users", 'users', 'other', 'staff']) root_gid = pwd.getpwuid(root_uid).pw_gid