Sha256: 9e26c283879d95bdd0151db6a187a7d2e7fa53aedca0ec3f975ea6780421297e

Contents?: true

Size: 1.24 KB

Versions: 391

Compression:

Stored size: 1.24 KB

Contents

Puppet::Type.type(:selboolean).provide(:getsetsebool) do
  desc "Manage SELinux booleans using the getsebool and setsebool binaries."

  commands :getsebool => "/usr/sbin/getsebool"
  commands :setsebool => "/usr/sbin/setsebool"

  def value
    self.debug "Retrieving value of selboolean #{@resource[:name]}"

    status = getsebool(@resource[:name])

    if status =~ / off$/
      return :off
    elsif status =~ / on$/ then
      return :on
    else
      status.chomp!
      raise Puppet::Error, "Invalid response '#{status}' returned from getsebool"
    end
  end

  def value=(new)
    persist = ""
    if @resource[:persistent] == :true
      self.debug "Enabling persistence"
      persist = "-P"
    end
    execoutput("#{command(:setsebool)} #{persist} #{@resource[:name]} #{new}")
    :file_changed
  end

  # Required workaround, since SELinux policy prevents setsebool
  # from writing to any files, even tmp, preventing the standard
  # 'setsebool("...")' construct from working.

  def execoutput (cmd)
    output = ''
    begin
      execpipe(cmd) do |out|
        output = out.readlines.join('').chomp!
      end
    rescue Puppet::ExecutionFailure
      raise Puppet::ExecutionFailure, output.split("\n")[0], $!.backtrace
    end
    output
  end
end

Version data entries

391 entries across 391 versions & 3 rubygems

Version Path
puppet-5.5.22 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.22-x86-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.22-x64-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.22-universal-darwin lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.21 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.21-x86-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.21-x64-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.21-universal-darwin lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.20 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.20-x86-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.20-x64-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.20-universal-darwin lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.19 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.19-x86-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.19-x64-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.19-universal-darwin lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.18 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.18-x86-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.18-x64-mingw32 lib/puppet/provider/selboolean/getsetsebool.rb
puppet-5.5.18-universal-darwin lib/puppet/provider/selboolean/getsetsebool.rb