From 0ae58a9a6a6f201e6a32a4e9d567e04519d3f0b5 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 27 Feb 2008 10:35:22 +1100 Subject: Fixes #1099 - use of -m option with -d option for home directories --- lib/puppet/provider/nameservice/objectadd.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/puppet/provider/nameservice/objectadd.rb b/lib/puppet/provider/nameservice/objectadd.rb index 8ebf8924b..6149066db 100644 --- a/lib/puppet/provider/nameservice/objectadd.rb +++ b/lib/puppet/provider/nameservice/objectadd.rb @@ -25,9 +25,15 @@ class ObjectAdd < Puppet::Provider::NameService cmd = [command(:modify), flag(param), value] + if @resource[:allowdupe] == :true cmd << "-o" end + + if @resource.managehome? + cmd << "-m" + end + cmd << @resource[:name] return cmd -- cgit From 3b5daf77d4ab8da5d3ae9d20e86de8b79e74df2c Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 28 Feb 2008 13:29:32 +1100 Subject: Revert "Fixes #1099 - use of -m option with -d option for home directories" This reverts commit 0ae58a9a6a6f201e6a32a4e9d567e04519d3f0b5. --- lib/puppet/provider/nameservice/objectadd.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/nameservice/objectadd.rb b/lib/puppet/provider/nameservice/objectadd.rb index 6149066db..8ebf8924b 100644 --- a/lib/puppet/provider/nameservice/objectadd.rb +++ b/lib/puppet/provider/nameservice/objectadd.rb @@ -25,15 +25,9 @@ class ObjectAdd < Puppet::Provider::NameService cmd = [command(:modify), flag(param), value] - if @resource[:allowdupe] == :true cmd << "-o" end - - if @resource.managehome? - cmd << "-m" - end - cmd << @resource[:name] return cmd -- cgit From 4c47656a5f78ff3b13413e5d51948f3f3f36b60d Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 5 Mar 2008 21:25:40 +1100 Subject: Applies patches from #1111 and #1112 --- lib/puppet/provider/package/portage.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb index dccfeaf56..f795d0302 100644 --- a/lib/puppet/provider/package/portage.rb +++ b/lib/puppet/provider/package/portage.rb @@ -10,8 +10,8 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa defaultfor :operatingsystem => :gentoo def self.instances - result_format = /(\S+) (\S+) \[([^\[]*)(\[[^\]]*\])?\] \[[^0-9]*([^\s:\[]*)(\[[^\]]*\])?(:\S*)?\] ([\S]*) (.*)/ - result_fields = [:category, :name, :ensure, :ensure_overlay, :version_available, :overlay, :slot, :vendor, :description] + result_format = /(\S+) (\S+) \[(?:([0-9.a-zA-Z]+(?:_(?:alpha|beta|pre|rc|p)[0-9]*)*(?:-r[0-9]*)?)(?:\([^\)]+\))?(?:\[([^\]]+)\])?[ ]*)*\] \[(?:(?:\{M\})?(?:\([~*]+\))?([0-9.a-zA-Z]+(?:_(?:alpha|beta|pre|rc|p)[0-9]*)*(?:-r[0-9]*)?)(?:\(([^\)]+)\))?(?:![mf])*(?:\[([^\]]+)\])?)?\] ([\S]*) (.*)/ + result_fields = [:category, :name, :ensure, :ensure_overlay, :version_available, :slot, :overlay, :vendor, :description] search_format = "{installedversionsshort} [] [] {}" @@ -67,8 +67,8 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa end def query - result_format = /(\S+) (\S+) \[([^\[]*)(\[[^\]]*\])?\] \[[^0-9]*([^\s:\[]*)(\[[^\]]*\])?(:\S*)?\] ([\S]*) (.*)/ - result_fields = [:category, :name, :ensure, :ensure_overlay, :version_available, :overlay, :slot, :vendor, :description] + result_format = /(\S+) (\S+) \[(?:([0-9.a-zA-Z]+(?:_(?:alpha|beta|pre|rc|p)[0-9]*)*(?:-r[0-9]*)?)(?:\([^\)]+\))?(?:\[([^\]]+)\])?[ ]*)*\] \[(?:(?:\{M\})?(?:\([~*]+\))?([0-9.a-zA-Z]+(?:_(?:alpha|beta|pre|rc|p)[0-9]*)*(?:-r[0-9]*)?)(?:\(([^\)]+)\))?(?:![mf])*(?:\[([^\]]+)\])?)?\] ([\S]*) (.*)/ + result_fields = [:category, :name, :ensure, :ensure_overlay, :version_available, :slot, :overlay, :vendor, :description] search_field = @resource[:category] ? "--category-name" : "--name" search_value = package_name -- cgit From 8192475a041d933b4fdf9e82142b09c9633952f4 Mon Sep 17 00:00:00 2001 From: Andrew Shafer Date: Wed, 5 Mar 2008 13:08:20 -0700 Subject: Ticket #1041 The CA serial file was getting owned by root because it was using a different method to write to file Pulled the readwritelock out of lib/puppet/sslcertificates/ca.rb into lib/puppet/util/settings.rb Refactored write, writesub and readwritelock a bit to reuse code (write and readwritelock both call writesub) Added a mode to :serial in lib/puppet/util/defaults.rb --- lib/puppet/defaults.rb | 1 + lib/puppet/sslcertificates/ca.rb | 30 +------------ lib/puppet/util/settings.rb | 96 ++++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 76 deletions(-) (limited to 'lib') diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 77792172f..e0225803a 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -258,6 +258,7 @@ module Puppet :serial => { :default => "$cadir/serial", :owner => "$user", :group => "$group", + :mode => 0600, :desc => "Where the serial number for certificates is stored." }, :autosign => { :default => "$confdir/autosign.conf", diff --git a/lib/puppet/sslcertificates/ca.rb b/lib/puppet/sslcertificates/ca.rb index 888bcf5b2..7386318f4 100644 --- a/lib/puppet/sslcertificates/ca.rb +++ b/lib/puppet/sslcertificates/ca.rb @@ -238,33 +238,6 @@ class Puppet::SSLCertificates::CA } end - # Create an exclusive lock for reading and writing, and do the - # writing in a tmp file. - def readwritelock(file, mode = 0600) - tmpfile = file + ".tmp" - sync = Sync.new - unless FileTest.directory?(File.dirname(tmpfile)) - raise Puppet::DevError, "Cannot create %s; directory %s does not exist" % - [file, File.dirname(file)] - end - sync.synchronize(Sync::EX) do - File.open(file, "r+", mode) do |rf| - rf.lock_exclusive do - File.open(tmpfile, "w", mode) do |tf| - yield tf - end - begin - File.rename(tmpfile, file) - rescue => detail - Puppet.err "Could not rename %s to %s: %s" % - [file, tmpfile, detail] - end - end - end - end - end - - # Sign a given certificate request. def sign(csr) unless csr.is_a?(OpenSSL::X509::Request) @@ -278,9 +251,8 @@ class Puppet::SSLCertificates::CA end serial = nil - readwritelock(@config[:serial]) { |f| + Puppet.settings.readwritelock(:serial) { |f| serial = File.read(@config[:serial]).chomp.hex - # increment the serial f << "%04X" % (serial + 1) } diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index a91b0d6b1..259e2045b 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -243,14 +243,7 @@ class Puppet::Util::Settings # Make a directory with the appropriate user, group, and mode def mkdir(default) - obj = nil - unless obj = @config[default] - raise ArgumentError, "Unknown default %s" % default - end - - unless obj.is_a? CFile - raise ArgumentError, "Default %s is not a file" % default - end + obj = get_config_default(default) Puppet::Util::SUIDManager.asuser(obj.owner, obj.group) do mode = obj.mode || 0750 @@ -737,49 +730,15 @@ Generated on #{Time.now}. end # Open a file with the appropriate user, group, and mode - def write(default, *args) - obj = nil - unless obj = @config[default] - raise ArgumentError, "Unknown default %s" % default - end - - unless obj.is_a? CFile - raise ArgumentError, "Default %s is not a file" % default - end - - chown = nil - if Puppet::Util::SUIDManager.uid == 0 - chown = [obj.owner, obj.group] - else - chown = [nil, nil] - end - Puppet::Util::SUIDManager.asuser(*chown) do - mode = obj.mode || 0640 - - if args.empty? - args << "w" - end - - args << mode - - File.open(value(obj.name), *args) do |file| - yield file - end - end + def write(default, *args, &bloc) + obj = get_config_default(default) + writesub(default, value(obj.name), *args, &bloc) end # Open a non-default file under a default dir with the appropriate user, # group, and mode - def writesub(default, file, *args) - obj = nil - unless obj = @config[default] - raise ArgumentError, "Unknown default %s" % default - end - - unless obj.is_a? CFile - raise ArgumentError, "Default %s is not a file" % default - end - + def writesub(default, file, *args, &bloc) + obj = get_config_default(default) chown = nil if Puppet::Util::SUIDManager.uid == 0 chown = [obj.owner, obj.group] @@ -804,8 +763,51 @@ Generated on #{Time.now}. end end + def readwritelock(default, *args, &bloc) + file = value(get_config_default(default).name) + tmpfile = file + ".tmp" + sync = Sync.new + unless FileTest.directory?(File.dirname(tmpfile)) + raise Puppet::DevError, "Cannot create %s; directory %s does not exist" % + [file, File.dirname(file)] + end + + sync.synchronize(Sync::EX) do + File.open(file, "r+", 0600) do |rf| + rf.lock_exclusive do + if File.exist?(tmpfile) + raise Puppet::Error, ".tmp file already exists for %s; Aborting locked write. Check the .tmp file and delete if appropriate" % + [file] + end + + writesub(default, tmpfile, *args, &bloc) + + begin + File.rename(tmpfile, file) + rescue => detail + Puppet.err "Could not rename %s to %s: %s" % + [file, tmpfile, detail] + end + end + end + end + end + private + def get_config_default(default) + obj = nil + unless obj = @config[default] + raise ArgumentError, "Unknown default %s" % default + end + + unless obj.is_a? CFile + raise ArgumentError, "Default %s is not a file" % default + end + + return obj + end + # Create the transportable objects for users and groups. def add_user_resources(section, obj, done) resources = [] -- cgit From ee8fac6f24a35edf9234e49fb7aae71e625917f4 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 5 Mar 2008 18:55:32 -0700 Subject: Changed name of method for clarity per code review --- lib/puppet/util/settings.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 259e2045b..6e0b4b66d 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -243,7 +243,7 @@ class Puppet::Util::Settings # Make a directory with the appropriate user, group, and mode def mkdir(default) - obj = get_config_default(default) + obj = get_config_file_default(default) Puppet::Util::SUIDManager.asuser(obj.owner, obj.group) do mode = obj.mode || 0750 @@ -731,14 +731,14 @@ Generated on #{Time.now}. # Open a file with the appropriate user, group, and mode def write(default, *args, &bloc) - obj = get_config_default(default) + obj = get_config_file_default(default) writesub(default, value(obj.name), *args, &bloc) end # Open a non-default file under a default dir with the appropriate user, # group, and mode def writesub(default, file, *args, &bloc) - obj = get_config_default(default) + obj = get_config_file_default(default) chown = nil if Puppet::Util::SUIDManager.uid == 0 chown = [obj.owner, obj.group] @@ -764,7 +764,7 @@ Generated on #{Time.now}. end def readwritelock(default, *args, &bloc) - file = value(get_config_default(default).name) + file = value(get_config_file_default(default).name) tmpfile = file + ".tmp" sync = Sync.new unless FileTest.directory?(File.dirname(tmpfile)) @@ -795,7 +795,7 @@ Generated on #{Time.now}. private - def get_config_default(default) + def get_config_file_default(default) obj = nil unless obj = @config[default] raise ArgumentError, "Unknown default %s" % default -- cgit From 647f5b458e854bb393d6bba8664798b127d36821 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 6 Mar 2008 13:07:11 -0600 Subject: Always duplicating resource defaults in the parser, so that stacked metaparameter values do not result in all resources that receive a given default also getting those stacked values. --- lib/puppet/parser/compiler.rb | 1 - lib/puppet/parser/resource.rb | 37 +++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index 70cd6e11a..8fba41121 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -366,7 +366,6 @@ class Puppet::Parser::Compiler # Make sure all of our resources and such have done any last work # necessary. def finish - #@catalog.resources.each do |name| @catalog.vertices.each do |resource| # Add in any resource overrides. if overrides = resource_overrides(resource) diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index b001e165b..4b48ff6cf 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -233,6 +233,20 @@ class Puppet::Parser::Resource @ref.to_s end + # Define a parameter in our resource. + def set_parameter(param, value = nil) + if value + param = Puppet::Parser::Resource::Param.new( + :name => param, :value => value, :source => self.source + ) + elsif ! param.is_a?(Puppet::Parser::Resource::Param) + raise ArgumentError, "Must pass a parameter or all necessary values" + end + + # And store it in our parameter hash. + @params[param.name] = param + end + def to_hash @params.inject({}) do |hash, ary| param = ary[1] @@ -331,7 +345,7 @@ class Puppet::Parser::Resource unless @params.include?(name) self.debug "Adding default for %s" % name - @params[name] = param + @params[name] = param.dup end end end @@ -370,11 +384,8 @@ class Puppet::Parser::Resource # The parameter is already set. Fail if they're not allowed to override it. unless param.source.child_of?(current.source) - if Puppet[:trace] - puts caller - end - msg = "Parameter '%s' is already set on %s" % - [param.name, self.to_s] + puts caller if Puppet[:trace] + msg = "Parameter '%s' is already set on %s" % [param.name, self.to_s] if current.source.to_s != "" msg += " by %s" % current.source end @@ -426,20 +437,6 @@ class Puppet::Parser::Resource end end - # Define a parameter in our resource. - def set_parameter(param, value = nil) - if value - param = Puppet::Parser::Resource::Param.new( - :name => param, :value => value, :source => self.source - ) - elsif ! param.is_a?(Puppet::Parser::Resource::Param) - raise ArgumentError, "Must pass a parameter or all necessary values" - end - - # And store it in our parameter hash. - @params[param.name] = param - end - # Make sure the resource's parameters are all valid for the type. def validate @params.each do |name, param| -- cgit From 4c0f6c8502a0759519877f3e933e44ba980f7da2 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 6 Mar 2008 13:20:30 -0700 Subject: Fix for 1094 Replace the catalog with the newly created one when converting to ral types. The aliases were being lost because the resources had references to the old catalog being converted --- lib/puppet/node/catalog.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index f885a41ee..ecda472be 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -84,6 +84,7 @@ class Puppet::Node::Catalog < Puppet::PGraph # Create an alias for a resource. def alias(resource, name) + #set $1 resource.ref =~ /^(.+)\[/ newref = "%s[%s]" % [$1 || resource.class.name, name] @@ -475,6 +476,15 @@ class Puppet::Node::Catalog < Puppet::PGraph vertices.each do |resource| next if resource.respond_to?(:virtual?) and resource.virtual? + #This is hackity hack for 1094 + #Aliases aren't working in the ral catalog because the current instance of the resource + #has a reference to the catalog being converted. . . So, give it a reference to the new one + #problem solved. . . + if resource.is_a?(Puppet::TransObject) + resource = resource.dup + resource.catalog = result + end + newres = resource.send(convert) # We can't guarantee that resources don't munge their names -- cgit From 2261032801a39affa1a4c5e998fc2c4dd145503f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 6 Mar 2008 14:43:41 -0600 Subject: Partially fixing #1113: LDAP nodes now support environments, and the schema has been updated accordingly. --- lib/puppet/indirector/node/ldap.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index dd11f4e9b..9320f3ba1 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -36,11 +36,14 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap information[:parameters][param] = value unless information[:parameters].include?(param) end + information[:environment] ||= parent_info[:environment] + parent = parent_info[:parent] end node.classes = information[:classes].uniq unless information[:classes].empty? node.parameters = information[:parameters] unless information[:parameters].empty? + node.environment = information[:environment] if information[:environment] node.fact_merge return node @@ -87,6 +90,8 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap hash end + result[:environment] = result[:parameters]["environment"] if result[:parameters]["environment"] + return result end -- cgit From 35214eb7e2887ed4ab7e4ab0d8c92c724db495d2 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 6 Mar 2008 14:47:14 -0600 Subject: Fixing the rest of #1113: External node commands can specify an environment and Puppet will now use it. --- lib/puppet/indirector/node/exec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb index ed76bce94..71f4fa8e1 100644 --- a/lib/puppet/indirector/node/exec.rb +++ b/lib/puppet/indirector/node/exec.rb @@ -30,7 +30,7 @@ class Puppet::Node::Exec < Puppet::Indirector::Exec def create_node(name, result) node = Puppet::Node.new(name) set = false - [:parameters, :classes].each do |param| + [:parameters, :classes, :environment].each do |param| if value = result[param] node.send(param.to_s + "=", value) set = true -- cgit From ca0b62a0f8be88bf3dc33df6b2437d8105a71cea Mon Sep 17 00:00:00 2001 From: Blake Barnett Date: Thu, 6 Mar 2008 12:50:24 -0800 Subject: Cache the same type we check for, hopefully fixes #1116 --- lib/puppet/type/file/checksum.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb index debb5a7db..3be147cb7 100755 --- a/lib/puppet/type/file/checksum.rb +++ b/lib/puppet/type/file/checksum.rb @@ -66,6 +66,9 @@ Puppet::Type.type(:file).newproperty(:checksum) do raise ArgumentError, "A type must be specified to cache a checksum" end type = symbolize(type) + type = :mtime if type == :timestamp + type = :ctime if type == :time + unless state = @resource.cached(:checksums) self.debug "Initializing checksum hash" state = {} -- cgit From f1216f82d564d089fb20fd29545e918b3100e02a Mon Sep 17 00:00:00 2001 From: Blake Barnett Date: Thu, 6 Mar 2008 12:51:55 -0800 Subject: Revert "Cache the same type we check for, hopefully fixes #1116" This reverts commit ca0b62a0f8be88bf3dc33df6b2437d8105a71cea. --- lib/puppet/type/file/checksum.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb index 3be147cb7..debb5a7db 100755 --- a/lib/puppet/type/file/checksum.rb +++ b/lib/puppet/type/file/checksum.rb @@ -66,9 +66,6 @@ Puppet::Type.type(:file).newproperty(:checksum) do raise ArgumentError, "A type must be specified to cache a checksum" end type = symbolize(type) - type = :mtime if type == :timestamp - type = :ctime if type == :time - unless state = @resource.cached(:checksums) self.debug "Initializing checksum hash" state = {} -- cgit From eecc22c52dceeccca148e543336a6cd7d64498e6 Mon Sep 17 00:00:00 2001 From: Blake Barnett Date: Thu, 6 Mar 2008 12:53:57 -0800 Subject: Cache the same type we check for, hopefully fixes #1116 --- lib/puppet/type/file/checksum.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb index debb5a7db..3be147cb7 100755 --- a/lib/puppet/type/file/checksum.rb +++ b/lib/puppet/type/file/checksum.rb @@ -66,6 +66,9 @@ Puppet::Type.type(:file).newproperty(:checksum) do raise ArgumentError, "A type must be specified to cache a checksum" end type = symbolize(type) + type = :mtime if type == :timestamp + type = :ctime if type == :time + unless state = @resource.cached(:checksums) self.debug "Initializing checksum hash" state = {} -- cgit From e8029cc61a1956263935a0df469cc77b8e80a102 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 7 Mar 2008 12:09:46 -0600 Subject: Fixing the "tidy" type to use an option hash for specifying its parent class --- lib/puppet/type/tidy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb index dacf037ac..fe8bde9ab 100755 --- a/lib/puppet/type/tidy.rb +++ b/lib/puppet/type/tidy.rb @@ -1,5 +1,5 @@ module Puppet - newtype(:tidy, Puppet.type(:file)) do + newtype(:tidy, :parent => Puppet.type(:file)) do @doc = "Remove unwanted files based on specific criteria. Multiple criteria are OR'd together, so a file that is too large but is not old enough will still get tidied." -- cgit