Module: Puppet::Util::ADSI

Defined in:
lib/vendor/puppet/util/adsi.rb

Defined Under Namespace

Classes: Group, User, UserProfile

Class Method Summary collapse

Class Method Details

.computer_nameObject



27
28
29
30
31
32
33
34
# File 'lib/vendor/puppet/util/adsi.rb', line 27

def computer_name
  unless @computer_name
    buf = " " * 128
    Win32API.new('kernel32', 'GetComputerName', ['P','P'], 'I').call(buf, buf.length.to_s)
    @computer_name = buf.unpack("A*")
  end
  @computer_name
end

.computer_uriObject



36
37
38
# File 'lib/vendor/puppet/util/adsi.rb', line 36

def computer_uri
  "WinNT://#{computer_name}"
end

.connect(uri) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/vendor/puppet/util/adsi.rb', line 11

def connect(uri)
  begin
    WIN32OLE.connect(uri)
  rescue Exception => e
    raise Puppet::Error.new( "ADSI connection error: #{e}" )
  end
end

.connectable?(uri) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
# File 'lib/vendor/puppet/util/adsi.rb', line 3

def connectable?(uri)
  begin
    !! connect(uri)
  rescue
    false
  end
end

.create(name, resource_type) ⇒ Object



19
20
21
# File 'lib/vendor/puppet/util/adsi.rb', line 19

def create(name, resource_type)
  Puppet::Util::ADSI.connect(computer_uri).Create(resource_type, name)
end

.delete(name, resource_type) ⇒ Object



23
24
25
# File 'lib/vendor/puppet/util/adsi.rb', line 23

def delete(name, resource_type)
  Puppet::Util::ADSI.connect(computer_uri).Delete(resource_type, name)
end

.execquery(query) ⇒ Object



52
53
54
# File 'lib/vendor/puppet/util/adsi.rb', line 52

def execquery(query)
  wmi_connection.execquery(query)
end

.sid_for_account(name) ⇒ Object



56
57
58
59
60
# File 'lib/vendor/puppet/util/adsi.rb', line 56

def (name)
  Puppet.deprecation_warning "Puppet::Util::ADSI.sid_for_account is deprecated and will be removed in 3.0, use Puppet::Util::Windows::SID.name_to_account instead."

  Puppet::Util::Windows::Security.name_to_sid(name)
end

.uri(resource_name, resource_type) ⇒ Object



44
45
46
# File 'lib/vendor/puppet/util/adsi.rb', line 44

def uri(resource_name, resource_type)
  "#{computer_uri}/#{resource_name},#{resource_type}"
end

.wmi_connectionObject



48
49
50
# File 'lib/vendor/puppet/util/adsi.rb', line 48

def wmi_connection
  connect(wmi_resource_uri)
end

.wmi_resource_uri(host = '.') ⇒ Object



40
41
42
# File 'lib/vendor/puppet/util/adsi.rb', line 40

def wmi_resource_uri( host = '.' )
  "winmgmts:{impersonationLevel=impersonate}!//#{host}/root/cimv2"
end