class Puppet::Util::Windows::ADSI::ADSIObject
Common base class shared by the User
and Group
classes below.
Attributes
object_class[R]
Is either 'user' or 'group'
name[R]
Public Class Methods
delete(name)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 196 def delete(name) 197 Puppet::Util::Windows::ADSI.delete(name, @object_class) 198 end
each(&block)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 233 def each(&block) 234 objects = [] 235 list_all.each do |o| 236 # Setting WIN32OLE.codepage in the microsoft_windows feature ensures 237 # values are returned as UTF-8 238 objects << new(o.name) 239 end 240 241 objects.each(&block) 242 end
exists?(name_or_sid)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 200 def exists?(name_or_sid) 201 well_known = false 202 if (sid = Puppet::Util::Windows::SID.name_to_principal(name_or_sid)) 203 # Examples of SidType include SidTypeUser, SidTypeGroup 204 if sid.account_type == "SidType#{@object_class.capitalize}".to_sym 205 # Check if we're getting back a local user when domain-joined 206 return true unless [:MEMBER_WORKSTATION, :MEMBER_SERVER].include?(Puppet::Util::Windows::ADSI.domain_role) 207 # The resource domain and the computer name are not always case-matching 208 return sid.domain.casecmp(Puppet::Util::Windows::ADSI.computer_name) == 0 209 end 210 211 # 'well known group' is special as it can be a group like Everyone OR a user like SYSTEM 212 # so try to resolve it 213 # https://msdn.microsoft.com/en-us/library/cc234477.aspx 214 well_known = sid.account_type == :SidTypeWellKnownGroup 215 return false if sid.account_type != :SidTypeAlias && !well_known 216 name_or_sid = "#{sid.domain}\\#{sid.account}" 217 end 218 219 object = Puppet::Util::Windows::ADSI.connect(uri(*parse_name(name_or_sid))) 220 object.Class.downcase == @object_class 221 rescue 222 # special accounts like SYSTEM or special groups like Authenticated Users cannot 223 # resolve via monikers like WinNT://./SYSTEM,user or WinNT://./Authenticated Users,group 224 # -- they'll fail to connect. thus, given a validly resolved SID, this failure is 225 # ambiguous as it may indicate either a group like Service or an account like SYSTEM 226 well_known 227 end
get_sids(adsi_child_collection)
click to toggle source
returns Puppet::Util::Windows::SID::Principal[] may contain objects that represent unresolvable SIDs
# File lib/puppet/util/windows/adsi.rb 174 def get_sids(adsi_child_collection) 175 sids = [] 176 adsi_child_collection.each do |m| 177 sids << Puppet::Util::Windows::SID.ads_to_principal(m) 178 end 179 180 sids 181 end
list_all()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 229 def list_all 230 raise NotImplementedError, _("Subclass must implement class-level method 'list_all'!") 231 end
localized_domains()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 144 def localized_domains 145 @localized_domains ||= [ 146 # localized version of BUILTIN 147 # for instance VORDEFINIERT on German Windows 148 Puppet::Util::Windows::SID.sid_to_name('S-1-5-32').upcase, 149 # localized version of NT AUTHORITY (can't use S-1-5) 150 # for instance AUTORITE NT on French Windows 151 Puppet::Util::Windows::SID.name_to_principal('SYSTEM').domain.upcase 152 ] 153 end
name_sid_hash(names, allow_unresolved = false)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 183 def name_sid_hash(names, allow_unresolved = false) 184 return {} if names.nil? || names.empty? 185 186 sids = names.map do |name| 187 sid = Puppet::Util::Windows::SID.name_to_principal(name, allow_unresolved) 188 raise Puppet::Error.new( _("Could not resolve name: %{name}") % { name: name } ) if !sid 189 [sid.sid, sid] 190 end 191 192 Hash[ sids ] 193 end
new(name, native_object = nil)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 246 def initialize(name, native_object = nil) 247 @name = name 248 @native_object = native_object 249 end
parse_name(name)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 160 def parse_name(name) 161 if name =~ /\// 162 raise Puppet::Error.new( _("Value must be in DOMAIN\\%{object_class} style syntax") % { object_class: @object_class } ) 163 end 164 165 matches = name.scan(/((.*)\\)?(.*)/) 166 domain = matches[0][1] || '.' 167 account = matches[0][2] 168 169 return account, domain 170 end
uri(name, host = '.')
click to toggle source
# File lib/puppet/util/windows/adsi.rb 155 def uri(name, host = '.') 156 host = '.' if (localized_domains << Socket.gethostname.upcase).include?(host.upcase) 157 Puppet::Util::Windows::ADSI.uri(name, @object_class, host) 158 end
Public Instance Methods
[](attribute)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 267 def [](attribute) 268 # Setting WIN32OLE.codepage ensures values are returned as UTF-8 269 native_object.Get(attribute) 270 end
[]=(attribute, value)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 272 def []=(attribute, value) 273 native_object.Put(attribute, value) 274 end
commit()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 276 def commit 277 begin 278 native_object.SetInfo 279 rescue WIN32OLERuntimeError => e 280 # ERROR_BAD_USERNAME 2202L from winerror.h 281 if e.message =~ /8007089A/m 282 raise Puppet::Error.new( 283 _("Puppet is not able to create/delete domain %{object_class} objects with the %{object_class} resource.") % { object_class: object_class }, 284 ) 285 end 286 287 raise Puppet::Error.new( _("%{object_class} update failed: %{error}") % { object_class: object_class.capitalize, error: e }, e ) 288 end 289 self 290 end
native_object()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 259 def native_object 260 @native_object ||= Puppet::Util::Windows::ADSI.connect(self.class.uri(*self.class.parse_name(name))) 261 end
object_class()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 251 def object_class 252 self.class.object_class 253 end
sid()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 263 def sid 264 @sid ||= Puppet::Util::Windows::SID.octet_string_to_principal(native_object.objectSID) 265 end
uri()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 255 def uri 256 self.class.uri(sid.account, sid.domain) 257 end