taken from winbase.h
# File lib/puppet/util/windows/adsi.rb, line 34 def computer_name unless @computer_name max_length = MAX_COMPUTERNAME_LENGTH + 1 # NULL terminated FFI::MemoryPointer.new(max_length * 2) do |buffer| # wide string FFI::MemoryPointer.new(:dword, 1) do |buffer_size| buffer_size.write_dword(max_length) # length in TCHARs if GetComputerNameW(buffer, buffer_size) == FFI::WIN32_FALSE raise Puppet::Util::Windows::Error.new("Failed to get computer name") end @computer_name = buffer.read_wide_string(buffer_size.read_dword) end end end @computer_name end
# File lib/puppet/util/windows/adsi.rb, line 51 def computer_uri(host = '.') "WinNT://#{host}" end
# File lib/puppet/util/windows/adsi.rb, line 15 def connect(uri) begin WIN32OLE.connect(uri) rescue WIN32OLERuntimeError => e raise Puppet::Error.new( "ADSI connection error: #{e}", e ) end end
# File lib/puppet/util/windows/adsi.rb, line 7 def connectable?(uri) begin !! connect(uri) rescue false end end
# File lib/puppet/util/windows/adsi.rb, line 23 def create(name, resource_type) Puppet::Util::Windows::ADSI.connect(computer_uri).Create(resource_type, name) end
# File lib/puppet/util/windows/adsi.rb, line 27 def delete(name, resource_type) Puppet::Util::Windows::ADSI.connect(computer_uri).Delete(resource_type, name) end
# File lib/puppet/util/windows/adsi.rb, line 84 def execquery(query) wmi_connection.execquery(query) end
# File lib/puppet/util/windows/adsi.rb, line 88 def sid_for_account(name) Puppet.deprecation_warning "Puppet::Util::Windows::ADSI.sid_for_account is deprecated and will be removed in 3.0, use Puppet::Util::Windows::SID.name_to_sid instead." Puppet::Util::Windows::SID.name_to_sid(name) end
# File lib/puppet/util/windows/adsi.rb, line 71 def sid_uri(sid) raise Puppet::Error.new( "Must use a valid SID object" ) if !sid.kind_of?(Win32::Security::SID) "WinNT://#{sid.to_s}" end
@api private
# File lib/puppet/util/windows/adsi.rb, line 60 def sid_uri_safe(sid) return sid_uri(sid) if sid.kind_of?(Win32::Security::SID) begin sid = Win32::Security::SID.new(Win32::Security::SID.string_to_sid(sid)) sid_uri(sid) rescue SystemCallError nil end end
# File lib/puppet/util/windows/adsi.rb, line 76 def uri(resource_name, resource_type, host = '.') "#{computer_uri(host)}/#{resource_name},#{resource_type}" end
# File lib/puppet/util/windows/adsi.rb, line 80 def wmi_connection connect(wmi_resource_uri) end
# File lib/puppet/util/windows/adsi.rb, line 55 def wmi_resource_uri( host = '.' ) "winmgmts:{impersonationLevel=impersonate}!//#{host}/root/cimv2" end