summaryrefslogtreecommitdiff
path: root/lib/chef/scan_access_control.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/scan_access_control.rb')
-rw-r--r--lib/chef/scan_access_control.rb97
1 files changed, 11 insertions, 86 deletions
diff --git a/lib/chef/scan_access_control.rb b/lib/chef/scan_access_control.rb
index 1384656a8b..95c82753a8 100644
--- a/lib/chef/scan_access_control.rb
+++ b/lib/chef/scan_access_control.rb
@@ -1,6 +1,6 @@
-#--
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2012 Opscode, Inc.
+#
+# Author:: Tyler Cloke (<tyler@opscode.com>)
+# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,8 +34,14 @@ class Chef
# progress towards the end goal.
#
# TODO: figure out if all this works with OS X's negative uids
- # TODO: windows
class ScanAccessControl
+ if Chef::Platform.windows?
+ require 'chef/scan_access_control/windows.rb'
+ include ScanAccessControl::Windows
+ else
+ require 'chef/scan_access_control/unix.rb'
+ include ScanAccessControl::Unix
+ end
attr_reader :new_resource
attr_reader :current_resource
@@ -44,90 +50,9 @@ class Chef
@new_resource, @current_resource = new_resource, current_resource
end
- # Modifies @current_resource, setting the current access control state.
+ # must be overrode by children unix.rb and windows.rb
def set_all!
- if ::File.exist?(new_resource.path)
- set_owner
- set_group
- set_mode
- else
- # leave the values as nil.
- end
- end
-
- # Set the owner attribute of +current_resource+ to whatever the current
- # state is. Attempts to match the format given in new_resource: if the
- # new_resource specifies the owner as a string, the username for the uid
- # will be looked up and owner will be set to the username, and vice versa.
- def set_owner
- @current_resource.owner(current_owner)
- end
-
- def current_owner
- case new_resource.owner
- when String, nil
- lookup_uid
- when Integer
- stat.uid
- else
- Chef::Log.error("The `owner` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})")
- raise ArgumentError, "cannot resolve #{new_resource.owner.inspect} to uid, owner must be a string or integer"
- end
- end
-
- def lookup_uid
- unless (pwent = Etc.getpwuid(stat.uid)).nil?
- pwent.name
- else
- stat.uid
- end
- rescue ArgumentError
- stat.uid
- end
-
- # Set the group attribute of +current_resource+ to whatever the current state is.
- def set_group
- @current_resource.group(current_group)
end
- def current_group
- case new_resource.group
- when String, nil
- lookup_gid
- when Integer
- stat.gid
- else
- Chef::Log.error("The `group` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})")
- raise ArgumentError, "cannot resolve #{new_resource.group.inspect} to gid, group must be a string or integer"
- end
- end
-
- def lookup_gid
- unless (pwent = Etc.getgrgid(stat.gid)).nil?
- pwent.name
- else
- stat.gid
- end
- rescue ArgumentError
- stat.gid
- end
-
- def set_mode
- @current_resource.mode(current_mode)
- end
-
- def current_mode
- case new_resource.mode
- when String, Integer, nil
- "0#{(stat.mode & 07777).to_s(8)}"
- else
- Chef::Log.error("The `mode` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.mode.inspect})")
- raise ArgumentError, "Invalid value #{new_resource.mode.inspect} for `mode` on resource #@new_resource"
- end
- end
-
- def stat
- @stat ||= @new_resource.instance_of?(Chef::Resource::Link) ? ::File.lstat(@new_resource.path) : ::File.stat(@new_resource.path)
- end
end
end