]> arthur.barton.de Git - bup.git/commitdiff
is_superuser: test for group 544 or 0 on cygwin
authorRob Browning <rlb@defaultvalue.org>
Sat, 31 Mar 2018 16:53:24 +0000 (11:53 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 7 Apr 2018 19:44:52 +0000 (14:44 -0500)
This appears to be the appropriate way to check for admin status in
cygwin right now: https://cygwin.com/ml/cygwin/2015-02/msg00057.html

Thanks to at least Andrew Skretvedt, Ruvim Pinka, renpj, and Iar De
for reporting the problem, Ruvim Pinka, Paul Kronenwetter, and renpj
for proposing earlier solutions, and Ben Kelly and Johannes Berg for
helping test this approach.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/helpers.py
t/root-status

index 583c65b4bf07f040102c153638ff2d1c62b245a2..1bae59d22e99da707daac8198bcba5c0275882b7 100644 (file)
@@ -350,19 +350,13 @@ def detect_fakeroot():
     return os.getenv("FAKEROOTKEY") != None
 
 
-_warned_about_superuser_detection = None
-def is_superuser():
-    if sys.platform.startswith('cygwin'):
-        if sys.getwindowsversion()[0] > 5:
-            # Sounds like situation is much more complicated here
-            global _warned_about_superuser_detection
-            if not _warned_about_superuser_detection:
-                log("can't detect root status for OS version > 5; assuming not root")
-                _warned_about_superuser_detection = True
-            return False
-        import ctypes
-        return ctypes.cdll.shell32.IsUserAnAdmin()
-    else:
+if sys.platform.startswith('cygwin'):
+    def is_superuser():
+        # https://cygwin.com/ml/cygwin/2015-02/msg00057.html
+        groups = os.getgroups()
+        return 544 in groups or 0 in groups
+else:
+    def is_superuser():
         return os.geteuid() == 0
 
 
index 28e2347357b6a0bc1a9ff7e595a3c9f869b10c04..69fad4e37fa1943058a852f0bb06dcf78c19d03e 100755 (executable)
@@ -9,15 +9,9 @@ from __future__ import absolute_import, print_function
 from sys import stderr
 import sys
 
-
 if sys.platform.startswith('cygwin'):
-    if sys.getwindowsversion()[0] > 5:
-        # Sounds like the situation is much more complicated here
-        print("can't detect root status for OS version > 5; assuming not root",
-              file=stderr)
-        print('none')
-    import ctypes
-    if ctypes.cdll.shell32.IsUserAnAdmin():
+    groups = os.getgroups()
+    if 544 in groups or 0 in groups:
         print('root')
     else:
         print('none')