provision: Fallback to assumption root-UID==zero
authorTim Beale <timbeale@catalyst.net.nz>
Tue, 2 Oct 2018 19:56:45 +0000 (08:56 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 31 May 2019 05:18:21 +0000 (05:18 +0000)
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 <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/provision/__init__.py

index 2bb2614e6296fe7223f97822a053ecd57166443a..14ab41be67005ce9e4e4a6fbd1b0cfce605c971a 100644 (file)
@@ -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