qvm-tools: check if running as root only on systems with os.geteuid
This commit is contained in:
		
							parent
							
								
									b323a4d1e3
								
							
						
					
					
						commit
						eaac99bf64
					
				| @ -48,7 +48,7 @@ def main(): | |||||||
|     vmname = args[0] |     vmname = args[0] | ||||||
|     templatename = args[1] |     templatename = args[1] | ||||||
| 
 | 
 | ||||||
|     if os.geteuid() == 0: |     if hasattr(os, "geteuid") and os.geteuid() == 0: | ||||||
|         if not options.force_root: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ def main(): | |||||||
|         parser.error ("You must specify at least the TemplateVM name!") |         parser.error ("You must specify at least the TemplateVM name!") | ||||||
|     vmname = args[0] |     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: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
| @ -75,7 +75,7 @@ def main(): | |||||||
| 
 | 
 | ||||||
|     base_backup_dir = args[0] |     base_backup_dir = args[0] | ||||||
| 
 | 
 | ||||||
|     if os.geteuid() == 0: |     if hasattr(os, "geteuid") and os.geteuid() == 0: | ||||||
|         if not options.force_root: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
| @ -175,7 +175,9 @@ def main(): | |||||||
|         if 'username-mismatch' in vm_info.keys(): |         if 'username-mismatch' in vm_info.keys(): | ||||||
|             dom0_username_mismatch = True |             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." |         print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|         if options.force_root: |         if options.force_root: | ||||||
|             print >> sys.stderr, "Continuing as commanded. You have been warned." |             print >> sys.stderr, "Continuing as commanded. You have been warned." | ||||||
|  | |||||||
| @ -56,7 +56,7 @@ def main(): | |||||||
| 
 | 
 | ||||||
|     (options, args) = parser.parse_args () |     (options, args) = parser.parse_args () | ||||||
| 
 | 
 | ||||||
|     if os.geteuid() == 0: |     if hasattr(os, "geteuid") and os.geteuid() == 0: | ||||||
|         if not options.force_root: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
| @ -45,7 +45,7 @@ def main(): | |||||||
|     srcname = args[0] |     srcname = args[0] | ||||||
|     dstname = args[1] |     dstname = args[1] | ||||||
| 
 | 
 | ||||||
|     if os.geteuid() == 0: |     if hasattr(os, "geteuid") and os.geteuid() == 0: | ||||||
|         if not options.force_root: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
| @ -69,7 +69,7 @@ def main(): | |||||||
|     if (options.netvm + options.proxyvm + options.hvm + options.hvm_template) > 1: |     if (options.netvm + options.proxyvm + options.hvm + options.hvm_template) > 1: | ||||||
|         parser.error ("You must specify at most one VM type switch") |         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." |         print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|         if options.force_root: |         if options.force_root: | ||||||
|             print >> sys.stderr, "Continuing as commanded. You have been warned." |             print >> sys.stderr, "Continuing as commanded. You have been warned." | ||||||
|  | |||||||
| @ -257,7 +257,7 @@ def main(): | |||||||
|     vmname = args[0] |     vmname = args[0] | ||||||
|     args = args[1:] |     args = args[1:] | ||||||
| 
 | 
 | ||||||
|     if os.geteuid() == 0: |     if hasattr(os, "geteuid") and os.geteuid() == 0: | ||||||
|         if not options.force_root: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
| @ -477,7 +477,7 @@ def main(): | |||||||
| 
 | 
 | ||||||
|     vmname = args[0] |     vmname = args[0] | ||||||
| 
 | 
 | ||||||
|     if os.geteuid() == 0: |     if hasattr(os, "geteuid") and os.geteuid() == 0: | ||||||
|         if not options.force_root: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ def main(): | |||||||
|         print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname) |         print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname) | ||||||
|         exit(1) |         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." |         print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|         if options.force_root: |         if options.force_root: | ||||||
|             print >> sys.stderr, "Continuing as commanded. You have been warned." |             print >> sys.stderr, "Continuing as commanded. You have been warned." | ||||||
|  | |||||||
| @ -41,7 +41,7 @@ def main(): | |||||||
|         parser.error ("You must specify TemplateVM name!") |         parser.error ("You must specify TemplateVM name!") | ||||||
|     vmname = args[0] |     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!" |         print >> sys.stderr, "ERROR: This tool must be run as root!" | ||||||
|         exit(1) |         exit(1) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -67,7 +67,7 @@ def main(): | |||||||
|         else: |         else: | ||||||
|             exit(1) |             exit(1) | ||||||
| 
 | 
 | ||||||
|     if os.geteuid() == 0: |     if hasattr(os, "geteuid") and os.geteuid() == 0: | ||||||
|         if not options.force_root: |         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, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." | ||||||
|             print >> sys.stderr, "Retry as unprivileged user." |             print >> sys.stderr, "Retry as unprivileged user." | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Marek Marczykowski-Górecki
						Marek Marczykowski-Górecki