Sha256: 1ce5a997e1270e6f54e91506427dc381cfe76093a390cd24e50d0715ad48b8a2

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

Ohai.plugin(:Passwd) do
  require "etc"
  provides "etc", "current_user"
  optional true

  def fix_encoding(str)
    str.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding)
    str
  end

  collect_data do
    unless etc
      etc Mash.new

      etc[:passwd] = Mash.new
      etc[:group] = Mash.new

      Etc.passwd do |entry|
        user_passwd_entry = Mash.new(dir: entry.dir, gid: entry.gid, uid: entry.uid, shell: entry.shell, gecos: entry.gecos)
        user_passwd_entry.each_value { |v| fix_encoding(v) }
        entry_name = fix_encoding(entry.name)
        etc[:passwd][entry_name] = user_passwd_entry unless etc[:passwd].key?(entry_name)
      end

      Etc.group do |entry|
        group_entry = Mash.new(gid: entry.gid,
                               members: entry.mem.map { |u| fix_encoding(u) })

        etc[:group][fix_encoding(entry.name)] = group_entry
      end
    end

    unless current_user
      current_user fix_encoding(Etc.getpwuid(Process.euid).name)
    end
  end

  collect_data(:windows) do
    # Etc returns nil on Windows
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ohai-14.15.0 lib/ohai/plugins/passwd.rb
ohai-14.14.0 lib/ohai/plugins/passwd.rb
ohai-14.8.12 lib/ohai/plugins/passwd.rb
ohai-15.0.35 lib/ohai/plugins/passwd.rb
ohai-14.8.11 lib/ohai/plugins/passwd.rb
ohai-14.8.10 lib/ohai/plugins/passwd.rb
ohai-14.6.2 lib/ohai/plugins/passwd.rb
ohai-14.5.4 lib/ohai/plugins/passwd.rb
ohai-14.5.0 lib/ohai/plugins/passwd.rb
ohai-14.4.2 lib/ohai/plugins/passwd.rb
ohai-14.4.1 lib/ohai/plugins/passwd.rb
ohai-14.4.0 lib/ohai/plugins/passwd.rb
ohai-14.3.0 lib/ohai/plugins/passwd.rb