Class: LibACL::ACL

Inherits:
NiceFFI::OpaqueStruct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/libacl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default(dir) ⇒ Object



84
85
86
87
# File 'lib/libacl.rb', line 84

def self.default(dir)
  assert File.directory? dir
  self.from_file(dir,:default)
end

.from_file(path, mode = :access) ⇒ Object

Construct from file, using mode :access or :default



80
81
82
# File 'lib/libacl.rb', line 80

def self.from_file(path, mode=:access)
  LibACL::acl_get_file(path,mode)
end

.from_text(text) ⇒ Object

Construct from text



90
91
92
# File 'lib/libacl.rb', line 90

def self.from_text(text)
  LibACL::acl_from_text(text)
end

.init(num = 10) ⇒ Object

Create struct capable of holding num entries



71
72
73
# File 'lib/libacl.rb', line 71

def self.init(num=10)
  LibACL::acl_init(num)
end

.release(ptr) ⇒ Object



75
76
77
# File 'lib/libacl.rb', line 75

def self.release(ptr)
  acl_free(ptr)
end

Instance Method Details

#cloneObject

Create a copy of acl.



95
96
97
# File 'lib/libacl.rb', line 95

def clone
  LibACL::acl_dup(self)
end

#create_entryObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/libacl.rb', line 123

def create_entry
  entry_p = FFI::MemoryPointer.new :pointer
  #acl_p = self.pointer
  ret= LibACL::acl_create_entry(self, entry_p )
  raise "Can't create entry" if ret == -1

  
  #test this case...
#      #in case of reallocation
#      if acl_p.pointer.address != self.pointer.address
#        self.pointer=acl_p
#      end
  Entry.new entry_p.read_pointer
end

#delete_entry(entry) ⇒ Object

I’m unsure of how memory is handled in this case Test!



140
141
142
143
# File 'lib/libacl.rb', line 140

def delete_entry(entry)
  ret = LibACL::acl_delete_entry(self,entry)
  raise "Can't delete #{entry}" if ret == -1
end

#each(&blk) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/libacl.rb', line 146

def each(&blk)
  ptr = FFI::MemoryPointer.new :pointer
  having = LibACL::acl_get_entry(self, :first_entry, ptr)
  while (having>0)
    entry=Entry.new ptr.read_pointer
    blk.call entry
    having = LibACL::acl_get_entry(self, :next_entry, ptr)
  end
  
  raise "Error getting entry" if having == -1
end

#entry_find(tag) ⇒ Object



177
178
179
180
181
# File 'lib/libacl.rb', line 177

def entry_find(tag)
  find do |entry| 	
    entry.tag_type==tag
  end
end

#group_objObject



164
165
166
# File 'lib/libacl.rb', line 164

def group_obj
  entry_find :group_obj
end

#maskObject



172
173
174
# File 'lib/libacl.rb', line 172

def mask
  entry_find :mask
end

#otherObject



168
169
170
# File 'lib/libacl.rb', line 168

def other
  entry_find :other
end

#set_default(dir) ⇒ Object



116
117
118
119
120
# File 'lib/libacl.rb', line 116

def set_default(dir)
  assert valid?
  assert File.directory? dir
  set_file(dir, :default)
end

#set_file(path, mode = :access) ⇒ Object



109
110
111
112
113
# File 'lib/libacl.rb', line 109

def set_file(path, mode=:access)
  assert valid?
  assert File.exists? path
  LibACL::acl_set_file(path, mode, self)
end

#to_textObject



104
105
106
# File 'lib/libacl.rb', line 104

def to_text
  LibACL::acl_to_text(self, nil)
end

#user_objObject

methods using each implementation



160
161
162
# File 'lib/libacl.rb', line 160

def user_obj
  entry_find :user_obj
end

#valid?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/libacl.rb', line 99

def valid?
  LibACL::acl_valid(self)==0
end