puppet 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +0 -0
- data/COPYING +340 -0
- data/LICENSE +17 -0
- data/README +24 -0
- data/Rakefile +294 -0
- data/TODO +4 -0
- data/bin/cf2puppet +186 -0
- data/bin/puppet +176 -0
- data/bin/puppetca +213 -0
- data/bin/puppetd +246 -0
- data/bin/puppetdoc +184 -0
- data/bin/puppetmasterd +258 -0
- data/examples/code/allatonce +13 -0
- data/examples/code/assignments +11 -0
- data/examples/code/classing +35 -0
- data/examples/code/components +73 -0
- data/examples/code/execs +16 -0
- data/examples/code/failers/badclassnoparam +10 -0
- data/examples/code/failers/badclassparam +10 -0
- data/examples/code/failers/badcompnoparam +9 -0
- data/examples/code/failers/badcompparam +9 -0
- data/examples/code/failers/badtypeparam +3 -0
- data/examples/code/file.bl +11 -0
- data/examples/code/filedefaults +10 -0
- data/examples/code/fileparsing +116 -0
- data/examples/code/filerecursion +15 -0
- data/examples/code/functions +3 -0
- data/examples/code/groups +7 -0
- data/examples/code/head +30 -0
- data/examples/code/importing +8 -0
- data/examples/code/nodes +20 -0
- data/examples/code/one +8 -0
- data/examples/code/relationships +34 -0
- data/examples/code/selectors +28 -0
- data/examples/code/simpletests +11 -0
- data/examples/code/snippets/argumentdefaults +14 -0
- data/examples/code/snippets/casestatement +39 -0
- data/examples/code/snippets/classheirarchy.pp +15 -0
- data/examples/code/snippets/classincludes.pp +17 -0
- data/examples/code/snippets/classpathtest +11 -0
- data/examples/code/snippets/dirchmod +19 -0
- data/examples/code/snippets/failmissingexecpath.pp +13 -0
- data/examples/code/snippets/falsevalues.pp +3 -0
- data/examples/code/snippets/filecreate +11 -0
- data/examples/code/snippets/implicititeration +15 -0
- data/examples/code/snippets/multipleinstances +7 -0
- data/examples/code/snippets/namevartest +9 -0
- data/examples/code/snippets/scopetest +13 -0
- data/examples/code/snippets/selectorvalues.pp +22 -0
- data/examples/code/snippets/simpledefaults +5 -0
- data/examples/code/snippets/simpleselector +38 -0
- data/examples/code/svncommit +13 -0
- data/examples/root/bin/sleeper +69 -0
- data/examples/root/etc/configfile +0 -0
- data/examples/root/etc/debian-passwd +29 -0
- data/examples/root/etc/debian-syslog.conf +71 -0
- data/examples/root/etc/init.d/sleeper +65 -0
- data/examples/root/etc/otherfile +0 -0
- data/examples/root/etc/puppet/fileserver.conf +3 -0
- data/examples/root/etc/puppet/puppetmasterd.conf +10 -0
- data/ext/module:puppet +195 -0
- data/install.rb +270 -0
- data/lib/puppet.rb +249 -0
- data/lib/puppet/base64.rb +19 -0
- data/lib/puppet/client.rb +519 -0
- data/lib/puppet/config.rb +49 -0
- data/lib/puppet/daemon.rb +208 -0
- data/lib/puppet/element.rb +71 -0
- data/lib/puppet/event.rb +259 -0
- data/lib/puppet/log.rb +321 -0
- data/lib/puppet/metric.rb +250 -0
- data/lib/puppet/parsedfile.rb +38 -0
- data/lib/puppet/parser/ast.rb +1560 -0
- data/lib/puppet/parser/interpreter.rb +150 -0
- data/lib/puppet/parser/lexer.rb +226 -0
- data/lib/puppet/parser/parser.rb +1354 -0
- data/lib/puppet/parser/scope.rb +755 -0
- data/lib/puppet/server.rb +170 -0
- data/lib/puppet/server/authstore.rb +227 -0
- data/lib/puppet/server/ca.rb +140 -0
- data/lib/puppet/server/filebucket.rb +147 -0
- data/lib/puppet/server/fileserver.rb +477 -0
- data/lib/puppet/server/logger.rb +43 -0
- data/lib/puppet/server/master.rb +103 -0
- data/lib/puppet/server/servlet.rb +247 -0
- data/lib/puppet/sslcertificates.rb +737 -0
- data/lib/puppet/statechange.rb +150 -0
- data/lib/puppet/storage.rb +95 -0
- data/lib/puppet/transaction.rb +179 -0
- data/lib/puppet/transportable.rb +151 -0
- data/lib/puppet/type.rb +1354 -0
- data/lib/puppet/type/component.rb +141 -0
- data/lib/puppet/type/cron.rb +543 -0
- data/lib/puppet/type/exec.rb +316 -0
- data/lib/puppet/type/group.rb +152 -0
- data/lib/puppet/type/nameservice.rb +3 -0
- data/lib/puppet/type/nameservice/netinfo.rb +173 -0
- data/lib/puppet/type/nameservice/objectadd.rb +146 -0
- data/lib/puppet/type/nameservice/posix.rb +200 -0
- data/lib/puppet/type/package.rb +420 -0
- data/lib/puppet/type/package/apt.rb +70 -0
- data/lib/puppet/type/package/dpkg.rb +108 -0
- data/lib/puppet/type/package/rpm.rb +81 -0
- data/lib/puppet/type/package/sun.rb +117 -0
- data/lib/puppet/type/package/yum.rb +58 -0
- data/lib/puppet/type/pfile.rb +569 -0
- data/lib/puppet/type/pfile/checksum.rb +219 -0
- data/lib/puppet/type/pfile/create.rb +108 -0
- data/lib/puppet/type/pfile/group.rb +129 -0
- data/lib/puppet/type/pfile/mode.rb +131 -0
- data/lib/puppet/type/pfile/source.rb +264 -0
- data/lib/puppet/type/pfile/type.rb +31 -0
- data/lib/puppet/type/pfile/uid.rb +166 -0
- data/lib/puppet/type/pfilebucket.rb +80 -0
- data/lib/puppet/type/pprocess.rb +97 -0
- data/lib/puppet/type/service.rb +347 -0
- data/lib/puppet/type/service/base.rb +17 -0
- data/lib/puppet/type/service/debian.rb +50 -0
- data/lib/puppet/type/service/init.rb +145 -0
- data/lib/puppet/type/service/smf.rb +29 -0
- data/lib/puppet/type/state.rb +182 -0
- data/lib/puppet/type/symlink.rb +183 -0
- data/lib/puppet/type/tidy.rb +183 -0
- data/lib/puppet/type/typegen.rb +149 -0
- data/lib/puppet/type/typegen/filerecord.rb +243 -0
- data/lib/puppet/type/typegen/filetype.rb +316 -0
- data/lib/puppet/type/user.rb +290 -0
- data/lib/puppet/util.rb +138 -0
- data/test/certmgr/certmgr.rb +265 -0
- data/test/client/client.rb +203 -0
- data/test/executables/puppetbin.rb +53 -0
- data/test/executables/puppetca.rb +79 -0
- data/test/executables/puppetd.rb +71 -0
- data/test/executables/puppetmasterd.rb +153 -0
- data/test/executables/puppetmodule.rb +60 -0
- data/test/language/ast.rb +412 -0
- data/test/language/interpreter.rb +71 -0
- data/test/language/scope.rb +412 -0
- data/test/language/snippets.rb +445 -0
- data/test/other/events.rb +111 -0
- data/test/other/log.rb +195 -0
- data/test/other/metrics.rb +92 -0
- data/test/other/overrides.rb +115 -0
- data/test/other/parsedfile.rb +31 -0
- data/test/other/relationships.rb +113 -0
- data/test/other/state.rb +106 -0
- data/test/other/storage.rb +39 -0
- data/test/other/transactions.rb +235 -0
- data/test/parser/lexer.rb +120 -0
- data/test/parser/parser.rb +180 -0
- data/test/puppet/conffiles.rb +104 -0
- data/test/puppet/defaults.rb +100 -0
- data/test/puppet/error.rb +23 -0
- data/test/puppet/utiltest.rb +120 -0
- data/test/puppettest.rb +774 -0
- data/test/server/authstore.rb +209 -0
- data/test/server/bucket.rb +227 -0
- data/test/server/ca.rb +201 -0
- data/test/server/fileserver.rb +710 -0
- data/test/server/logger.rb +175 -0
- data/test/server/master.rb +150 -0
- data/test/server/server.rb +130 -0
- data/test/tagging/tagging.rb +80 -0
- data/test/test +51 -0
- data/test/types/basic.rb +119 -0
- data/test/types/component.rb +272 -0
- data/test/types/cron.rb +261 -0
- data/test/types/exec.rb +273 -0
- data/test/types/file.rb +616 -0
- data/test/types/filebucket.rb +167 -0
- data/test/types/fileignoresource.rb +287 -0
- data/test/types/filesources.rb +587 -0
- data/test/types/filetype.rb +162 -0
- data/test/types/group.rb +271 -0
- data/test/types/package.rb +205 -0
- data/test/types/query.rb +101 -0
- data/test/types/service.rb +100 -0
- data/test/types/symlink.rb +93 -0
- data/test/types/tidy.rb +124 -0
- data/test/types/type.rb +135 -0
- data/test/types/user.rb +371 -0
- metadata +243 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
# Manage file modes. This state should support different formats
|
2
|
+
# for specification (e.g., u+rwx, or -0011), but for now only supports
|
3
|
+
# specifying the full mode.
|
4
|
+
module Puppet
|
5
|
+
class State
|
6
|
+
class PFileMode < Puppet::State
|
7
|
+
require 'etc'
|
8
|
+
@doc = "Mode the file should be. Currently relatively limited:
|
9
|
+
you must specify the exact mode the file should be."
|
10
|
+
@name = :mode
|
11
|
+
@event = :inode_changed
|
12
|
+
|
13
|
+
# Our modes are octal, so make sure they print correctly. Other
|
14
|
+
# valid values are symbols, basically
|
15
|
+
def is_to_s
|
16
|
+
case @is
|
17
|
+
when Integer
|
18
|
+
return "%o" % @is
|
19
|
+
when Symbol
|
20
|
+
return @is
|
21
|
+
else
|
22
|
+
raise Puppet::DevError, "Invalid 'is' value for mode: %s" %
|
23
|
+
@is.inspect
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def should_to_s
|
28
|
+
case self.should
|
29
|
+
when Integer
|
30
|
+
return "%o" % self.should
|
31
|
+
when Symbol
|
32
|
+
return self.should
|
33
|
+
else
|
34
|
+
raise Puppet::DevError, "Invalid 'should' value for mode: %s" %
|
35
|
+
self.should.inspect
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def shouldprocess(should)
|
40
|
+
# this is pretty hackish, but i need to make sure the number is in
|
41
|
+
# octal, yet the number can only be specified as a string right now
|
42
|
+
value = should
|
43
|
+
if value.is_a?(String)
|
44
|
+
unless value =~ /^[0-9]+$/
|
45
|
+
raise Puppet::Error, "File modes can only be numbers"
|
46
|
+
end
|
47
|
+
unless value =~ /^0/
|
48
|
+
value = "0" + value
|
49
|
+
end
|
50
|
+
begin
|
51
|
+
value = Integer(value)
|
52
|
+
rescue ArgumentError => detail
|
53
|
+
raise Puppet::DevError, "Could not convert %s to integer" %
|
54
|
+
value.inspect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
return value
|
59
|
+
end
|
60
|
+
|
61
|
+
# If we're a directory, we need to be executable for all cases
|
62
|
+
# that are readable. This should probably be selectable, but eh.
|
63
|
+
def dirmask(value)
|
64
|
+
if FileTest.directory?(@parent.name)
|
65
|
+
if value & 0400 != 0
|
66
|
+
value |= 0100
|
67
|
+
end
|
68
|
+
if value & 040 != 0
|
69
|
+
value |= 010
|
70
|
+
end
|
71
|
+
if value & 04 != 0
|
72
|
+
value |= 01
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
return value
|
77
|
+
end
|
78
|
+
|
79
|
+
def retrieve
|
80
|
+
if stat = @parent.stat(true)
|
81
|
+
self.is = stat.mode & 007777
|
82
|
+
unless defined? @fixed
|
83
|
+
if defined? @should and @should
|
84
|
+
@should = @should.collect { |s| self.dirmask(s) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
else
|
88
|
+
self.is = :notfound
|
89
|
+
end
|
90
|
+
|
91
|
+
#self.debug "chmod state is %o" % self.is
|
92
|
+
end
|
93
|
+
|
94
|
+
def sync
|
95
|
+
if @is == :notfound
|
96
|
+
@parent.stat(true)
|
97
|
+
self.retrieve
|
98
|
+
#self.debug "%s: after refresh, is '%s'" % [self.class.name,@is]
|
99
|
+
if @is == :notfound
|
100
|
+
self.info "File does not exist; cannot set mode" %
|
101
|
+
@parent.name
|
102
|
+
return nil
|
103
|
+
end
|
104
|
+
|
105
|
+
if self.insync?
|
106
|
+
# we're already in sync
|
107
|
+
return nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
mode = self.should
|
112
|
+
|
113
|
+
if mode == :notfound
|
114
|
+
# This is really only valid for create states...
|
115
|
+
return nil
|
116
|
+
end
|
117
|
+
|
118
|
+
begin
|
119
|
+
File.chmod(mode,@parent[:path])
|
120
|
+
rescue => detail
|
121
|
+
error = Puppet::Error.new("failed to chmod %s: %s" %
|
122
|
+
[@parent.name, detail.message])
|
123
|
+
raise error
|
124
|
+
end
|
125
|
+
return :inode_changed
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# $Id: mode.rb 740 2005-11-01 20:22:19Z luke $
|
@@ -0,0 +1,264 @@
|
|
1
|
+
module Puppet
|
2
|
+
class State
|
3
|
+
# Copy files from a local or remote source.
|
4
|
+
class PFileSource < Puppet::State
|
5
|
+
attr_accessor :source, :local
|
6
|
+
@doc = "Copy a file over the current file. Uses `checksum` to
|
7
|
+
determine when a file should be copied. Valid values are either
|
8
|
+
fully qualified paths to files, or URIs. Currently supported URI
|
9
|
+
types are *puppet* and *file*."
|
10
|
+
@name = :source
|
11
|
+
|
12
|
+
# Ask the file server to describe our file.
|
13
|
+
def describe(source)
|
14
|
+
sourceobj, path = @parent.uri2obj(source)
|
15
|
+
server = sourceobj.server
|
16
|
+
|
17
|
+
begin
|
18
|
+
desc = server.describe(path)
|
19
|
+
rescue NetworkClientError => detail
|
20
|
+
self.err "Could not describe %s: %s" %
|
21
|
+
[path, detail]
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
|
25
|
+
args = {}
|
26
|
+
Puppet::Type::PFile::PINPARAMS.zip(
|
27
|
+
desc.split("\t")
|
28
|
+
).each { |param, value|
|
29
|
+
if value =~ /^[0-9]+$/
|
30
|
+
value = value.to_i
|
31
|
+
end
|
32
|
+
unless value.nil?
|
33
|
+
args[param] = value
|
34
|
+
end
|
35
|
+
}
|
36
|
+
|
37
|
+
# we can't manage ownership as root, so don't even try
|
38
|
+
unless Process.uid == 0
|
39
|
+
args.delete(:owner)
|
40
|
+
end
|
41
|
+
|
42
|
+
if args.empty?
|
43
|
+
return nil
|
44
|
+
else
|
45
|
+
return args
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# This basically calls describe() on our file, and then sets all
|
50
|
+
# of the local states appropriately. If the remote file is a normal
|
51
|
+
# file then we set it to copy; if it's a directory, then we just mark
|
52
|
+
# that the local directory should be created.
|
53
|
+
def retrieve
|
54
|
+
sum = nil
|
55
|
+
|
56
|
+
unless defined? @shouldorig
|
57
|
+
raise Puppet::DevError, "No sources defined for %s" %
|
58
|
+
@parent.name
|
59
|
+
end
|
60
|
+
|
61
|
+
@source = nil
|
62
|
+
|
63
|
+
# Find the first source that exists. @shouldorig contains
|
64
|
+
# the sources as specified by the user.
|
65
|
+
@shouldorig.each { |source|
|
66
|
+
if @stats = self.describe(source)
|
67
|
+
@source = source
|
68
|
+
break
|
69
|
+
end
|
70
|
+
}
|
71
|
+
|
72
|
+
if @stats.nil? or @stats[:type].nil?
|
73
|
+
@is = :notdescribed
|
74
|
+
@source = nil
|
75
|
+
return nil
|
76
|
+
end
|
77
|
+
|
78
|
+
# Take each of the stats and set them as states on the local file
|
79
|
+
# if a value has not already been provided.
|
80
|
+
@stats.each { |stat, value|
|
81
|
+
next if stat == :checksum
|
82
|
+
next if stat == :type
|
83
|
+
|
84
|
+
# was the stat already specified, or should the value
|
85
|
+
# be inherited from the source?
|
86
|
+
unless @parent.argument?(stat)
|
87
|
+
if state = @parent.state(stat)
|
88
|
+
state.should = value
|
89
|
+
else
|
90
|
+
@parent[stat] = value
|
91
|
+
end
|
92
|
+
end
|
93
|
+
}
|
94
|
+
|
95
|
+
# If we're a normal file, then set things up to copy the file down.
|
96
|
+
case @stats[:type]
|
97
|
+
when "file":
|
98
|
+
if sum = @parent.state(:checksum)
|
99
|
+
if sum.is
|
100
|
+
if sum.is == :notfound
|
101
|
+
sum.retrieve
|
102
|
+
end
|
103
|
+
@is = sum.is
|
104
|
+
else
|
105
|
+
@is = :notfound
|
106
|
+
end
|
107
|
+
else
|
108
|
+
self.info "File does not have checksum"
|
109
|
+
@is = :notfound
|
110
|
+
end
|
111
|
+
|
112
|
+
@should = [@stats[:checksum]]
|
113
|
+
|
114
|
+
if state = @parent.state(:create)
|
115
|
+
unless state.should == "file"
|
116
|
+
self.notice(
|
117
|
+
"File %s had both create and source enabled" %
|
118
|
+
@parent.name
|
119
|
+
)
|
120
|
+
@parent.delete(:create)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
# If we're a directory, then do not copy anything, and instead just
|
124
|
+
# create the directory using the 'create' state.
|
125
|
+
when "directory":
|
126
|
+
if state = @parent.state(:create)
|
127
|
+
unless state.should == "directory"
|
128
|
+
state.should = "directory"
|
129
|
+
end
|
130
|
+
else
|
131
|
+
@parent[:create] = "directory"
|
132
|
+
@parent.state(:create).retrieve
|
133
|
+
end
|
134
|
+
# we'll let the :create state do our work
|
135
|
+
@should.clear
|
136
|
+
@is = true
|
137
|
+
# FIXME We should at least support symlinks, I would think...
|
138
|
+
else
|
139
|
+
self.err "Cannot use files of type %s as sources" %
|
140
|
+
@stats[:type]
|
141
|
+
@should = nil
|
142
|
+
@is = true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# The special thing here is that we need to make sure that 'should'
|
147
|
+
# is only set for files, not directories. The processing we're doing
|
148
|
+
# here doesn't really matter, because the @should values will be
|
149
|
+
# overridden when we 'retrieve'.
|
150
|
+
def shouldprocess(source)
|
151
|
+
unless @parent.uri2obj(source)
|
152
|
+
raise Puppet::Error, "Invalid source %s" % source
|
153
|
+
end
|
154
|
+
|
155
|
+
if ! defined? @stats or @stats.nil?
|
156
|
+
# stupid hack for now; it'll get overriden
|
157
|
+
return source
|
158
|
+
else
|
159
|
+
if @stats[:type] == "directory"
|
160
|
+
@is = true
|
161
|
+
return nil
|
162
|
+
else
|
163
|
+
return source
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def sync
|
169
|
+
if @is == :notdescribed
|
170
|
+
self.retrieve # try again
|
171
|
+
if @is == :notdescribed
|
172
|
+
@parent.log "Could not retreive information on %s" %
|
173
|
+
@parent.name
|
174
|
+
return nil
|
175
|
+
end
|
176
|
+
if @is == @should
|
177
|
+
return nil
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
unless @stats[:type] == "file"
|
182
|
+
if @stats[:type] == "directory"
|
183
|
+
[@parent.name, @is.inspect, @should.inspect]
|
184
|
+
end
|
185
|
+
raise Puppet::DevError, "Got told to copy non-file %s" %
|
186
|
+
@parent.name
|
187
|
+
end
|
188
|
+
|
189
|
+
unless defined? @source
|
190
|
+
raise Puppet::DevError, "Somehow source is still undefined"
|
191
|
+
end
|
192
|
+
|
193
|
+
sourceobj, path = @parent.uri2obj(@source)
|
194
|
+
|
195
|
+
begin
|
196
|
+
contents = sourceobj.server.retrieve(path)
|
197
|
+
rescue NetworkClientError => detail
|
198
|
+
self.err "Could not retrieve %s: %s" %
|
199
|
+
[path, detail]
|
200
|
+
return nil
|
201
|
+
end
|
202
|
+
|
203
|
+
# FIXME It's stupid that this isn't taken care of in the
|
204
|
+
# protocol.
|
205
|
+
unless sourceobj.server.local
|
206
|
+
contents = CGI.unescape(contents)
|
207
|
+
end
|
208
|
+
|
209
|
+
if contents == ""
|
210
|
+
self.notice "Could not retrieve contents for %s" %
|
211
|
+
@source
|
212
|
+
end
|
213
|
+
|
214
|
+
if FileTest.exists?(@parent.name)
|
215
|
+
# this makes sure we have a copy for posterity
|
216
|
+
@backed = @parent.handlebackup
|
217
|
+
end
|
218
|
+
|
219
|
+
# create the file in a tmp location
|
220
|
+
args = [@parent.name + ".puppettmp",
|
221
|
+
File::CREAT | File::WRONLY | File::TRUNC]
|
222
|
+
|
223
|
+
# try to create it with the correct modes to start
|
224
|
+
# we should also be changing our effective uid/gid, but...
|
225
|
+
if @parent.should(:mode) and @parent.should(:mode) != :notfound
|
226
|
+
args.push @parent.should(:mode)
|
227
|
+
end
|
228
|
+
|
229
|
+
# FIXME we should also change our effective user and group id
|
230
|
+
|
231
|
+
begin
|
232
|
+
File.open(*args) { |f|
|
233
|
+
f.print contents
|
234
|
+
}
|
235
|
+
rescue => detail
|
236
|
+
# since they said they want a backup, let's error out
|
237
|
+
# if we couldn't make one
|
238
|
+
raise Puppet::Error, "Could not create %s to %s: %s" %
|
239
|
+
[@source, @parent.name, detail.message]
|
240
|
+
end
|
241
|
+
|
242
|
+
if FileTest.exists?(@parent.name)
|
243
|
+
begin
|
244
|
+
File.unlink(@parent.name)
|
245
|
+
rescue => detail
|
246
|
+
self.err "Could not remove %s for replacing: %s" %
|
247
|
+
[@parent.name, detail]
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
begin
|
252
|
+
File.rename(@parent.name + ".puppettmp", @parent.name)
|
253
|
+
rescue => detail
|
254
|
+
self.err "Could not rename tmp %s for replacing: %s" %
|
255
|
+
[@parent.name, detail]
|
256
|
+
end
|
257
|
+
|
258
|
+
return :file_changed
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
# $Id: source.rb 745 2005-11-16 22:17:29Z luke $
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Puppet
|
2
|
+
class State
|
3
|
+
class PFileType < Puppet::State
|
4
|
+
require 'etc'
|
5
|
+
@doc = "A read-only state to check the file type."
|
6
|
+
@name = :type
|
7
|
+
|
8
|
+
def shouldprocess(value)
|
9
|
+
raise Puppet::Error, ":type is read-only"
|
10
|
+
end
|
11
|
+
|
12
|
+
def retrieve
|
13
|
+
if stat = @parent.stat(true)
|
14
|
+
@is = stat.ftype
|
15
|
+
else
|
16
|
+
@is = :notfound
|
17
|
+
end
|
18
|
+
|
19
|
+
# so this state is never marked out of sync
|
20
|
+
@should = [@is]
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def sync
|
25
|
+
raise Puppet::Error, ":type is read-only"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# $Id: type.rb 713 2005-10-02 01:56:38Z luke $
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module Puppet
|
2
|
+
class State
|
3
|
+
class PFileUID < Puppet::State
|
4
|
+
require 'etc'
|
5
|
+
@doc = "To whom the file should belong. Argument can be user name or
|
6
|
+
user ID."
|
7
|
+
@name = :owner
|
8
|
+
@event = :inode_changed
|
9
|
+
|
10
|
+
def id2name(id)
|
11
|
+
if id.is_a?(Symbol)
|
12
|
+
return id.to_s
|
13
|
+
end
|
14
|
+
begin
|
15
|
+
user = Etc.getpwuid(id)
|
16
|
+
rescue TypeError
|
17
|
+
return nil
|
18
|
+
rescue ArgumentError
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
if user.uid == ""
|
22
|
+
return nil
|
23
|
+
else
|
24
|
+
return user.name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def name2id(value)
|
29
|
+
if value.is_a?(Symbol)
|
30
|
+
return value.to_s
|
31
|
+
end
|
32
|
+
begin
|
33
|
+
user = Etc.getpwnam(value)
|
34
|
+
if user.uid == ""
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
return user.uid
|
38
|
+
rescue ArgumentError => detail
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Determine if the user is valid, and if so, return the UID
|
44
|
+
def validuser?(value)
|
45
|
+
if value =~ /^\d+$/
|
46
|
+
value = value.to_i
|
47
|
+
end
|
48
|
+
|
49
|
+
if value.is_a?(Integer)
|
50
|
+
# verify the user is a valid user
|
51
|
+
if tmp = id2name(value)
|
52
|
+
return value
|
53
|
+
else
|
54
|
+
return false
|
55
|
+
end
|
56
|
+
else
|
57
|
+
if tmp = name2id(value)
|
58
|
+
return tmp
|
59
|
+
else
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# We want to print names, not numbers
|
66
|
+
def is_to_s
|
67
|
+
id2name(@is) || @is
|
68
|
+
end
|
69
|
+
|
70
|
+
def should_to_s
|
71
|
+
case self.should
|
72
|
+
when Symbol
|
73
|
+
self.should.to_s
|
74
|
+
when Integer
|
75
|
+
id2name(self.should) || self.should
|
76
|
+
when String
|
77
|
+
self.should
|
78
|
+
else
|
79
|
+
raise Puppet::DevError, "Invalid uid type %s(%s)" %
|
80
|
+
[self.should.class, self.should]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def retrieve
|
85
|
+
unless stat = @parent.stat(true)
|
86
|
+
@is = :notfound
|
87
|
+
return
|
88
|
+
end
|
89
|
+
|
90
|
+
self.is = stat.uid
|
91
|
+
|
92
|
+
# On OS X, files that are owned by -2 get returned as really
|
93
|
+
# large UIDs instead of negative ones. This isn't a Ruby bug,
|
94
|
+
# it's an OS X bug, since it shows up in perl, too.
|
95
|
+
if @is > 120000
|
96
|
+
self.warning "current state is silly: %s" % @is
|
97
|
+
@is = :notfound
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# If we're not root, we can check the values but we cannot change
|
102
|
+
# them. We can't really do any processing here, because users
|
103
|
+
# might not exist yet. FIXME There's still a bit of a problem here
|
104
|
+
# if the user's UID changes at run time, but we're just going to
|
105
|
+
# have to be okay with that for now, unfortunately.
|
106
|
+
def shouldprocess(value)
|
107
|
+
if tmp = self.validuser?(value)
|
108
|
+
return tmp
|
109
|
+
else
|
110
|
+
return value
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def sync
|
115
|
+
unless Process.uid == 0
|
116
|
+
unless defined? @@notifieduid
|
117
|
+
self.notice "Cannot manage ownership unless running as root"
|
118
|
+
#@parent.delete(self.name)
|
119
|
+
@@notifieduid = true
|
120
|
+
end
|
121
|
+
return nil
|
122
|
+
end
|
123
|
+
|
124
|
+
user = nil
|
125
|
+
unless user = self.validuser?(self.should)
|
126
|
+
tmp = self.should
|
127
|
+
unless defined? @@usermissing
|
128
|
+
@@usermissing = {}
|
129
|
+
end
|
130
|
+
|
131
|
+
if @@usermissing.include?(tmp)
|
132
|
+
@@usermissing[tmp] += 1
|
133
|
+
else
|
134
|
+
self.notice "user %s does not exist" % tmp
|
135
|
+
@@usermissing[tmp] = 1
|
136
|
+
return nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
if @is == :notfound
|
141
|
+
@parent.stat(true)
|
142
|
+
self.retrieve
|
143
|
+
if @is == :notfound
|
144
|
+
self.info "File does not exist; cannot set owner"
|
145
|
+
return nil
|
146
|
+
end
|
147
|
+
if self.insync?
|
148
|
+
return nil
|
149
|
+
end
|
150
|
+
#self.debug "%s: after refresh, is '%s'" % [self.class.name,@is]
|
151
|
+
end
|
152
|
+
|
153
|
+
begin
|
154
|
+
File.chown(user, nil, @parent[:path])
|
155
|
+
rescue => detail
|
156
|
+
raise Puppet::Error, "Failed to set owner to '%s': %s" %
|
157
|
+
[user, detail]
|
158
|
+
end
|
159
|
+
|
160
|
+
return :inode_changed
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# $Id: uid.rb 749 2005-11-22 05:33:42Z luke $
|