File: getsetsebool.rb

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (48 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
    debug "Retrieving value of selboolean #{@resource[:name]}"

    status = getsebool(@resource[:name])

    case status
    when %r{ off$}
      :off
    when %r{ on$}
      :on
    else
      status.chomp!
      raise Puppet::Error, "Invalid response '#{status}' returned from getsebool"
    end
  end

  def value=(new)
    persist = ''
    if @resource[:persistent] == :true
      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], $ERROR_INFO.backtrace
    end
    output
  end
end