summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/resource/windows_ad_join.rb16
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)