Commit Graph

22 Commits

Author SHA1 Message Date
Panu Matilainen dd5c0446a3 Stop using deprecated security_context_t
In libselinux >= 3.1 these cause deprecation warnings on build.

security_context_t always was nothing but typedef to plain old "char *"
so just using that is entirely backwards compatible too.
2020-10-28 10:40:22 +02:00
Panu Matilainen 153c5c2198 Use common error logic regardless of setexecfilecon() availability
Refactor the custom exec context setting code to look like setexecfilecon()
in case the real one is not available to eliminate pesky behavioral
differences between the two cases.

This fixes a concrete bug of libselinux setexecfilecon() returning with
an error when security_getenforce() returns with -1 (such as a bare
chroot with no /sys mounts etc), causing us to spit out useless error
messages in that case ever since fixing the bogus if-logic in
commit ab601b882b.

Fixes: #1077
2020-02-19 14:26:15 +01:00
Panu Matilainen 4a71a3eccd Silence spurious error message from lsetfilecon() on -EOPNOTSUPP
We already filter out -EOPNOTSUPP and return OK, but the message was
getting logged before the filtering so we'd spit out spurious error
messages on filesystems that don't support SELinux (RhBug:1777502)
2019-12-13 13:49:03 +01:00
Panu Matilainen ab601b882b Fix suspicious condition in selinux plugin
Misplaced parenthesis introduced in commit 148e82833a.

Fixes #872
2019-10-07 14:40:41 +03:00
Panu Matilainen 8cbe8baf9c Log RPMLOG_ERR level messages on actual errors in selinux plugin, doh.
When there's an actual error, people will want to know without having
to rerun in verbose mode. Such as in RhBug:1641631 where configured
selinux policy differs from what is installed - the former message

    error: Plugin selinux: hook tsm_pre failed

...is not particularly helpful to anybody, whereas this actually provides
some clues now:

    error: selabel_open: (/etc/selinux/ponies/contexts/files/file_contexts) No such file or directory
    error: Plugin selinux: hook tsm_pre failed
2019-02-14 13:12:49 +02:00
Panu Matilainen 66e0c929b2 Fix testing for wrong variable in selinux plugin debug log
The strerror() case couldn't be reached as we were testing for the
wrong rc, spotted by covscan.
2018-10-10 12:00:38 +03:00
Davide Cavalca 007a405b98 selinux: use string_to_security_class() instead of class ID
SELinux recommends to use string_to_security_class() instead of referencing
class IDs directly. This also fixes a build issue for systems that don't
include flask.h by default.

References:
https://selinuxproject.org/page/NB_Imp_SELinux-aware_Apps#Implementing_SELinux-aware_Applications_2
76913d8adb
2017-02-08 11:25:25 +02:00
Panu Matilainen b1e7ce8153 Remove leftover include of <selinux/flask.h>
Besides unused, this has started spitting warnings in recent selinux versions:
In file included from selinux.c:5:0:
/usr/include/selinux/flask.h:5:2: warning: #warning "Please remove any #include's of this header in your source code." [-Wcpp]
 #warning "Please remove any #include's of this header in your source code."
  ^~~~~~~
2016-10-03 13:57:56 +03:00
Lubos Kardos 468726ece5 Display message when a hook function of some plugin fails (rhbz:1262424)
For a pre hook function display an error message and for a post hook
function display just a warning message. This corresponds with
the way how error/warning messages are displayed for scriptlets.

Also add a debug message into selinux plugin.
2016-03-07 13:26:35 +01:00
Florian Festi 0d214a17e4 Permit scriptlet exec context setting to fail in non-enforcing modes
for new code path, too.

See also 9c082fb868
2015-10-12 12:47:45 +02:00
Guillem Jover 148e82833a Use setexecfilecon() from libselinux instead of ad-hoc code
This function was factored out from rpm_execcon() upstream to make it
easier to use by its users, by making it not call execve() directly. It
is now also used by dpkg since 1.17.11.

Preserve the ad-hoc code for now so that it can be compiled against old
libselinux versions.
2015-02-16 11:24:10 +01:00
Panu Matilainen 9383d258be And now that we finally can, pass rpmfi to plugin hooks when available
- Unowned directories obviously do not exist in rpmfi, so plugins
  still need to be passed path and mode separately, but for all
  the rest rpmfi is there and contains valuable additional information
  that's been unavailable to plugins until now
2014-03-05 14:30:59 +02:00
Panu Matilainen 9c082fb868 Permit scriptlet exec context setting to fail in non-enforcing modes
- This is what rpm_execcon() in libselinux always did, and trying to
  be more strict causes things to blow up on install to an empty
  chroot where /proc and /sys/fs/selinux are not mounted.
2013-04-05 10:54:24 +03:00
Panu Matilainen 6fd18f15b3 Rename all hook functions for saner debugging
- Now that the hook functions in plugins no longer need to be uniformly
  named, rename them to more "natural" pluginname_hookname style so
  __func__ (and gdb etc) give meaningful, distinct values for them.
  No functional changes unless I typoed something.
2013-04-05 09:10:03 +03:00
Panu Matilainen f869670e78 Pass the handle to plugin itself to all plugin hooks
- Change all plugin hooks to take plugin itself as the first argument,
  adjust our existing plugins
- Further steps towards making plugins "instances" instead of
  just semi-global blobs
2013-04-03 12:04:05 +03:00
Panu Matilainen 91cefc3c3f Separate the external plugin API to its own header
- rpmplugins.[ch] implements the rpm internal plugin management
  infrastructure, which is no business of anybody else. Mark the
  symbols internal while at it.
- rpmplugin.h describes the API for the actual plugins, this is
  to be made public once the API is considered stable enough (which
  it certainly is not yet ;)
- Adjust our plugins to include the right header
2013-04-03 11:42:04 +03:00
Panu Matilainen 08b7daccee Remove unused init + cleanup hooks in selinux and systemd inhibit plugins
- We should perhaps require an init hook instead of foo_hooks struct
  but while things are this way... these are useless.
2013-04-03 10:57:39 +03:00
Panu Matilainen aa582a56ed Restore former behavior of ignoring selinux label "not found" errors
- The in-rpm selinux code always ignored errors from selabel_lookup_raw(),
  but the plugin version does. Apparently it can occasionally return
  ENOENT as in "no context for this thingie here" for something which
  causes the plugin version to return an error (I'm seeing this on
  /var/lib/nfs/rpc_pipefs from nfs-utils)
- It's not rpm's business to say everything needs to have a label,
  although this does seem a bit peculiar: for an arbitrary unknown
  directory selabel_lookup() seems to normally return a "default"
  context. Why that is not happening here I haven't got the slightest
  idea, but then restorecon isn't complaining on this, why should we?
2013-04-02 11:33:25 +03:00
Panu Matilainen 504bc846f1 Further adjust our plugins wrt the new hook system
- Make the hook functions static now that its possible
- Directly include what the plugins need, dont include plugin.h
- Eliminate now unnecessary plugin.h
2013-03-31 13:30:59 +03:00
Panu Matilainen 2b840edcf5 Revamp the way plugin hooks discovered and called, adjust plugins
- Add a struct containing all hook function pointers to plugins,
  let plugins populate it by themselves and call the hooks by the
  hook struct, avoiding repeated dlsym() discovery on each call etc.
- Eliminate now unnecessary PLUGINHOOK_FOO typedefs, defines and the
  "supported hooks" bitfield: supported hooks are whatever a plugin
  declares in the struct. This also means the number of possible
  plugin hooks is not limited by number of bits in an integer.
- This means the only symbol plugins need to export is <name>_hooks,
  the actual functions can be static. This is not the case yet but
  to avoid changing everything at once... this is already a fairly
  big commit.
- This also fixes the nasty issue where in presence of multiple
  (non-collection) plugins, supported hooks would not get called if
  another plugin didn't support that hook because of
  RPMPLUGINS_SET_HOOK_FUNC() using "return" on several cases,
  which doesn't go very well with loops.
2013-03-31 13:24:00 +03:00
Panu Matilainen 08912b1b0c Fix segfault in selinux plugin when labeling is disabled 2013-03-27 05:52:20 +02:00
Panu Matilainen 301daabe78 First cut at selinux plugin to replace the in-core selinux support
- This obviously clashes with the built-in selinux support, but
  we need to have something in place before the built-in version
  is axed so...
2013-03-21 13:35:58 +02:00