@@ -17,8 +17,8 @@ def initialize(options = {})
17
17
@domain_controller = options [ :domain_controller ]
18
18
@domain = options [ :realm ] . downcase
19
19
@ou = options [ :ou ]
20
- @computername_prefix = options [ :computername_prefix ]
21
- @computername_hash = options [ :computername_hash ]
20
+ @computername_prefix = options . fetch ( :computername_prefix , '' )
21
+ @computername_hash = options . fetch ( :computername_hash , @null )
22
22
@computername_use_fqdn = options [ :computername_use_fqdn ]
23
23
logger . info 'Proxy::AdRealm: initialize...'
24
24
end
@@ -76,7 +76,20 @@ def hostfqdn_to_computername(hostfqdn)
76
76
end
77
77
78
78
def apply_computername_prefix? ( computername )
79
- !computername_prefix . nil? && !computername_prefix . empty? && ( computername_hash || !computername [ 0 , computername_prefix . size ] . casecmp ( computername_prefix ) . zero? )
79
+ # Return false if computername is nil or empty
80
+ return false if computername . nil? || computername . empty?
81
+
82
+ # Return false if computername_prefix is nil or empty
83
+ return false if computername_prefix . nil? || computername_prefix . empty?
84
+
85
+ # Extract the prefix from computername with the same length as computername_prefix
86
+ extracted_prefix = computername [ 0 , computername_prefix . size ]
87
+
88
+ # Check if prefix is already in the beginning of computername string
89
+ prefix_matches = extracted_prefix . casecmp ( computername_prefix ) . zero?
90
+
91
+ # Return true if computername_hash is non empty or if the prefix does not match
92
+ computername_hash || !prefix_matches
80
93
end
81
94
82
95
def kinit_radcli_connect
0 commit comments