Class: ACL::ACLEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/drb/acl.rb

Overview

An entry in an ACL

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ ACLEntry

Creates a new entry using str.

str may be “*” or “all” to match any address, an IP address string to match a specific address, an IP address mask per IPAddr, or one containing “*” to match part of an IPv4 address.


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/drb/acl.rb', line 53

def initialize(str)
  if str == '*' or str == 'all'
    @pat = [:all]
  elsif str.include?('*')
    @pat = [:name, dot_pat(str)]
  else
    begin
      @pat = [:ip, IPAddr.new(str)]
    rescue ArgumentError
      @pat = [:name, dot_pat(str)]
    end
  end
end

Instance Method Details

#match(addr) ⇒ Object

Matches addr against this entry.


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/drb/acl.rb', line 94

def match(addr)
  case @pat[0]
  when :all
    true
  when :ip
    begin
      ipaddr = IPAddr.new(addr[3])
      ipaddr = ipaddr.ipv4_mapped if @pat[1].ipv6? && ipaddr.ipv4?
    rescue ArgumentError
      return false
    end
    (@pat[1].include?(ipaddr)) ? true : false
  when :name
    (@pat[1] =~ addr[2]) ? true : false
  else
    false
  end
end