diff options
Diffstat (limited to 'lib/puppet/util')
-rw-r--r-- | lib/puppet/util/ldap/manager.rb | 2 | ||||
-rw-r--r-- | lib/puppet/util/log.rb | 36 | ||||
-rwxr-xr-x | lib/puppet/util/posix.rb | 81 |
3 files changed, 90 insertions, 29 deletions
diff --git a/lib/puppet/util/ldap/manager.rb b/lib/puppet/util/ldap/manager.rb index 9761fc753..8d444195e 100644 --- a/lib/puppet/util/ldap/manager.rb +++ b/lib/puppet/util/ldap/manager.rb @@ -80,7 +80,7 @@ class Puppet::Util::Ldap::Manager # Calculate the dn for a given resource. def dn(name) - ["#{rdn.to_s}=%s" % name, base].join(",") + ["%s=%s" % [rdn, name], base].join(",") end # Convert an ldap-style entry hash to a provider-style hash. diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 22f4f3233..8824a8b50 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -244,23 +244,31 @@ class Puppet::Util::Log newdesttype :console do - PINK = {:console => "[0;31m", :html => "FFA0A0"} - GREEN = {:console => "[0;32m", :html => "00CD00"} - YELLOW = {:console => "[0;33m", :html => "FFFF60"} - SLATE = {:console => "[0;34m", :html => "80A0FF"} - ORANGE = {:console => "[0;35m", :html => "FFA500"} - BLUE = {:console => "[0;36m", :html => "40FFFF"} - RESET = {:console => "[0m", :html => ""} + RED = {:console => "[0;31m", :html => "FFA0A0"} + GREEN = {:console => "[0;32m", :html => "00CD00"} + YELLOW = {:console => "[0;33m", :html => "FFFF60"} + BLUE = {:console => "[0;34m", :html => "80A0FF"} + PURPLE = {:console => "[0;35m", :html => "FFA500"} + CYAN = {:console => "[0;36m", :html => "40FFFF"} + WHITE = {:console => "[0;37m", :html => "FFFFFF"} + HRED = {:console => "[1;31m", :html => "FFA0A0"} + HGREEN = {:console => "[1;32m", :html => "00CD00"} + HYELLOW = {:console => "[1;33m", :html => "FFFF60"} + HBLUE = {:console => "[1;34m", :html => "80A0FF"} + HPURPLE = {:console => "[1;35m", :html => "FFA500"} + HCYAN = {:console => "[1;36m", :html => "40FFFF"} + HWHITE = {:console => "[1;37m", :html => "FFFFFF"} + RESET = {:console => "[0m", :html => ""} @@colormap = { - :debug => SLATE, + :debug => WHITE, :info => GREEN, - :notice => PINK, - :warning => ORANGE, - :err => YELLOW, - :alert => BLUE, - :emerg => RESET, - :crit => RESET + :notice => CYAN, + :warning => YELLOW, + :err => HPURPLE, + :alert => RED, + :emerg => HRED, + :crit => HRED } def colorize(level, str) diff --git a/lib/puppet/util/posix.rb b/lib/puppet/util/posix.rb index 8228734ef..aff797485 100755 --- a/lib/puppet/util/posix.rb +++ b/lib/puppet/util/posix.rb @@ -3,23 +3,22 @@ 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. It's also broken on - # some platforms, unfortunately. - def old_get_posix_field(space, field, id) + # some platforms, unfortunately, which is why we fall back to the other + # method search_posix_field in the gid and uid methods if a sanity check + # fails + def get_posix_field(space, field, id) unless id raise ArgumentError, "Did not get id" end - if id =~ /^\d+$/ - id = Integer(id) - end prefix = "get" + space.to_s if id.is_a?(Integer) if id > Puppet[:maximum_uid].to_i Puppet.err "Tried to get %s field for silly id %s" % [field, id] return nil end - method = (prefix + idfield(space).to_s).intern + method = methodbyid(space) else - method = (prefix + "nam").intern + method = methodbyname(space) end begin @@ -31,13 +30,11 @@ module Puppet::Util::POSIX 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) + # to retrieve all objects of a certain type, search for a specific entry + # and then return a given field from that entry. + def search_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 > Puppet[:maximum_uid].to_i @@ -73,14 +70,70 @@ module Puppet::Util::POSIX end end + # Determine what the method is to get users and groups by id + def methodbyid(space) + case Puppet::Util.symbolize(space) + when :gr, :group: return :getgrgid + when :pw, :user, :passwd: return :getpwuid + else + raise ArgumentError.new("Can only handle users and groups") + end + end + + # Determine what the method is to get users and groups by name + def methodbyname(space) + case Puppet::Util.symbolize(space) + when :gr, :group: return :getgrnam + when :pw, :user, :passwd: return :getpwnam + else + raise ArgumentError.new("Can only handle users and groups") + end + end + # Get the GID of a given group, provided either a GID or a name def gid(group) - get_posix_field(:group, :gid, group) + begin + group = Integer(group) + rescue ArgumentError + # pass + end + if group.is_a?(Integer) + name = get_posix_field(:group, :name, group) + gid = get_posix_field(:group, :gid, name) + check_value = gid + else + gid = get_posix_field(:group, :gid, group) + name = get_posix_field(:group, :name, gid) + check_value = name + end + if check_value != group + return search_posix_field(:group, :gid, group) + else + return gid + end end # Get the UID of a given user, whether a UID or name is provided def uid(user) - get_posix_field(:passwd, :uid, user) + begin + user = Integer(user) + rescue ArgumentError + # pass + end + if user.is_a?(Integer) + name = get_posix_field(:passwd, :name, user) + uid = get_posix_field(:passwd, :uid, name) + check_value = uid + else + uid = get_posix_field(:passwd, :uid, user) + name = get_posix_field(:passwd, :name, uid) + check_value = name + end + if check_value != user + return search_posix_field(:passwd, :uid, user) + else + return uid + end end end |