class OodSupport::ACLs::PosixEntry
Object describing single Posix ACL
entry
Constants
Attributes
Is this a default ACL
entry @return [Boolean] whether default acl entry
Flag set on ACL
entry @return [Symbol] flag on acl entry
Permissions of ACL
entry @return [Array<Symbol>] permissions of acl entry
Public Class Methods
@param default [Boolean] whether default acl entry @param flag [#to_sym] flag for entry @param permissions [Array<#to_sym>] list of permissions for entry @see ACLEntry#initialize
OodSupport::ACLEntry::new
# File lib/ood_support/acls/posix.rb, line 174 def initialize(default: false, flag:, permissions:, **kwargs) @default = default @flag = flag.to_sym @permissions = permissions.map(&:to_sym) super(kwargs) end
Private Class Methods
Parse an entry string into input parameters
# File lib/ood_support/acls/posix.rb, line 261 def self.parse_entry(entry) e = REGEX_PATTERN.match(entry.to_s.strip) do |m| { default: m[:default] ? true : false, flag: m[:flag], principle: m[:principle], permissions: m[:permissions].chars } end e ? e : raise(InvalidACLEntry, "invalid entry: #{entry}") end
Public Instance Methods
Is this a default ACL
entry @return [Boolean] is this a default entry
# File lib/ood_support/acls/posix.rb, line 206 def default_entry? default end
Is this a group-specific ACL
entry @return [Boolean] is this a group entry
# File lib/ood_support/acls/posix.rb, line 218 def group_entry? !default_entry? && flag == :group end
Is this the owning group ACL
entry @return [Boolean] is this the owning group entry
# File lib/ood_support/acls/posix.rb, line 236 def group_owner_entry? group_entry? && principle.empty? end
Does this entry have the requested permission @param permission [#to_sym] the requested permission @param mask [PosixEntry] the permissions of the mask entry @return [Boolean] found this permission
# File lib/ood_support/acls/posix.rb, line 244 def has_permission?(permission:, mask:) if user_owner_entry? || other_entry? permissions.include? permission.to_sym else (mask ? permissions & mask.permissions : permissions).include? permission.to_sym end end
Do the requested args match this ACL
entry? @param principle [User, Group
, to_s
] requested principle @param owner [String] owner of corresponding ACL
@param group [String] owning group of corresponding ACL
@raise [ArgumentError] principle isn't {User} or {Group} object @return [Boolean] does this match this entry
# File lib/ood_support/acls/posix.rb, line 187 def match(principle:, owner:, group:) principle = User.new(principle) if (!principle.is_a?(User) && !principle.is_a?(Group)) return false if default_entry? p = self.principle p = owner if user_owner_entry? p = group if group_owner_entry? if (principle.is_a?(User) && group_entry?) principle.groups.include?(p) elsif (principle.is_a?(User) && user_entry?) || (principle.is_a?(Group) && group_entry?) principle == p elsif other_entry? true else false end end
Is this an other-specific ACL
entry @return [Boolean] is this an other entry
# File lib/ood_support/acls/posix.rb, line 224 def other_entry? !default_entry? && flag == :other end
Convert object to string @param w_perms [Boolean] whether display permissions @return [String] the string describing this object
# File lib/ood_support/acls/posix.rb, line 255 def to_s(w_perms: true) %[#{"default:" if default_entry?}#{flag}:#{principle}#{":#{permissions.join}" if w_perms}] end
Is this a user-specific ACL
entry @return [Boolean] is this a user entry
# File lib/ood_support/acls/posix.rb, line 212 def user_entry? !default_entry? && flag == :user end
Is this the owner ACL
entry @return [Boolean] is this the owner entry
# File lib/ood_support/acls/posix.rb, line 230 def user_owner_entry? user_entry? && principle.empty? end