Class: Chef::ReservedNames::Win32::Security::ACL

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/chef/win32/security/acl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer, owner = nil) ⇒ ACL

Returns a new instance of ACL


29
30
31
32
33
34
# File 'lib/chef/win32/security/acl.rb', line 29

def initialize(pointer, owner = nil)
  @struct = Chef::ReservedNames::Win32::API::Security::ACLStruct.new pointer
  # Keep a reference to the actual owner of this memory so that it isn't freed out from under us
  # TODO this could be avoided if we could mark a pointer's parent manually
  @owner = owner
end

Instance Attribute Details

#structObject (readonly)

Returns the value of attribute struct


44
45
46
# File 'lib/chef/win32/security/acl.rb', line 44

def struct
  @struct
end

Class Method Details

.create(aces) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/chef/win32/security/acl.rb', line 36

def self.create(aces)
  aces_size = aces.inject(0) { |sum, ace| sum + ace.size }
  acl_size = align_dword(Chef::ReservedNames::Win32::API::Security::ACLStruct.size + aces_size) # What the heck is 94???
  acl = Chef::ReservedNames::Win32::Security.initialize_acl(acl_size)
  aces.each { |ace| Chef::ReservedNames::Win32::Security.add_ace(acl, ace) }
  acl
end

Instance Method Details

#==(other) ⇒ Object


46
47
48
49
50
51
52
# File 'lib/chef/win32/security/acl.rb', line 46

def ==(other)
  return false if length != other.length
  0.upto(length - 1) do |i|
    return false if self[i] != other[i]
  end
  true
end

#[](index) ⇒ Object


58
59
60
# File 'lib/chef/win32/security/acl.rb', line 58

def [](index)
  Chef::ReservedNames::Win32::Security.get_ace(self, index)
end

#delete_at(index) ⇒ Object


62
63
64
# File 'lib/chef/win32/security/acl.rb', line 62

def delete_at(index)
  Chef::ReservedNames::Win32::Security.delete_ace(self, index)
end

#eachObject


66
67
68
# File 'lib/chef/win32/security/acl.rb', line 66

def each
  0.upto(length - 1) { |i| yield self[i] }
end

#insert(index, *aces) ⇒ Object


70
71
72
# File 'lib/chef/win32/security/acl.rb', line 70

def insert(index, *aces)
  aces.reverse_each { |ace| add_ace(self, ace, index) }
end

#lengthObject


74
75
76
# File 'lib/chef/win32/security/acl.rb', line 74

def length
  struct[:AceCount]
end

#pointerObject


54
55
56
# File 'lib/chef/win32/security/acl.rb', line 54

def pointer
  struct.pointer
end

#push(*aces) ⇒ Object


78
79
80
# File 'lib/chef/win32/security/acl.rb', line 78

def push(*aces)
  aces.each { |ace| Chef::ReservedNames::Win32::Security.add_ace(self, ace) }
end

#to_sObject


90
91
92
# File 'lib/chef/win32/security/acl.rb', line 90

def to_s
  "[#{collect { |ace| ace.to_s }.join(", ")}]"
end

#unshift(*aces) ⇒ Object


82
83
84
# File 'lib/chef/win32/security/acl.rb', line 82

def unshift(*aces)
  aces.each { |ace| Chef::ReservedNames::Win32::Security.add_ace(self, ace, 0) }
end

#valid?Boolean

Returns:

  • (Boolean)

86
87
88
# File 'lib/chef/win32/security/acl.rb', line 86

def valid?
  Chef::ReservedNames::Win32::Security.is_valid_acl(self)
end