summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-04 20:43:50 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-04 20:43:50 +0000
commit2195b7637d52877aedf5b8e1d58b001d4a51dbd2 (patch)
treedd2be7dabea3f53fa6a3af433922dd4b3bf1141b /lib
parent8fd976515e52effb4d99feebc3a9c58684ea9df8 (diff)
downloadpuppet-2195b7637d52877aedf5b8e1d58b001d4a51dbd2.tar.gz
puppet-2195b7637d52877aedf5b8e1d58b001d4a51dbd2.tar.xz
puppet-2195b7637d52877aedf5b8e1d58b001d4a51dbd2.zip
Trying to fix #364. Somewhat used the patch provided by nslm.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2040 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/type/pfile.rb19
-rwxr-xr-xlib/puppet/type/pfile/ensure.rb4
2 files changed, 20 insertions, 3 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 0e5954add..5d8a3a63e 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -1002,7 +1002,7 @@ module Puppet
end
# As the correct user and group
- Puppet::SUIDManager.asuser(asuser(), self.should(:group)) do
+ write_if_writable(File.dirname(path)) do
f = nil
# Open our file with the correct modes
if mode
@@ -1040,6 +1040,23 @@ module Puppet
# FIXME This is extra work, because it's going to read the whole
# file back in again.
self.setchecksum
+
+ end
+
+ # Run the block as the specified user if the dir is writeable, else
+ # run it as root (or the current user).
+ def write_if_writable(dir)
+ asroot = true
+ Puppet::SUIDManager.asuser(asuser(), self.should(:group)) do
+ if FileTest.writable?(dir)
+ asroot = false
+ yield
+ end
+ end
+
+ if asroot
+ yield
+ end
end
end # Puppet.type(:pfile)
diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb
index 9e1eec86d..6f8c335b1 100755
--- a/lib/puppet/type/pfile/ensure.rb
+++ b/lib/puppet/type/pfile/ensure.rb
@@ -67,7 +67,7 @@ module Puppet
"Cannot create %s; parent directory %s does not exist" %
[@parent[:path], parent]
end
- Puppet::SUIDManager.asuser(@parent.asuser()) {
+ @parent.write_if_writable(parent) do
if mode
Puppet::Util.withumask(000) do
Dir.mkdir(@parent[:path],mode)
@@ -75,7 +75,7 @@ module Puppet
else
Dir.mkdir(@parent[:path])
end
- }
+ end
@parent.setchecksum
return :directory_created
end