Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 430488 - sys-apps/portage selinux code still requires python-2
Summary: sys-apps/portage selinux code still requires python-2
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: SELinux (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Sven Vermeulen (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 741194
  Show dependency tree
 
Reported: 2012-08-08 19:35 UTC by Sven Vermeulen (RETIRED)
Modified: 2020-09-08 20:36 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
portage.patch (portage.patch,5.93 KB, patch)
2013-01-14 07:23 UTC, Arfrever Frehtes Taifersar Arahesis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Vermeulen (RETIRED) gentoo-dev 2012-08-08 19:35:13 UTC
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
Comment 1 Arfrever Frehtes Taifersar Arahesis 2013-01-14 07:23:10 UTC
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.
Comment 2 Zac Medico gentoo-dev 2013-01-14 11:42:15 UTC
(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).
Comment 3 Zac Medico gentoo-dev 2013-01-14 20:00:27 UTC
(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.
Comment 4 Zac Medico gentoo-dev 2013-01-15 12:30:25 UTC
(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.
Comment 5 Sven Vermeulen (RETIRED) gentoo-dev 2013-03-17 10:36:35 UTC
Thanks, i can confirm it is working well. I've removed the python2 use force in the SELinux profiles.