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

This commit is contained in:
Marek Marczykowski-Górecki 2013-07-30 10:42:08 +02:00
parent b323a4d1e3
commit eaac99bf64
12 changed files with 14 additions and 12 deletions

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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."

View File

@ -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)

View File

@ -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."