Class: ACL

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

Defined Under Namespace

Classes: ACLEntry, ACLList

Constant Summary collapse

VERSION =
["2.0.0"]
DENY_ALLOW =
0
ALLOW_DENY =
1

Instance Method Summary collapse

Constructor Details

#initialize(list = nil, order = DENY_ALLOW) ⇒ ACL

Returns a new instance of ACL.



84
85
86
87
88
89
# File 'lib/drb/acl.rb', line 84

def initialize(list=nil, order = DENY_ALLOW)
  @order = order
  @deny = ACLList.new
  @allow = ACLList.new
  install_list(list) if list
end

Instance Method Details

#allow_addr?(addr) ⇒ Boolean

Returns:

  • (Boolean)


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

def allow_addr?(addr)
  case @order
  when DENY_ALLOW
    return true if @allow.match(addr)
    return false if @deny.match(addr)
    return true
  when ALLOW_DENY
    return false if @deny.match(addr)
    return true if @allow.match(addr)
    return false
  else
    false
  end
end

#allow_socket?(soc) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/drb/acl.rb', line 92

def allow_socket?(soc)
  allow_addr?(soc.peeraddr)
end

#install_list(list) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/drb/acl.rb', line 113

def install_list(list)
  i = 0
  while i < list.size
    permission, domain = list.slice(i,2)
    case permission.downcase
    when 'allow'
	@allow.add(domain)
    when 'deny'
	@deny.add(domain)
    else
	raise "Invalid ACL entry #{list.to_s}"
    end
    i += 2
  end
end