summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
committerLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
commit740fd6b301af89ab3aad89bca183ad1fcdc24ac4 (patch)
treef34617a229509c373d28d67abb453e7ae2136c39 /lib/puppet/util
parent8971d8beae2c409f9052f27c3f80ad3bdfff4de2 (diff)
parent4a06379f8770c164e42bcc410d874076c6e95f24 (diff)
downloadpuppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.gz
puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.xz
puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.zip
Merge branch '0.25.x'
Conflicts: lib/puppet/agent.rb lib/puppet/application/puppetd.rb lib/puppet/parser/ast/leaf.rb lib/puppet/util/rdoc/parser.rb
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/log.rb4
-rw-r--r--lib/puppet/util/methodhelper.rb7
-rw-r--r--lib/puppet/util/monkey_patches.rb8
-rw-r--r--lib/puppet/util/rdoc/parser.rb17
-rw-r--r--lib/puppet/util/selinux.rb23
-rw-r--r--lib/puppet/util/subclass_loader.rb2
-rw-r--r--lib/puppet/util/suidmanager.rb12
-rw-r--r--lib/puppet/util/tagging.rb26
8 files changed, 78 insertions, 21 deletions
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index 25c4677fb..4cdad700c 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -282,9 +282,9 @@ class Puppet::Util::Log
def colorize(level, str)
case Puppet[:color]
- when false; str
- when true, :ansi, "ansi"; console_color(level, str)
+ when true, :ansi, "ansi", :yes, "yes"; console_color(level, str)
when :html, "html"; html_color(level, str)
+ else str
end
end
diff --git a/lib/puppet/util/methodhelper.rb b/lib/puppet/util/methodhelper.rb
index 32fca1877..ecc9d537f 100644
--- a/lib/puppet/util/methodhelper.rb
+++ b/lib/puppet/util/methodhelper.rb
@@ -12,11 +12,10 @@ module Puppet::Util::MethodHelper
def set_options(options)
options.each do |param,value|
method = param.to_s + "="
- begin
+ if respond_to? method
self.send(method, value)
- rescue NoMethodError
- raise ArgumentError, "Invalid parameter %s to object class %s" %
- [param,self.class.to_s]
+ else
+ raise ArgumentError, "Invalid parameter #{param} to object class #{self.class}"
end
end
end
diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb
index e69de29bb..6e438bc73 100644
--- a/lib/puppet/util/monkey_patches.rb
+++ b/lib/puppet/util/monkey_patches.rb
@@ -0,0 +1,8 @@
+module RDoc
+ def self.caller(skip=nil)
+ in_gem_wrapper = false
+ Kernel.caller.reject { |call|
+ in_gem_wrapper ||= call =~ /#{Regexp.escape $0}:\d+:in `load'/
+ }
+ end
+end
diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index 3f04fbf52..4d0ac484f 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -200,9 +200,20 @@ class Parser
if stmt.is_a?(Puppet::Parser::AST::Resource) and !stmt.type.nil?
begin
- ref = resource_stmt_to_ref(stmt)
- Puppet.debug "rdoc: found resource: %s[%s]" % [ref.type, ref.title]
- container.add_resource(ref)
+ type = stmt.type.split("::").collect { |s| s.capitalize }.join("::")
+ title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s
+ Puppet.debug "rdoc: found resource: %s[%s]" % [type,title]
+
+ param = []
+ stmt.params.children.each do |p|
+ res = {}
+ res["name"] = p.param
+ res["value"] = "#{p.value.to_s}" unless p.value.nil?
+
+ param << res
+ end
+
+ container.add_resource(PuppetResource.new(type, title, stmt.doc, param))
rescue => detail
raise Puppet::ParseError, "impossible to parse resource in #{stmt.file} at line #{stmt.line}: #{detail}"
end
diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb
index bdf44152b..3eff03996 100644
--- a/lib/puppet/util/selinux.rb
+++ b/lib/puppet/util/selinux.rb
@@ -13,6 +13,8 @@ rescue LoadError
# Nothing
end
+require 'pathname'
+
module Puppet::Util::SELinux
def selinux_support?
@@ -91,7 +93,7 @@ module Puppet::Util::SELinux
# I believe that the OS should always provide at least a fall-through context
# though on any well-running system.
def set_selinux_context(file, value, component = false)
- unless selinux_support?
+ unless selinux_support? && selinux_label_support?(file)
return nil
end
@@ -185,9 +187,19 @@ module Puppet::Util::SELinux
return mntpoint
end
+ def realpath(path)
+ path, rest = Pathname.new(path), []
+ path, rest = path.dirname, [path.basename] + rest while ! path.exist?
+ File.join( path.realpath, *rest )
+ end
+
+ def parent_directory(path)
+ Pathname.new(path).dirname.to_s
+ end
+
# Internal helper function to return which type of filesystem a
# given file path resides on
- def find_fs(file)
+ def find_fs(path)
unless mnts = read_mounts()
return nil
end
@@ -198,13 +210,12 @@ module Puppet::Util::SELinux
# Just in case: return something if you're down to "/" or ""
# Remove the last slash and everything after it,
# and repeat with that as the file for the next loop through.
- ary = file.split('/')
- while not ary.empty? do
- path = ary.join('/')
+ path = realpath(path)
+ while not path.empty? do
if mnts.has_key?(path)
return mnts[path]
end
- ary.pop
+ path = parent_directory(path)
end
return mnts['/']
end
diff --git a/lib/puppet/util/subclass_loader.rb b/lib/puppet/util/subclass_loader.rb
index 8776e855c..b71ec7293 100644
--- a/lib/puppet/util/subclass_loader.rb
+++ b/lib/puppet/util/subclass_loader.rb
@@ -72,7 +72,7 @@ module Puppet::Util::SubclassLoader
end
# Retrieve or calculate a name.
- def name
+ def name(dummy_argument=:work_arround_for_ruby_GC_bug)
unless defined? @name
@name = self.to_s.sub(/.+::/, '').intern
end
diff --git a/lib/puppet/util/suidmanager.rb b/lib/puppet/util/suidmanager.rb
index c5df0d198..a0a9178bb 100644
--- a/lib/puppet/util/suidmanager.rb
+++ b/lib/puppet/util/suidmanager.rb
@@ -7,7 +7,7 @@ module Puppet::Util::SUIDManager
extend Forwardable
to_delegate_to_process = [ :euid=, :euid, :egid=, :egid,
- :uid=, :uid, :gid=, :gid ]
+ :uid=, :uid, :gid=, :gid, :groups=, :groups ]
to_delegate_to_process.each do |method|
def_delegator Process, method
@@ -26,13 +26,16 @@ module Puppet::Util::SUIDManager
# We set both because some programs like to drop privs, i.e. bash.
old_uid, old_gid = self.uid, self.gid
old_euid, old_egid = self.euid, self.egid
+ old_groups = self.groups
begin
self.egid = convert_xid :gid, new_gid if new_gid
+ self.initgroups(convert_xid(:uid, new_uid)) if new_uid
self.euid = convert_xid :uid, new_uid if new_uid
yield
ensure
self.euid, self.egid = old_euid, old_egid
+ self.groups = old_groups
end
end
module_function :asuser
@@ -49,6 +52,13 @@ module Puppet::Util::SUIDManager
end
module_function :convert_xid
+ # Initialize supplementary groups
+ def initgroups(user)
+ require 'etc'
+ Process.initgroups(Etc.getpwuid(user).name, Process.gid)
+ end
+
+ module_function :initgroups
def run_and_capture(command, new_uid=nil, new_gid=nil)
output = Puppet::Util.execute(command, :failonfail => false, :uid => new_uid, :gid => new_gid)
diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb
index f421d18d8..9ee90799f 100644
--- a/lib/puppet/util/tagging.rb
+++ b/lib/puppet/util/tagging.rb
@@ -16,13 +16,12 @@ module Puppet::Util::Tagging
@tags << tag unless @tags.include?(tag)
end
- # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
- qualified.collect { |name| x = name.split("::") }.flatten.each { |tag| @tags << tag unless @tags.include?(tag) }
+ handle_qualified_tags( qualified )
end
# Are we tagged with the provided tag?
- def tagged?(tag)
- defined?(@tags) and @tags.include?(tag.to_s)
+ def tagged?(*tags)
+ not ( self.tags & tags.flatten.collect { |t| t.to_s } ).empty?
end
# Return a copy of the tag list, so someone can't ask for our tags
@@ -32,8 +31,27 @@ module Puppet::Util::Tagging
@tags.dup
end
+ def tags=(tags)
+ @tags = []
+
+ return if tags.nil? or tags == ""
+
+ if tags.is_a?(String)
+ tags = tags.strip.split(/\s*,\s*/)
+ end
+
+ tags.each do |t|
+ tag(t)
+ end
+ end
+
private
+ def handle_qualified_tags( qualified )
+ # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
+ qualified.collect { |name| x = name.split("::") }.flatten.each { |tag| @tags << tag unless @tags.include?(tag) }
+ end
+
def valid_tag?(tag)
tag =~ /^\w[-\w:.]*$/
end