Skip to content

Commit

Permalink
(PUP-7126) Replace matchpathcon_fini with selinux_close
Browse files Browse the repository at this point in the history
This commit replaces mathpathcon_fini with selinux_close when closing
the SELinux handle since resources are released back to the system when
the handle is closed with selabel_close, so mathpathcon_fini is no
longer necessary.

Co-authored-by: William Bradford Clark <wclark@redhat.com>
  • Loading branch information
AriaXLi and wbclark committed May 21, 2024
1 parent e3b3336 commit 65f1112
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/puppet/provider/file/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
require 'etc'
require_relative '../../../puppet/util/selinux'

def self.post_resource_eval
Selinux.matchpathcon_fini if Puppet::Util::SELinux.selinux_support?
class << self

# @return [non-NULL handle value] A handle for selinux
Expand All @@ -27,6 +25,9 @@ def pre_resource_eval
end
end

def post_resource_eval
Selinux.selinux_close(@selinux_handle) if @selinux_handle
end
end

def uid2name(id)
Expand Down
8 changes: 5 additions & 3 deletions spec/unit/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,14 +770,16 @@ def post_resource_eval
transaction.evaluate
end

it "should call Selinux.matchpathcon_fini in case Selinux is enabled ", :if => Puppet.features.posix? do
selinux = double('selinux', is_selinux_enabled: true, matchpathcon_fini: nil)
it "should call Selinux.selinux_close in case Selinux is enabled ", :if => Puppet.features.posix? do
selinux = double('selinux', is_selinux_enabled: true, selinux_close: nil)
stub_const('Selinux', selinux)

resource = Puppet::Type.type(:file).new(:path => make_absolute("/tmp/foo"))
transaction = transaction_with_resource(resource)

expect(Selinux).to receive(:matchpathcon_fini)
handle = double('selinux_handle')
allow(selinux).to receive(:selabel_open).and_return(handle)
expect(Selinux).to receive(:selinux_close).with(handle)
expect(Puppet::Util::SELinux).to receive(:selinux_support?).and_return(true)

transaction.evaluate
Expand Down

0 comments on commit 65f1112

Please sign in to comment.