From eaac99bf64e1b082687510c4188d305f5bf5e383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 30 Jul 2013 10:42:08 +0200 Subject: [PATCH] qvm-tools: check if running as root only on systems with os.geteuid --- qvm-tools/qvm-add-appvm | 2 +- qvm-tools/qvm-add-template | 2 +- qvm-tools/qvm-backup | 2 +- qvm-tools/qvm-backup-restore | 4 +++- qvm-tools/qvm-block | 2 +- qvm-tools/qvm-clone | 2 +- qvm-tools/qvm-create | 2 +- qvm-tools/qvm-firewall | 2 +- qvm-tools/qvm-prefs | 2 +- qvm-tools/qvm-remove | 2 +- qvm-tools/qvm-revert-template-changes | 2 +- qvm-tools/qvm-usb | 2 +- 12 files changed, 14 insertions(+), 12 deletions(-) diff --git a/qvm-tools/qvm-add-appvm b/qvm-tools/qvm-add-appvm index 3e080b3f..d7c94ad6 100755 --- a/qvm-tools/qvm-add-appvm +++ b/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." diff --git a/qvm-tools/qvm-add-template b/qvm-tools/qvm-add-template index 867f4fda..16b2011e 100755 --- a/qvm-tools/qvm-add-template +++ b/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." diff --git a/qvm-tools/qvm-backup b/qvm-tools/qvm-backup index 36218f16..dff4e9e5 100755 --- a/qvm-tools/qvm-backup +++ b/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." diff --git a/qvm-tools/qvm-backup-restore b/qvm-tools/qvm-backup-restore index 8f27b295..c07119d6 100755 --- a/qvm-tools/qvm-backup-restore +++ b/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." diff --git a/qvm-tools/qvm-block b/qvm-tools/qvm-block index 1dcbc2d5..17bf05c0 100755 --- a/qvm-tools/qvm-block +++ b/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." diff --git a/qvm-tools/qvm-clone b/qvm-tools/qvm-clone index ae0c9d98..e2eba3b3 100755 --- a/qvm-tools/qvm-clone +++ b/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." diff --git a/qvm-tools/qvm-create b/qvm-tools/qvm-create index fe75bc66..1e2ac66a 100755 --- a/qvm-tools/qvm-create +++ b/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." diff --git a/qvm-tools/qvm-firewall b/qvm-tools/qvm-firewall index 64be8fe8..7ccebafb 100755 --- a/qvm-tools/qvm-firewall +++ b/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." diff --git a/qvm-tools/qvm-prefs b/qvm-tools/qvm-prefs index c12850a1..78e6c819 100755 --- a/qvm-tools/qvm-prefs +++ b/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." diff --git a/qvm-tools/qvm-remove b/qvm-tools/qvm-remove index fdb92a4c..4330fa32 100755 --- a/qvm-tools/qvm-remove +++ b/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." diff --git a/qvm-tools/qvm-revert-template-changes b/qvm-tools/qvm-revert-template-changes index fc2d6261..29c491ca 100755 --- a/qvm-tools/qvm-revert-template-changes +++ b/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) diff --git a/qvm-tools/qvm-usb b/qvm-tools/qvm-usb index 9badab29..31556379 100755 --- a/qvm-tools/qvm-usb +++ b/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."