diff options
author | srb3 <sbrown@chef.io> | 2020-02-14 14:22:55 +0000 |
---|---|---|
committer | srb3 <sbrown@chef.io> | 2020-02-14 14:22:55 +0000 |
commit | fcf10d7dcf772e876a7f712d4b4d8a1ceff2a2b1 (patch) | |
tree | 25f186d805db9b2a21dccec97e3e2c4f609aed51 | |
parent | 5a9f64b83e4605ee4d23190a3afcf08b000e3da1 (diff) | |
download | chef-fcf10d7dcf772e876a7f712d4b4d8a1ceff2a2b1.tar.gz |
Fix for domain_user from different domain, in windows_ad_join
Signed-off-by: srb3 <sbrown@chef.io>
-rw-r--r-- | lib/chef/resource/windows_ad_join.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/chef/resource/windows_ad_join.rb b/lib/chef/resource/windows_ad_join.rb index 4a72ab13cf..31a5e9c2b5 100644 --- a/lib/chef/resource/windows_ad_join.rb +++ b/lib/chef/resource/windows_ad_join.rb @@ -102,7 +102,7 @@ class Chef if joined_to_domain? cmd = "" cmd << "$pswd = ConvertTo-SecureString \'#{new_resource.domain_password}\' -AsPlainText -Force;" - cmd << "$credential = New-Object System.Management.Automation.PSCredential (\"#{new_resource.domain_user}@#{new_resource.domain_name}\",$pswd);" + cmd << "$credential = New-Object System.Management.Automation.PSCredential (\"#{sanitize_usename}\",$pswd);" cmd << "Remove-Computer" cmd << " -UnjoinDomainCredential $credential" cmd << " -NewName \"#{new_resource.new_hostname}\"" if new_resource.new_hostname @@ -169,6 +169,20 @@ class Chef node_domain == new_resource.domain_name.downcase end + # + # @return [String] the correct user and domain to use. + # if the domain_user property contains an @ symbol followed by any number of non white space characheters + # then we assume it is a user from another domain than the one specifed in the resource domain_name property. + # if this is the case we do not append the domain_name property to the domain_user property + # regex: https://rubular.com/r/VzupyBWemC8MMM + def sanitize_usename + if new_resource.domain_user =~ /^\S*@\S*$/ + new_resource.domain_user + else + "#{new_resource.domain_user}@#{new_resource.domain_name}" + end + end + # This resource historically took `:immediate` and `:delayed` as arguments to the reboot property but then # tried to shove that straight to the `reboot` resource which objected strenuously def clarify_reboot(reboot_action) |