Răsfoiți Sursa

qvm-tools: check if running as root only on systems with os.geteuid

Marek Marczykowski-Górecki 10 ani în urmă
părinte
comite
eaac99bf64

+ 1 - 1
qvm-tools/qvm-add-appvm

@@ -48,7 +48,7 @@ def main():
     vmname = args[0]
     templatename = args[1]
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."

+ 1 - 1
qvm-tools/qvm-add-template

@@ -49,7 +49,7 @@ def main():
         parser.error ("You must specify at least the TemplateVM name!")
     vmname = args[0]
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root and not options.installed_by_rpm:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."

+ 1 - 1
qvm-tools/qvm-backup

@@ -75,7 +75,7 @@ def main():
 
     base_backup_dir = args[0]
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."

+ 3 - 1
qvm-tools/qvm-backup-restore

@@ -175,7 +175,9 @@ def main():
         if 'username-mismatch' in vm_info.keys():
             dom0_username_mismatch = True
 
-    if os.geteuid() == 0:
+    print
+
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
         if options.force_root:
             print >> sys.stderr, "Continuing as commanded. You have been warned."

+ 1 - 1
qvm-tools/qvm-block

@@ -56,7 +56,7 @@ def main():
 
     (options, args) = parser.parse_args ()
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."

+ 1 - 1
qvm-tools/qvm-clone

@@ -45,7 +45,7 @@ def main():
     srcname = args[0]
     dstname = args[1]
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."

+ 1 - 1
qvm-tools/qvm-create

@@ -69,7 +69,7 @@ def main():
     if (options.netvm + options.proxyvm + options.hvm + options.hvm_template) > 1:
         parser.error ("You must specify at most one VM type switch")
         
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
         if options.force_root:
             print >> sys.stderr, "Continuing as commanded. You have been warned."

+ 1 - 1
qvm-tools/qvm-firewall

@@ -257,7 +257,7 @@ def main():
     vmname = args[0]
     args = args[1:]
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."

+ 1 - 1
qvm-tools/qvm-prefs

@@ -477,7 +477,7 @@ def main():
 
     vmname = args[0]
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."

+ 1 - 1
qvm-tools/qvm-remove

@@ -47,7 +47,7 @@ def main():
         print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
         exit(1)
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
         if options.force_root:
             print >> sys.stderr, "Continuing as commanded. You have been warned."

+ 1 - 1
qvm-tools/qvm-revert-template-changes

@@ -41,7 +41,7 @@ def main():
         parser.error ("You must specify TemplateVM name!")
     vmname = args[0]
 
-    if os.geteuid() != 0:
+    if hasattr(os, "geteuid") and os.geteuid() != 0:
         print >> sys.stderr, "ERROR: This tool must be run as root!"
         exit(1)
 

+ 1 - 1
qvm-tools/qvm-usb

@@ -67,7 +67,7 @@ def main():
         else:
             exit(1)
 
-    if os.geteuid() == 0:
+    if hasattr(os, "geteuid") and os.geteuid() == 0:
         if not options.force_root:
             print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
             print >> sys.stderr, "Retry as unprivileged user."