summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/filetype.rb22
-rw-r--r--lib/puppet/parser/scope.rb3
-rw-r--r--lib/puppet/statechange.rb6
-rwxr-xr-xlib/puppet/type/cron.rb60
-rwxr-xr-xlib/puppet/type/parsedtype.rb3
-rw-r--r--lib/puppet/util.rb109
6 files changed, 123 insertions, 80 deletions
diff --git a/lib/puppet/filetype.rb b/lib/puppet/filetype.rb
index c86ed9c07..f67382b56 100755
--- a/lib/puppet/filetype.rb
+++ b/lib/puppet/filetype.rb
@@ -44,6 +44,9 @@ module Puppet
rescue Puppet::Error => detail
raise
rescue => detail
+ if Puppet[:debug]
+ puts detail.backtrace
+ end
raise Puppet::Error, "%s could not read %s: %s" %
[self.class, @path, detail]
end
@@ -134,29 +137,38 @@ module Puppet
# Only add the -u flag when the @path is different. Fedora apparently
# does not think I should be allowed to set the @path to my
def cmdbase
- uid = CronType.uid(@path)
cmd = nil
- if uid == Process.uid
+ if @path == Process.uid
return "crontab"
else
return "crontab -u #{@path}"
end
end
+ def initialize(user)
+ begin
+ uid = Puppet::Util.uid(user)
+ rescue Puppet::Error => detail
+ raise Puppet::Error, "Could not retrieve user %s" % user
+ end
+
+ @path = uid
+ end
+
# Read a specific @path's cron tab.
def read
- %x{#{cmdbase(@path)} -l 2>/dev/null}
+ %x{#{cmdbase()} -l 2>/dev/null}
end
# Remove a specific @path's cron tab.
def remove
- %x{#{cmdbase(@path)} -r 2>/dev/null}
+ %x{#{cmdbase()} -r 2>/dev/null}
end
# Overwrite a specific @path's cron tab; must be passed the @path name
# and the text with which to create the cron tab.
def write(text)
- IO.popen("#{cmdbase(@path)} -", "w") { |p|
+ IO.popen("#{cmdbase()} -", "w") { |p|
p.print text
}
end
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index d05ccac03..6cdc24178 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -564,6 +564,9 @@ module Puppet
# in the scope tree, which is what provides some minimal closure-like
# behaviour.
def setobject(type, name, params, file, line)
+ # FIXME This objectlookup stuff should be looking up using both
+ # the name and the namevar.
+
# First see if we can look the object up using normal scope
# rules, i.e., one of our parent classes has defined the
# object or something
diff --git a/lib/puppet/statechange.rb b/lib/puppet/statechange.rb
index 8adbb5d91..b260f0bd3 100644
--- a/lib/puppet/statechange.rb
+++ b/lib/puppet/statechange.rb
@@ -12,7 +12,7 @@ module Puppet
@path = [state.path,"change"].flatten
@is = state.is
- if state.is == state.should
+ if state.insync?
raise Puppet::Error.new(
"Tried to create a change for in-sync state %s" % state.name
)
@@ -25,8 +25,8 @@ module Puppet
#---------------------------------------------------------------
def go
- if @state.is == @state.should
- @state.info "already in sync"
+ if @state.insync?
+ @state.info "Already in sync"
return nil
end
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index 21794e5f6..7e44125a2 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -21,6 +21,16 @@ module Puppet
attr_accessor :boundaries
end
+ # We have to override the parent method, because we consume the entire
+ # "should" array
+ def insync?
+ if self.class.name == :command
+ return super
+ else
+ return @is == @should
+ end
+ end
+
# A method used to do parameter input handling. Converts integers
# in string form to actual integers, and returns the value if it's
# an integer or false if it's just a normal string.
@@ -67,6 +77,18 @@ module Puppet
return false
end
+ def is_to_s
+ if @is.empty?
+ return "*"
+ else
+ if @is.is_a? Array
+ return @is.join(",")
+ else
+ return @is.to_s
+ end
+ end
+ end
+
def should_to_s
if @should.empty?
return "*"
@@ -169,16 +191,18 @@ module Puppet
newparam(:user) do
desc "The user to run the command as. This user must
be allowed to run cron jobs, which is not currently checked by
- Puppet."
+ Puppet.
+
+ The user defaults to whomever Puppet is running as."
+
+ defaultto Process.uid
- # This validation isn't really a good idea, since the user might
- # be created by Puppet, in which case the validation will fail.
validate do |user|
require 'etc'
begin
- obj = Etc.getpwnam(user)
- parent.uid = obj.uid
+ parent.uid = Puppet::Util.uid(user)
+ #obj = Etc.getpwnam(user)
rescue ArgumentError
self.fail "User %s not found" % user
end
@@ -212,13 +236,6 @@ module Puppet
@instances = {}
@tabs = {}
- case Facter["operatingsystem"].value
- when "Solaris":
- @filetype = Puppet::FileType.filetype(:suntab)
- else
- @filetype = Puppet::FileType.filetype(:crontab)
- end
-
class << self
attr_accessor :filetype
end
@@ -240,6 +257,17 @@ module Puppet
super
end
+ def self.defaulttype
+ case Facter["operatingsystem"].value
+ when "Solaris":
+ return Puppet::FileType.filetype(:suntab)
+ else
+ return Puppet::FileType.filetype(:crontab)
+ end
+ end
+
+ self.filetype = self.defaulttype()
+
# Override the default Puppet::Type method, because instances
# also need to be deleted from the @instances hash
def self.delete(child)
@@ -303,9 +331,9 @@ module Puppet
fields().zip(match.captures).each { |param, value|
unless value == "*"
unless param == :command
- if value =~ /,/
- value = value.split(",")
- end
+ # We always want the 'is' value to be an
+ # array
+ value = value.split(",")
end
hash[param] = value
end
@@ -403,7 +431,7 @@ module Puppet
# Collect all Cron instances for a given user and convert them
# into literal text.
def self.tab(user)
- Puppet.info "writing cron tab for %s" % user
+ Puppet.info "Writing cron tab for %s" % user
if @instances.include?(user)
return self.header() + @instances[user].reject { |obj|
if obj.is_a?(self) and obj.should(:ensure) == :absent
diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb
index 268b7ad56..2048ba934 100755
--- a/lib/puppet/type/parsedtype.rb
+++ b/lib/puppet/type/parsedtype.rb
@@ -55,7 +55,8 @@ module Puppet
tail = "deleted"
#elsif @is == @should
elsif self.insync?
- self.info "already in sync"
+ self.info "Already in sync: %s vs %s" %
+ [@is.inspect, @should.inspect]
return nil
else
#@is = self.should
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index d84021a46..44b3bae44 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -21,21 +21,7 @@ module Util
# The gid has to be changed first, because, well, otherwise we won't
# be able to
if group
- if group.is_a?(Integer)
- gid = group
- else
- unless obj = Puppet.type(:group)[group]
- obj = Puppet.type(:group).create(
- :name => group,
- :check => [:gid]
- )
- end
- obj.retrieve
- gid = obj.is(:gid)
- unless gid.is_a?(Integer)
- raise Puppet::Error, "Could not find group %s" % group
- end
- end
+ gid = self.gid(group)
if Process.gid != gid
oldgid = Process.gid
@@ -48,23 +34,7 @@ module Util
end
if user
- # Retrieve the user id
- if user.is_a?(Integer)
- uid = user
- else
- unless obj = Puppet.type(:user)[user]
- obj = Puppet.type(:user).create(
- :name => user,
- :check => [:uid, :gid]
- )
- end
- obj.retrieve
- uid = obj.is(:uid)
- unless uid.is_a?(Integer)
- raise Puppet::Error, "Could not find user %s" % user
- end
- end
-
+ uid = self.uid(user)
# Now change the uid
if Process.uid != uid
olduid = Process.uid
@@ -93,16 +63,7 @@ module Util
# Change the process to a different user
def self.chuser
if group = Puppet[:group]
- if group =~ /^\d+$/
- group = Integer(group)
- else
- begin
- g = Etc.getgrnam(group)
- rescue ArgumentError
- $stderr.puts "Could not find group %s" % group
- end
- group = g.gid
- end
+ group = self.gid(group)
unless Process.gid == group
begin
Process.egid = group
@@ -115,16 +76,7 @@ module Util
end
if user = Puppet[:user]
- if user =~ /^\d+$/
- user = Integer(user)
- else
- begin
- u = Etc.getpwnam(user)
- rescue ArgumentError
- $stderr.puts "Could not find user %s" % user
- end
- user = u.uid
- end
+ user = self.uid(user)
unless Process.uid == user
begin
Process.euid = user
@@ -146,9 +98,6 @@ module Util
end
end
- def self.sync
- end
-
# Create an exclusive lock fro writing, and do the writing in a
# tmp file.
def self.writelock(file, mode = 0600)
@@ -172,6 +121,56 @@ module Util
end
end
+ # Get the GID of a given group, provided either a GID or a name
+ def self.gid(group)
+ if group =~ /^\d+$/
+ group = Integer(group)
+ end
+ gid = nil
+ if group.is_a?(Integer)
+ gid = group
+ else
+ unless obj = Puppet.type(:group)[group]
+ obj = Puppet.type(:group).create(
+ :name => group,
+ :check => [:gid]
+ )
+ end
+ obj.retrieve
+ gid = obj.is(:gid)
+ unless gid.is_a?(Integer)
+ raise Puppet::Error, "Could not find group %s" % group
+ end
+ end
+
+ return gid
+ end
+
+ # Get the UID of a given user, whether a UID or name is provided
+ def self.uid(user)
+ uid = nil
+ if user =~ /^\d+$/
+ user = Integer(user)
+ end
+ if user.is_a?(Integer)
+ uid = user
+ else
+ unless obj = Puppet.type(:user)[user]
+ obj = Puppet.type(:user).create(
+ :name => user,
+ :check => [:uid, :gid]
+ )
+ end
+ obj.retrieve
+ uid = obj.is(:uid)
+ unless uid.is_a?(Integer)
+ raise Puppet::Error, "Could not find user %s" % user
+ end
+ end
+
+ return uid
+ end
+
# Create a lock file while something is happening
def self.disabledlock(*opts)
lock = opts[0] + ".lock"