Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 433453 | Differences between
and this patch

Collapse All | Expand All

(-)a/pym/portage/const.py (+1 lines)
Lines 189-194 SUPPORTED_FEATURES = frozenset([ Link Here
189
	"unmerge-backup",
189
	"unmerge-backup",
190
	"unmerge-logs",
190
	"unmerge-logs",
191
	"unmerge-orphans",
191
	"unmerge-orphans",
192
	"unprivileged",
192
	"userfetch",
193
	"userfetch",
193
	"userpriv",
194
	"userpriv",
194
	"usersandbox",
195
	"usersandbox",
(-)a/pym/portage/data.py (-30 / +65 lines)
Lines 59-64 def portage_group_warning(): Link Here
59
# If the "wheel" group does not exist then wheelgid falls back to 0.
59
# If the "wheel" group does not exist then wheelgid falls back to 0.
60
# If the "portage" group does not exist then portage_uid falls back to wheelgid.
60
# If the "portage" group does not exist then portage_uid falls back to wheelgid.
61
61
62
# If the current user is not root, but has write access to the
63
# EROOT directory (not due to the 0002 bit), then use "unprivileged"
64
# mode which sets secpass = 2 and uses the UID and GID of the EROOT
65
# directory to generate default PORTAGE_INST_GID, PORTAGE_INST_UID,
66
# PORTAGE_USERNAME, and PORTAGE_GRPNAME settings.
67
def _unprivileged_mode(eroot, eroot_st):
68
	return os.getuid() != 0 and os.access(eroot, os.W_OK) and \
69
		not eroot_st.st_mode & 0o0002
70
62
uid = os.getuid()
71
uid = os.getuid()
63
wheelgid = 0
72
wheelgid = 0
64
try:
73
try:
Lines 77-89 def _get_global(k): Link Here
77
	if k in _initialized_globals:
86
	if k in _initialized_globals:
78
		return globals()[k]
87
		return globals()[k]
79
88
80
	if k in ('portage_gid', 'portage_uid', 'secpass'):
89
	if k == 'secpass':
81
		global portage_gid, portage_uid, secpass
90
82
		secpass = 0
91
		unprivileged = False
92
		if hasattr(portage, 'settings'):
93
			unprivileged = "unprivileged" in portage.settings.features
94
		else:
95
			# The config class has equivalent code, but we also need to
96
			# do it here if _disable_legacy_globals() has been called.
97
			eroot = os.path.join(os.environ.get('ROOT', os.sep),
98
				portage.const.EPREFIX.lstrip(os.sep))
99
			try:
100
				eroot_st = os.stat(eroot)
101
			except OSError:
102
				pass
103
			else:
104
				unprivileged = _unprivileged_mode(eroot, eroot_st)
105
106
		v = 0
83
		if uid == 0:
107
		if uid == 0:
84
			secpass = 2
108
			v = 2
85
		elif portage.const.EPREFIX:
109
		elif unprivileged:
86
			secpass = 2
110
			v = 2
111
		elif portage_gid in os.getgroups():
112
			v = 1
113
114
	elif k in ('portage_gid', 'portage_uid'):
115
87
		#Discover the uid and gid of the portage user/group
116
		#Discover the uid and gid of the portage user/group
88
		keyerror = False
117
		keyerror = False
89
		try:
118
		try:
Lines 98-106 def _get_global(k): Link Here
98
			keyerror = True
127
			keyerror = True
99
			portage_gid = 0
128
			portage_gid = 0
100
129
101
		if secpass < 1 and portage_gid in os.getgroups():
102
			secpass = 1
103
104
		# Suppress this error message if both PORTAGE_GRPNAME and
130
		# Suppress this error message if both PORTAGE_GRPNAME and
105
		# PORTAGE_USERNAME are set to "root", for things like
131
		# PORTAGE_USERNAME are set to "root", for things like
106
		# Android (see bug #454060).
132
		# Android (see bug #454060).
Lines 118-133 def _get_global(k): Link Here
118
				noiselevel=-1)
144
				noiselevel=-1)
119
			portage_group_warning()
145
			portage_group_warning()
120
146
147
		globals()['portage_gid'] = portage_gid
121
		_initialized_globals.add('portage_gid')
148
		_initialized_globals.add('portage_gid')
149
		globals()['portage_uid'] = portage_uid
122
		_initialized_globals.add('portage_uid')
150
		_initialized_globals.add('portage_uid')
123
		_initialized_globals.add('secpass')
124
151
125
		if k == 'portage_gid':
152
		if k == 'portage_gid':
126
			return portage_gid
153
			return portage_gid
127
		elif k == 'portage_uid':
154
		elif k == 'portage_uid':
128
			return portage_uid
155
			return portage_uid
129
		elif k == 'secpass':
130
			return secpass
131
		else:
156
		else:
132
			raise AssertionError('unknown name: %s' % k)
157
			raise AssertionError('unknown name: %s' % k)
133
158
Lines 178-188 def _get_global(k): Link Here
178
			v = os.environ[env_key]
203
			v = os.environ[env_key]
179
		elif hasattr(portage, 'settings'):
204
		elif hasattr(portage, 'settings'):
180
			v = portage.settings.get(env_key)
205
			v = portage.settings.get(env_key)
181
		elif portage.const.EPREFIX:
206
		else:
182
			# For prefix environments, default to the UID and GID of
207
			# The config class has equivalent code, but we also need to
183
			# the top-level EROOT directory. The config class has
208
			# do it here if _disable_legacy_globals() has been called.
184
			# equivalent code, but we also need to do it here if
185
			# _disable_legacy_globals() has been called.
186
			eroot = os.path.join(os.environ.get('ROOT', os.sep),
209
			eroot = os.path.join(os.environ.get('ROOT', os.sep),
187
				portage.const.EPREFIX.lstrip(os.sep))
210
				portage.const.EPREFIX.lstrip(os.sep))
188
			try:
211
			try:
Lines 190-209 def _get_global(k): Link Here
190
			except OSError:
213
			except OSError:
191
				pass
214
				pass
192
			else:
215
			else:
193
				if k == '_portage_grpname':
216
				if _unprivileged_mode(eroot, eroot_st):
194
					try:
217
					if k == '_portage_grpname':
195
						grp_struct = grp.getgrgid(eroot_st.st_gid)
218
						try:
196
					except KeyError:
219
							grp_struct = grp.getgrgid(eroot_st.st_gid)
197
						pass
220
						except KeyError:
221
							pass
222
						else:
223
							v = grp_struct.gr_name
198
					else:
224
					else:
199
						v = grp_struct.gr_name
225
						try:
200
				else:
226
							pwd_struct = pwd.getpwuid(eroot_st.st_uid)
201
					try:
227
						except KeyError:
202
						pwd_struct = pwd.getpwuid(eroot_st.st_uid)
228
							pass
203
					except KeyError:
229
						else:
204
						pass
230
							v = pwd_struct.pw_name
205
					else:
206
						v = pwd_struct.pw_name
207
231
208
		if v is None:
232
		if v is None:
209
			v = 'portage'
233
			v = 'portage'
Lines 254-256 def _init(settings): Link Here
254
			v = portage._native_string(v)
278
			v = portage._native_string(v)
255
		globals()['_portage_username'] = v
279
		globals()['_portage_username'] = v
256
		_initialized_globals.add('_portage_username')
280
		_initialized_globals.add('_portage_username')
281
282
	if 'secpass' not in _initialized_globals:
283
		v = 0
284
		if uid == 0:
285
			v = 2
286
		elif "unprivileged" in settings.features:
287
			v = 2
288
		elif portage_gid in os.getgroups():
289
			v = 1
290
		globals()['secpass'] = v
291
		_initialized_globals.add('secpass')
(-)a/pym/portage/package/ebuild/config.py (-8 / +13 lines)
Lines 834-847 class config(object): Link Here
834
				"PORTAGE_INST_UID": "0",
834
				"PORTAGE_INST_UID": "0",
835
			}
835
			}
836
836
837
			if eprefix:
837
			unprivileged = False
838
				# For prefix environments, default to the UID and GID of
838
			try:
839
				# the top-level EROOT directory.
839
				eroot_st = os.stat(eroot)
840
				try:
840
			except OSError:
841
					eroot_st = os.stat(eroot)
841
				pass
842
				except OSError:
842
			else:
843
					pass
843
844
				else:
844
				if portage.data._unprivileged_mode(eroot, eroot_st):
845
					unprivileged = True
846
845
					default_inst_ids["PORTAGE_INST_GID"] = str(eroot_st.st_gid)
847
					default_inst_ids["PORTAGE_INST_GID"] = str(eroot_st.st_gid)
846
					default_inst_ids["PORTAGE_INST_UID"] = str(eroot_st.st_uid)
848
					default_inst_ids["PORTAGE_INST_UID"] = str(eroot_st.st_uid)
847
849
Lines 880-885 class config(object): Link Here
880
			# initialize self.features
882
			# initialize self.features
881
			self.regenerate()
883
			self.regenerate()
882
884
885
			if unprivileged:
886
				self.features.add('unprivileged')
887
883
			if bsd_chflags:
888
			if bsd_chflags:
884
				self.features.add('chflags')
889
				self.features.add('chflags')
885
890
(-)a/pym/portage/tests/emerge/test_simple.py (-2 / +1 lines)
Lines 351-357 pkg_preinst() { Link Here
351
				os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"]
351
				os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"]
352
352
353
		updates_dir = os.path.join(test_repo_location, "profiles", "updates")
353
		updates_dir = os.path.join(test_repo_location, "profiles", "updates")
354
		dirs = [cachedir, cachedir_pregen, distdir, fake_bin,
354
		dirs = [cachedir, cachedir_pregen, cross_prefix, distdir, fake_bin,
355
			portage_tmpdir, updates_dir,
355
			portage_tmpdir, updates_dir,
356
			user_config_dir, var_cache_edb]
356
			user_config_dir, var_cache_edb]
357
		etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
357
		etc_symlinks = ("dispatch-conf.conf", "etc-update.conf")
358
- 

Return to bug 433453