Module: Puppet::Util::ADSI

Defined in:
lib/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/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*")[0]
  end
  @computer_name
end

.computer_uri(host = '.') ⇒ Object



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

def computer_uri(host = '.')
  "WinNT://#{host}"
end

.connect(uri) ⇒ Object



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

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

.connectable?(uri) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
# File 'lib/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/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/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



69
70
71
# File 'lib/puppet/util/adsi.rb', line 69

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

.sid_for_account(name) ⇒ Object



73
74
75
76
77
# File 'lib/puppet/util/adsi.rb', line 73

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_sid instead."

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

.sid_uri(sid) ⇒ Object

Raises:



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

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

.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.



45
46
47
48
49
50
51
52
53
54
# File 'lib/puppet/util/adsi.rb', line 45

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 Win32::Security::SID::Error
    return nil
  end
end

.uri(resource_name, resource_type, host = '.') ⇒ Object



61
62
63
# File 'lib/puppet/util/adsi.rb', line 61

def uri(resource_name, resource_type, host = '.')
  "#{computer_uri(host)}/#{resource_name},#{resource_type}"
end

.wmi_connectionObject



65
66
67
# File 'lib/puppet/util/adsi.rb', line 65

def wmi_connection
  connect(wmi_resource_uri)
end

.wmi_resource_uri(host = '.') ⇒ Object



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

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