Skip to content

Commit

Permalink
Fix #168 Default owner of 'root' fails on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Williams <[email protected]>
  • Loading branch information
sgtcoolguy committed Nov 18, 2016
1 parent e8fdfb1 commit 451cc72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions libraries/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def set_paths
new_resource.prefix_root = defaults.prefix_root
new_resource.home_dir = defaults.home_dir
new_resource.version = defaults.version
new_resource.owner = defaults.owner

# TODO: what happens when the path is already set --
# with the current logic we overwrite it
Expand Down
19 changes: 19 additions & 0 deletions libraries/resource_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def path
end
end

def owner
resource.owner || default_owner
end

def windows?
node_in_run_context['platform_family'] == 'windows'
end
Expand Down Expand Up @@ -89,6 +93,21 @@ def default_version
'1'
end

def default_owner
if windows?
wmi_property_from_query(:name, "select * from Win32_UserAccount where sid like 'S-1-5-21-%-500' and LocalAccount=True")
else
'root'
end
end

def wmi_property_from_query(wmi_property, wmi_query)
@wmi = ::WIN32OLE.connect('winmgmts://')
result = @wmi.ExecQuery(wmi_query)
return nil unless result.each.count > 0
result.each.next.send(wmi_property)
end

def file_cache_path
Chef::Config[:file_cache_path]
end
Expand Down
2 changes: 1 addition & 1 deletion resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
:release_file,
:version

attribute :owner, kind_of: String, default: 'root'
attribute :owner, kind_of: String, default: nil
attribute :group, kind_of: [String, Fixnum], default: 0
attribute :url, kind_of: String, required: true
attribute :path, kind_of: String, default: nil
Expand Down

0 comments on commit 451cc72

Please sign in to comment.