Module: Puppet::Util::Windows::ADSI Private
- Extended by:
- FFI::Library
- Defined in:
- lib/puppet/util/windows.rb,
lib/puppet/util/windows/adsi.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: ADSIObject, Group, User, UserProfile
Constant Summary collapse
- STANDALONE_WORKSTATION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
docs.microsoft.com/en-us/windows/win32/api/dsrole/ne-dsrole-dsrole_machine_role
0
- MEMBER_WORKSTATION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1
- STANDALONE_SERVER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
2
- MEMBER_SERVER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
3
- BACKUP_DOMAIN_CONTROLLER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
4
- PRIMARY_DOMAIN_CONTROLLER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
5
- DOMAIN_ROLES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ STANDALONE_WORKSTATION => :STANDALONE_WORKSTATION, MEMBER_WORKSTATION => :MEMBER_WORKSTATION, STANDALONE_SERVER => :STANDALONE_SERVER, MEMBER_SERVER => :MEMBER_SERVER, BACKUP_DOMAIN_CONTROLLER => :BACKUP_DOMAIN_CONTROLLER, PRIMARY_DOMAIN_CONTROLLER => :PRIMARY_DOMAIN_CONTROLLER, }
- MAX_COMPUTERNAME_LENGTH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
taken from winbase.h
31
Class Method Summary collapse
- .computer_name ⇒ Object private
- .computer_uri(host = '.') ⇒ Object private
- .connect(uri) ⇒ Object private
- .connectable?(uri) ⇒ Boolean private
- .create(name, resource_type) ⇒ Object private
- .delete(name, resource_type) ⇒ Object private
- .domain_role ⇒ Object private
- .execquery(query) ⇒ Object private
-
.sid_uri(sid) ⇒ Object
private
This method should only be used to generate WinNT://<SID> style monikers used for IAdsGroup::Add / IAdsGroup::Remove.
-
.sid_uri_safe(sid) ⇒ Object
private
This method should only be used to generate WinNT://<SID> style monikers used for IAdsGroup::Add / IAdsGroup::Remove.
- .uri(resource_name, resource_type, host = '.') ⇒ Object private
- .wmi_connection ⇒ Object private
- .wmi_resource_uri(host = '.') ⇒ Object private
Class Method Details
.computer_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puppet/util/windows/adsi.rb', line 51 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 |
.computer_uri(host = '.') ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/puppet/util/windows/adsi.rb', line 68 def computer_uri(host = '.') "WinNT://#{host}" end |
.connect(uri) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 37 38 |
# File 'lib/puppet/util/windows/adsi.rb', line 32 def connect(uri) begin WIN32OLE.connect(uri) rescue WIN32OLERuntimeError => e raise Puppet::Error.new( _("ADSI connection error: %{e}") % { e: e }, e ) end end |
.connectable?(uri) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 27 28 29 30 |
# File 'lib/puppet/util/windows/adsi.rb', line 24 def connectable?(uri) begin !! connect(uri) rescue false end end |
.create(name, resource_type) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/puppet/util/windows/adsi.rb', line 40 def create(name, resource_type) Puppet::Util::Windows::ADSI.connect(computer_uri).Create(resource_type, name) end |
.delete(name, resource_type) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/puppet/util/windows/adsi.rb', line 44 def delete(name, resource_type) Puppet::Util::Windows::ADSI.connect(computer_uri).Delete(resource_type, name) end |
.domain_role ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 117 118 119 120 |
# File 'lib/puppet/util/windows/adsi.rb', line 114 def domain_role unless @domain_role query_result = Puppet::Util::Windows::ADSI.execquery('select DomainRole from Win32_ComputerSystem').to_enum.first @domain_role = DOMAIN_ROLES[query_result.DomainRole] if query_result end @domain_role end |
.execquery(query) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 |
# File 'lib/puppet/util/windows/adsi.rb', line 110 def execquery(query) wmi_connection.execquery(query) end |
.sid_uri(sid) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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
96 97 98 99 100 |
# File 'lib/puppet/util/windows/adsi.rb', line 96 def sid_uri(sid) raise Puppet::Error.new( _("Must use a valid SID::Principal") ) if !sid.kind_of?(Puppet::Util::Windows::SID::Principal) "WinNT://#{sid.sid}" end |
.sid_uri_safe(sid) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/util/windows/adsi.rb', line 82 def sid_uri_safe(sid) return sid_uri(sid) if sid.kind_of?(Puppet::Util::Windows::SID::Principal) begin sid = Puppet::Util::Windows::SID.name_to_principal(sid) sid_uri(sid) rescue Puppet::Util::Windows::Error, Puppet::Error nil end end |
.uri(resource_name, resource_type, host = '.') ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'lib/puppet/util/windows/adsi.rb', line 102 def uri(resource_name, resource_type, host = '.') "#{computer_uri(host)}/#{resource_name},#{resource_type}" end |
.wmi_connection ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 |
# File 'lib/puppet/util/windows/adsi.rb', line 106 def wmi_connection connect(wmi_resource_uri) end |
.wmi_resource_uri(host = '.') ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'lib/puppet/util/windows/adsi.rb', line 72 def wmi_resource_uri( host = '.' ) "winmgmts:{impersonationLevel=impersonate}!//#{host}/root/cimv2" end |