module Puppet::Util::Windows::ADSI
Constants
- BACKUP_DOMAIN_CONTROLLER
- DOMAIN_ROLES
- MAX_COMPUTERNAME_LENGTH
taken from winbase.h
- MEMBER_SERVER
- MEMBER_WORKSTATION
- PRIMARY_DOMAIN_CONTROLLER
- STANDALONE_SERVER
- STANDALONE_WORKSTATION
docs.microsoft.com/en-us/windows/win32/api/dsrole/ne-dsrole-dsrole_machine_role
Public Class Methods
computer_name()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 52 def computer_name 53 unless @computer_name 54 max_length = MAX_COMPUTERNAME_LENGTH + 1 # NULL terminated 55 FFI::MemoryPointer.new(max_length * 2) do |buffer| # wide string 56 FFI::MemoryPointer.new(:dword, 1) do |buffer_size| 57 buffer_size.write_dword(max_length) # length in TCHARs 58 59 if GetComputerNameW(buffer, buffer_size) == FFI::WIN32_FALSE 60 raise Puppet::Util::Windows::Error.new(_("Failed to get computer name")) 61 end 62 @computer_name = buffer.read_wide_string(buffer_size.read_dword) 63 end 64 end 65 end 66 @computer_name 67 end
computer_uri(host = '.')
click to toggle source
# File lib/puppet/util/windows/adsi.rb 69 def computer_uri(host = '.') 70 "WinNT://#{host}" 71 end
connect(uri)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 33 def connect(uri) 34 begin 35 WIN32OLE.connect(uri) 36 rescue WIN32OLERuntimeError => e 37 raise Puppet::Error.new( _("ADSI connection error: %{e}") % { e: e }, e ) 38 end 39 end
connectable?(uri)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 25 def connectable?(uri) 26 begin 27 !! connect(uri) 28 rescue 29 false 30 end 31 end
create(name, resource_type)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 41 def create(name, resource_type) 42 Puppet::Util::Windows::ADSI.connect(computer_uri).Create(resource_type, name) 43 end
delete(name, resource_type)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 45 def delete(name, resource_type) 46 Puppet::Util::Windows::ADSI.connect(computer_uri).Delete(resource_type, name) 47 end
domain_role()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 115 def domain_role 116 unless @domain_role 117 query_result = Puppet::Util::Windows::ADSI.execquery('select DomainRole from Win32_ComputerSystem').to_enum.first 118 @domain_role = DOMAIN_ROLES[query_result.DomainRole] if query_result 119 end 120 @domain_role 121 end
execquery(query)
click to toggle source
# File lib/puppet/util/windows/adsi.rb 111 def execquery(query) 112 wmi_connection.execquery(query) 113 end
sid_uri(sid)
click to toggle source
This method should only be used to generate WinNT://<SID> style monikers used for IAdsGroup::Add / IAdsGroup::Remove. These URIs are not useable to resolve an account with WIN32OLE.connect
# File lib/puppet/util/windows/adsi.rb 97 def sid_uri(sid) 98 raise Puppet::Error.new( _("Must use a valid SID::Principal") ) if !sid.kind_of?(Puppet::Util::Windows::SID::Principal) 99 100 "WinNT://#{sid.sid}" 101 end
sid_uri_safe(sid)
click to toggle source
This method should only be used to generate WinNT://<SID> style monikers used for IAdsGroup::Add / IAdsGroup::Remove. These URIs are not usable to resolve an account with WIN32OLE.connect Valid input is a SID::Principal, S-X-X style SID string or any valid account name with or without domain prefix @api private
# File lib/puppet/util/windows/adsi.rb 83 def sid_uri_safe(sid) 84 return sid_uri(sid) if sid.kind_of?(Puppet::Util::Windows::SID::Principal) 85 86 begin 87 sid = Puppet::Util::Windows::SID.name_to_principal(sid) 88 sid_uri(sid) 89 rescue Puppet::Util::Windows::Error, Puppet::Error 90 nil 91 end 92 end
uri(resource_name, resource_type, host = '.')
click to toggle source
# File lib/puppet/util/windows/adsi.rb 103 def uri(resource_name, resource_type, host = '.') 104 "#{computer_uri(host)}/#{resource_name},#{resource_type}" 105 end
wmi_connection()
click to toggle source
# File lib/puppet/util/windows/adsi.rb 107 def wmi_connection 108 connect(wmi_resource_uri) 109 end
wmi_resource_uri( host = '.' )
click to toggle source
# File lib/puppet/util/windows/adsi.rb 73 def wmi_resource_uri( host = '.' ) 74 "winmgmts:{impersonationLevel=impersonate}!//#{host}/root/cimv2" 75 end