diff options
Diffstat (limited to 'lib/ohai/plugins/passwd.rb')
-rw-r--r-- | lib/ohai/plugins/passwd.rb | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/lib/ohai/plugins/passwd.rb b/lib/ohai/plugins/passwd.rb index ed63d268..397b15c6 100644 --- a/lib/ohai/plugins/passwd.rb +++ b/lib/ohai/plugins/passwd.rb @@ -1,32 +1,37 @@ -provides 'etc', 'current_user' require 'etc' -def fix_encoding(str) - str.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding) - str -end +Ohai.plugin(:Passwd) do + provides 'etc', 'current_user' -unless etc - etc Mash.new + def fix_encoding(str) + str.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding) + str + end - etc[:passwd] = Mash.new - etc[:group] = Mash.new + collect_data do + unless etc + etc 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)} - etc[:passwd][fix_encoding(entry.name)] = user_passwd_entry - end + etc[:passwd] = Mash.new + etc[:group] = Mash.new - Etc.group do |entry| - group_entry = Mash.new(:gid => entry.gid, - :members => entry.mem.map {|u| fix_encoding(u)}) + 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)} + etc[:passwd][fix_encoding(entry.name)] = user_passwd_entry + end - etc[:group][fix_encoding(entry.name)] = group_entry - end -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.getlogin) + unless current_user + current_user fix_encoding(Etc.getlogin) + end + end end |