public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] _selinux.setexec: improve failure message (525726)
@ 2014-11-11 21:52 Zac Medico
  2014-11-11 22:18 ` Brian Dolbec
  0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2014-11-11 21:52 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Sven Vermeulen

From: Sven Vermeulen <swift@gentoo.org>

This converts "OSError: [Errno 22] Invalid argument" into a more
meaningful error message that is to designed to guide users in the
right direction. Also, add an import that was missing for the "sys"
module, since is referenced in the error paths of many functions in
this module.

X-Gentoo-Bug: 525726
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=525726
---
 pym/portage/_selinux.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/pym/portage/_selinux.py b/pym/portage/_selinux.py
index 2a7194c..c5e8b2c 100644
--- a/pym/portage/_selinux.py
+++ b/pym/portage/_selinux.py
@@ -5,6 +5,7 @@
 # the whole _selinux module itself will be wrapped.
 import os
 import shutil
+import sys
 
 import portage
 from portage import _encodings
@@ -77,7 +78,18 @@ def settype(newtype):
 
 def setexec(ctx="\n"):
 	ctx = _native_string(ctx, encoding=_encodings['content'], errors='strict')
-	if selinux.setexeccon(ctx) < 0:
+	rc = 0
+	try:
+		rc = selinux.setexeccon(ctx)
+	except OSError:
+		msg = _("Failed to set new SELinux execution context. " + \
+			"Is your current SELinux context allowed to run Portage?")
+		if selinux.security_getenforce() == 1:
+			raise OSError(msg)
+		else:
+			portage.writemsg("!!! %s\n" % msg, noiselevel=-1)
+
+	if rc < 0:
 		if sys.hexversion < 0x3000000:
 			ctx = _unicode_decode(ctx, encoding=_encodings['content'], errors='replace')
 		if selinux.security_getenforce() == 1:
-- 
2.0.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] _selinux.setexec: improve failure message (525726)
  2014-11-11 21:52 [gentoo-portage-dev] [PATCH] _selinux.setexec: improve failure message (525726) Zac Medico
@ 2014-11-11 22:18 ` Brian Dolbec
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2014-11-11 22:18 UTC (permalink / raw
  To: gentoo-portage-dev

On Tue, 11 Nov 2014 13:52:04 -0800
Zac Medico <zmedico@gentoo.org> wrote:

> From: Sven Vermeulen <swift@gentoo.org>
> 
> This converts "OSError: [Errno 22] Invalid argument" into a more
> meaningful error message that is to designed to guide users in the
> right direction. Also, add an import that was missing for the "sys"
> module, since is referenced in the error paths of many functions in
> this module.
> 
> X-Gentoo-Bug: 525726
> X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=525726
> ---
>  pym/portage/_selinux.py | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 

LGTM, merge your fixed patch.

Thank you Swen and Zac

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-11 22:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-11 21:52 [gentoo-portage-dev] [PATCH] _selinux.setexec: improve failure message (525726) Zac Medico
2014-11-11 22:18 ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox