class Ardecy::Harden::Mountpoint::MountInc

Public Class Methods

new(args) click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 18
def initialize(args)
  @res = 'FAIL'
  @args = args
  @tab = 2
end

Public Instance Methods

add_group() click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 32
def add_group
  return unless @args[:fix] && @group

  has_group = group_search
  unless has_group
    if File.exists? '/usr/sbin/groupadd'
      puts " => Group #{@group} added." if system("/usr/sbin/groupadd #{@group}")
    elsif File.exists? '/usr/bin/groupadd'
      puts " => Group #{@group} added." if system("/usr/bin/groupadd #{@group}")
    else
      puts '[-] Can\'t find command groupadd'
    end
  end
end
build_args() click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 71
def build_args
  return unless @args[:fix]
  return if @res =~ /OK/

  v = @val.split ' '
  @ensure.each do |e|
    o = e.split('=')
    v[3] += ",#{e}" unless v[3] =~ /#{o[0]}=[a-z0-9]+/
  end
  @new = v.join(' ')
end
edit_fstab() click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 108
def edit_fstab
  sed(/^#{@name}/, @new, '/etc/fstab')
end
fix() click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 83
def fix
  return unless @args[:fix]
  return if @res =~ /OK/

  if mount_match('/etc/fstab')
    edit_fstab
  else
    File.write('/etc/fstab', "\n#{@new}\n", mode: 'a')
  end

  puts "old -> " + @val
  puts "new -> " + @new
  puts
end
mount_match(file) click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 98
def mount_match(file)
  File.readlines(file).each do |l|
    if l =~ /^#{@name}/
      @val = l
      return true
    end
  end
  false
end
scan() click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 57
def scan
  return unless mount_match('/proc/mounts')

  print "  - Checking #{@name} contain " + @ensure.join(',') if @args[:audit]
  res_a = []
  @ensure.each do |v|
    o = v.split('=')
    res_a << true if @val =~ /#{o[0]}=[a-z0-9]+/
  end
  @res = 'OK' if res_a.length == @ensure.length

  @tab ? result(@res, @tab) : result(@res) if @args[:audit]
end
systemd_case() click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 112
def systemd_case
end
x() click to toggle source
# File lib/ardecy/harden/mountpoint.rb, line 24
def x
  scan
  add_group
  build_args
  fix
  systemd_case
end