When trying to use Portage with python3, it still fails on the SELinux code within: """ ~# emerge cowsay ... File "/usr/lib64/portage/pym/portage/_selinux.py", line 104, in wrapper_func con = settype(selinux_type) File "/usr/lib64/portage/pym/portage/_selinux.py", line 75, in settype return ":".join(ret) TypeError: sequence item 2: expected str instance, bytes found """ When fixing that one (with str(ctx) instead of ctx): """ File "/usr/lib64/portage/pym/portage/_selinux.py", line 105, in wrapper_func setexec(con) File "/usr/lib64/portage/pym/portage/_selinux.py", line 79, in setexec if selinux.setexeccon(ctx) < 0: TypeError: in method 'setexeccon', argument 1 of type 'security_context_t const' """ Can't immediately find a proper way to handle this. From some online resources (like [1]) it looks like I need to generate the proper type based on the input (using gen_context) but that function isn't available in Gentoo Portage' SELinux integration code (yet). In the mean time, I'm remasking python3 USE flag for Portage in the SELinux profiles. [1] http://www.spinics.net/lists/selinux/msg07837.html Reproducible: Always
Created attachment 335564 [details, diff] portage.patch Source code generated by SWIG seems to imply that these functions require bytes in Python 2 and unicode in Python 3. Please test this patch.
(In reply to comment #1) > Created attachment 335564 [details, diff] [details, diff] > portage.patch > > Source code generated by SWIG seems to imply that these functions require > bytes in Python 2 and unicode in Python 3. Please test this patch. I've tested it with libselinux-2.1.12-r2 and python-3.2.3, and it seems to work fine, so I've committed the patch: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=6137290b2bb8353db0df1a7664e435ced37bacfd I'm not sure how the libselinux functions will handle encoding/decoding of UTF-8 file names, and whether or not it's locale dependent. For these reasons, it would be nice if libselinux functions could handle file names encoded as raw bytes (like python's os.* functions do).
(In reply to comment #2) > I've tested it with libselinux-2.1.12-r2 and python-3.2.3, and it seems to > work fine, so I've committed the patch: > > http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit; > h=6137290b2bb8353db0df1a7664e435ced37bacfd Released in portage-2.1.11.41 and 2.2.0_alpha152.
(In reply to comment #2) > I'm not sure how the libselinux functions will handle encoding/decoding of > UTF-8 file names, and whether or not it's locale dependent. To follow up on this, Arfrever tells me SWIG-generated code uses the following function to encode unicode strings as bytes: http://docs.python.org/3/c-api/unicode.html#PyUnicode_AsUTF8String This is good news, because it's consistent with portage, which uses UTF-8 encoding for file names of all installed files (regardless of locale). > For these > reasons, it would be nice if libselinux functions could handle file names > encoded as raw bytes (like python's os.* functions do). While this might be a nice enhancement, it won't really matter for portage, because of the portage's consistency with PyUnicode_AsUTF8String. So, it seems that we can consider this bug fixed with portage-2.1.11.41 and 2.2.0_alpha152.
Thanks, i can confirm it is working well. I've removed the python2 use force in the SELinux profiles.