chef-boneyard / windows

Development repository for Chef Cookbook windows
https://supermarket.chef.io/cookbooks/windows
Apache License 2.0
252 stars 270 forks source link

windows_http_acl does not work on non-English Windows #379

Open maltewitt opened 8 years ago

maltewitt commented 8 years ago

Cookbook version

1.39.2

Chef-client version

12.9.38

Platform Details

Windows 7 Enterprise (German)

Scenario:

When trying to use the windows_http_acl resource, it fails while checking if the requested URL is already registered. This works fine, if I use an English Windows or an English language pack and switch language to English for the current user.

Steps to Reproduce:

Install some non-English language pack (i.e. German) and switch current users language settings to that language. Try running a recipe with windows_http_acl resource used.

windows_http_acl "http://+:#{node[:cp_suite_drop][:airport]}/" do
    user "Jeder"
end

Expected Result:

windows_http_acl should not fail, but successfully register the requested URL

Actual Result:

Generated at 2016-07-14 16:52:25 +0200 Mixlib::ShellOut::ShellCommandFailed: windows_http_acl[http://+:8086/](cp_suite_drop::zip line 60) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1' ---- Begin output of C:\Windows\system32\netsh.exe http add urlacl url=http://+:8086/ user="Jeder" ---- STDOUT: Die URL-Reservierung konnte nicht hinzugefgt werden. Fehler: 183

Eine Datei kann nicht erstellt werden, wenn sie bereits vorhanden ist. STDERR: ---- End output of C:\Windows\system32\netsh.exe http add urlacl url=http://+:8086/ user="Jeder" ----

maltewitt commented 8 years ago

I just looked into http_acl.rb and noticed that getCurrentAcl is parsing netsh output and looking for the string "User:". Using German Windows, this would be "Benutzer:"

def getCurrentAcl
  cmd = shell_out!("#{@command} http show urlacl url=#{@current_resource.url}")
  Chef::Log.debug "netsh reports: #{cmd.stdout}"

  m = cmd.stdout.scan(/User:\s*(.+)/)
  ...
mwrock commented 8 years ago

seems like we need to find another API to get this info in a language agnostic format

maltewitt commented 8 years ago

To get around this issue in my case I put the http_acl stuff into a new cookbook and wrote a library for getting current urlacl using Windows-API via FFI. Of course I would be willing to share that code, but I am not sure if windows cookbook wants to depend on ffi gem... Let me know if you are interested in my solution.

mwrock commented 8 years ago

chef core already depends and makes ample use of it. I for one would be very open to reviewing such a PR.

maltewitt commented 8 years ago

Best way to share would probably be creating a fork and moving my changes to that fork, followed by a pull request, right? (sorry for that github-beginner-question ;-) )

mwrock commented 8 years ago

No worries. Thats exactly right.