Sha256: cef44c95aded4ad02071baa9c050702a63a015bc2bbf75c201392d5582bf8440

Contents?: true

Size: 1.08 KB

Versions: 28

Compression:

Stored size: 1.08 KB

Contents

require "etc"

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

  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].has_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

28 entries across 28 versions & 1 rubygems

Version Path
ohai-8.26.1 lib/ohai/plugins/passwd.rb
ohai-8.26.0 lib/ohai/plugins/passwd.rb
ohai-8.25.1 lib/ohai/plugins/passwd.rb
ohai-8.25.0 lib/ohai/plugins/passwd.rb
ohai-13.3.0 lib/ohai/plugins/passwd.rb
ohai-13.2.0 lib/ohai/plugins/passwd.rb
ohai-8.24.1 lib/ohai/plugins/passwd.rb
ohai-13.1.0 lib/ohai/plugins/passwd.rb
ohai-8.24.0 lib/ohai/plugins/passwd.rb
ohai-13.0.1 lib/ohai/plugins/passwd.rb
ohai-13.0.0 lib/ohai/plugins/passwd.rb
ohai-8.23.0 lib/ohai/plugins/passwd.rb
ohai-8.22.1 lib/ohai/plugins/passwd.rb
ohai-8.22.0 lib/ohai/plugins/passwd.rb
ohai-8.21.0 lib/ohai/plugins/passwd.rb
ohai-8.20.0 lib/ohai/plugins/passwd.rb
ohai-8.19.2 lib/ohai/plugins/passwd.rb
ohai-8.19.0 lib/ohai/plugins/passwd.rb
ohai-8.18.0 lib/ohai/plugins/passwd.rb
ohai-8.17.1 lib/ohai/plugins/passwd.rb