diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-17 23:11:14 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-17 23:11:14 +0000 |
| commit | f842cef3eddc375875447dc74158ee9c5317bdf6 (patch) | |
| tree | d8e2f46cafe96a6f97b8c976752bf2c3e0ed3f0b /lib | |
| parent | 46252b5bb858a1f2b87cc8646f3a59f935c58061 (diff) | |
| download | puppet-f842cef3eddc375875447dc74158ee9c5317bdf6.tar.gz puppet-f842cef3eddc375875447dc74158ee9c5317bdf6.tar.xz puppet-f842cef3eddc375875447dc74158ee9c5317bdf6.zip | |
Fixing #643 -- replacing the get_posix_field method with a more degenerate version that works even on broken systems
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2598 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/puppet/util/posix.rb | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/lib/puppet/util/posix.rb b/lib/puppet/util/posix.rb index 06df632a9..d7e3bb8b2 100755 --- a/lib/puppet/util/posix.rb +++ b/lib/puppet/util/posix.rb @@ -1,8 +1,10 @@ # Utility methods for interacting with POSIX objects; mostly user and group module Puppet::Util::POSIX + # Retrieve a field from a POSIX Etc object. The id can be either an integer - # or a name. This only works for users and groups. - def get_posix_field(space, field, id) + # or a name. This only works for users and groups. It's also broken on + # some platforms, unfortunately. + def old_get_posix_field(space, field, id) unless id raise ArgumentError, "Did not get id" end @@ -27,8 +29,35 @@ module Puppet::Util::POSIX return nil end end + + # A degenerate method of retrieving name/id mappings. The job of this method is + # to find a specific entry and then return a given field from that entry. + def get_posix_field(type, field, id) + idmethod = idfield(type) + integer = false + if id =~ /^\d+$/ + id = Integer(id) + end + if id.is_a?(Integer) + integer = true + if id > 1000000 + Puppet.err "Tried to get %s field for silly id %s" % [field, id] + return nil + end + end + + Etc.send(type) do |object| + if integer and object.send(idmethod) == id + return object.send(field) + elsif object.name == id + return object.send(field) + end + end + return nil + end # Look in memory for an already-managed type and use its info if available. + # Currently unused. def get_provider_value(type, field, id) unless typeklass = Puppet::Type.type(type) raise ArgumentError, "Invalid type %s" % type @@ -70,7 +99,7 @@ module Puppet::Util::POSIX def idfield(space) case Puppet::Util.symbolize(space) when :gr, :group: return :gid - when :pw, :user: return :uid + when :pw, :user, :passwd: return :uid else raise ArgumentError.new("Can only handle users and groups") end @@ -78,12 +107,12 @@ module Puppet::Util::POSIX # Get the GID of a given group, provided either a GID or a name def gid(group) - get_provider_value(:group, :gid, group) or get_posix_field(:gr, :gid, group) + get_posix_field(:group, :gid, group) end # Get the UID of a given user, whether a UID or name is provided def uid(user) - get_provider_value(:user, :uid, user) or get_posix_field(:pw, :uid, user) + get_posix_field(:passwd, :uid, user) end end |
