From: Stephen Smalley <sds@tycho.nsa.gov>
To: rarob@travelinglightfarm.net
Cc: selinux@tycho.nsa.gov, Daniel J Walsh <dwalsh@redhat.com>,
Eric Paris <eparis@redhat.com>,
Steve Lawrence <slawrence@tresys.com>
Subject: Re: PythonSELinux binding problem
Date: Fri, 22 Jul 2011 09:44:53 -0400 [thread overview]
Message-ID: <1311342293.20800.15.camel@moss-pluto> (raw)
In-Reply-To: <847d1fe893f5d55fda3cae11fb1c66df.squirrel@box559.bluehost.com>
On Thu, 2011-07-21 at 17:33 -0400, rarob@travelinglightfarm.net wrote:
> Hi,
> I'm using the python selinux bindings to determine if SELinux is
> disable/permissive/enforcing. The following snippet of code works just
> fine on RH5 and F10 regardless of the SELinux mode, but fails with an
> error on F11/12/13 and RH6 if SELinux is disabled.
>
> $ python -c 'import selinux ; print selinux.security_getenforce()'
>
> Under RH5 and F10 I correctly get the -1/0/1 returns for
> disabled/permissive/enforcing, as specified in the man pages for
> 'security_getenforce'. Under F11/12/13 and RH6 for permissive and
> enforcing I get the correct return values, but if the system is in
> disabled mode instead an OSError is thrown for 'No such file or
> directory'. I haven't look at the source for the underlying
> security_getenforce() system call, but I suspect is is assuming that the
> /selinux pseudo filesystem is populated (as in permissive/enforcing mode),
> and is not handling the case where that pseudo filesystem is empty.
>
> For now I've got my python calls wrapped in try/except blocks treating any
> exception as SELinux in disabled mode.
>
> I wasn't sure where the best place to log this as a bug is, either for the
> libselinux-python package or libselinux itself.
I don't know why this would have ever worked, as security_getenforce()
has always returned -1 with errno ENOENT if there is no selinuxfs mount.
Maybe the older python bindings handled this error condition? The
correct test for enabled/disabled is selinux.is_selinux_enabled(), and
that should be checked prior to calling security_getenforce().
--
Stephen Smalley
National Security Agency
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
next prev parent reply other threads:[~2011-07-22 13:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-21 21:33 PythonSELinux binding problem rarob
2011-07-22 13:44 ` Stephen Smalley [this message]
2011-07-22 14:00 ` Eric Paris
2011-07-22 13:46 ` Daniel J Walsh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1311342293.20800.15.camel@moss-pluto \
--to=sds@tycho.nsa.gov \
--cc=dwalsh@redhat.com \
--cc=eparis@redhat.com \
--cc=rarob@travelinglightfarm.net \
--cc=selinux@tycho.nsa.gov \
--cc=slawrence@tresys.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.