W3cubDocs

/Ruby 2.7

class ACL::ACLEntry

Parent:
Object

An entry in an ACL

Public Class Methods

new(str) Show source
# File lib/drb/acl.rb, line 56
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 IPAddr::InvalidPrefixError
      # In this case, `str` shouldn't be a host name pattern
      # because it contains a slash.
      raise
    rescue ArgumentError
      @pat = [:name, dot_pat(str)]
    end
  end
end

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.

IPAddr::InvalidPrefixError may be raised when an IP network address with an invalid netmask/prefix is given.

Public Instance Methods

match(addr) Show source
# File lib/drb/acl.rb, line 100
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

Matches addr against this entry.

Private Instance Methods

dot_pat(str) Show source
# File lib/drb/acl.rb, line 91
def dot_pat(str)
  /\A#{dot_pat_str(str)}\z/
end

Creates a Regexp to match an address.

dot_pat_str(str) Show source
# File lib/drb/acl.rb, line 79
def dot_pat_str(str)
  list = str.split('.').collect { |s|
    (s == '*') ? '.+' : s
  }
  list.join("\\.")
end

Creates a regular expression to match IPv4 addresses

Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.