Michał Górny avatar Michał Górny committed 872c281

Always require superuser or --unprivileged-user.

Getting userpriv UID/GID is slicky, so just require root by default.

Comments (0)

Files changed (2)

smartliverebuild/cli.py

 		except Exception:
 			pass
 
-	if opts.setuid:
-		portage_uid = pm_conf.userpriv_uid
-		portage_gid = pm_conf.userpriv_gid
-		if portage_uid and portage_gid and os.geteuid() != 0 and os.getuid() == portage_uid:
-			if not opts.pretend:
-				out.s1('Running as the portage user, assuming --pretend.')
-				opts.pretend = True
-			if opts.quickpkg:
-				out.err("Running as the portage user, --quickpkg probably won't work")
+	if os.geteuid() != 0 and opts.unprivileged_user:
+		if not opts.pretend:
+			out.s1('Running as an unprivileged user, assuming --pretend.')
+			opts.pretend = True
+		if opts.quickpkg:
+			out.err("Running as an unprivileged user, --quickpkg probably won't work")
 
 	try:
 		packages = SmartLiveRebuild(opts, pm, cliargs = args)

smartliverebuild/core.py

 
 	childpid = None
 	commpipe = None
-	userok = (os.geteuid() == 0)
+	superuser = (os.geteuid() == 0)
 	if opts.setuid:
 		pm_conf = pm.config
 		portage_uid = pm_conf.userpriv_uid
 		portage_gid = pm_conf.userpriv_gid
 		if portage_uid and portage_gid:
-			if not userok:
-				if os.getuid() == portage_uid:
-					userok = True
-			else:
+			if superuser:
 				out.s1('Forking to drop superuser privileges ...')
 				commpipe = os.pipe()
 				childpid = os.fork()
 			out.err("setuid requested but there's no 'portage' user in the system")
 			return 1
 
-	if not opts.unprivileged_user and not userok:
-		out.err('Either superuser or portage privileges are required!')
+	if not superuser and not opts.unprivileged_user:
+		out.err('Superuser privileges are required!')
 		out.out('''
-This tool requires either superuser or portage (if FEATURES=userpriv is set)
-privileges. If you would like to force running the update using your current
-user account, please pass the --unprivileged-user option.
+This tool requires superuser privileges. If you would like to force running
+the update using your current user account, please pass the --unprivileged-user
+option.
 ''')
 		raise SLRFailure('')
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.