Class: AuditDaemonRules

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/auditd_rules.rb

Overview

Usage: describe audit_daemon_rules do

its("LIST_RULES") {should contain_match(/^exit,always arch=.* key=time-change syscall=adjtimex,settimeofday/) }
its("LIST_RULES") {should contain_match(/^exit,always arch=.* key=time-change syscall=stime,settimeofday,adjtimex/) }
its("LIST_RULES") {should contain_match(/^exit,always arch=.* key=time-change syscall=clock_settime/)}
its("LIST_RULES") {should contain_match(/^exit,always watch=\/etc\/localtime perm=wa key=time-change/)}

end

Instance Method Summary collapse

Constructor Details

#initializeAuditDaemonRules

Returns a new instance of AuditDaemonRules.



18
19
20
21
22
23
24
25
# File 'lib/resources/auditd_rules.rb', line 18

def initialize
  @content = inspec.command('/sbin/auditctl -l').stdout.chomp

  @opts = {
    assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
    multiple_values: true,
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



31
32
33
# File 'lib/resources/auditd_rules.rb', line 31

def method_missing(name)
  params[name.to_s]
end

Instance Method Details

#paramsObject



27
28
29
# File 'lib/resources/auditd_rules.rb', line 27

def params
  @params ||= SimpleConfig.new(@content, @opts).params
end

#status(name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/resources/auditd_rules.rb', line 35

def status(name)
  @status_opts = {
    assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
    multiple_values: false,
  }
  @status_content ||= inspec.command('/sbin/auditctl -s').stdout.chomp
  @status_params = SimpleConfig.new(@status_content, @status_opts).params

  status = @status_params['AUDIT_STATUS']
  return nil if status.nil?

  items = Hash[status.scan(/([^=]+)=(\w*)\s*/)]
  items[name]
end

#to_sObject



50
51
52
# File 'lib/resources/auditd_rules.rb', line 50

def to_s
  'Audit Daemon Rules'
end