1 # acl-2.0 - simple Access Control List
3 # Copyright (c) 2000,2002,2003 Masatoshi SEKI
5 # acl.rb is copyrighted free software by Masatoshi SEKI.
6 # You can redistribute it and/or modify it under the same terms as Ruby.
14 if str == '*' or str == 'all'
16 elsif str.include?('*')
17 @pat = [:name, dot_pat(str)]
20 @pat = [:ip, IPAddr.new(str)]
22 @pat = [:name, dot_pat(str)]
29 list = str.split('.').collect { |s|
37 exp = "^" + dot_pat_str(str) + "$"
48 ipaddr = IPAddr.new(addr[3])
49 ipaddr = ipaddr.ipv4_mapped if @pat[1].ipv6? && ipaddr.ipv4?
53 (@pat[1].include?(ipaddr)) ? true : false
55 (@pat[1] =~ addr[2]) ? true : false
70 return true if e.match(addr)
77 @list.push(ACLEntry.new(str))
84 def initialize(list=nil, order = DENY_ALLOW)
88 install_list(list) if list
92 def allow_socket?(soc)
93 allow_addr?(soc.peeraddr)
100 return true if @allow.match(addr)
101 return false if @deny.match(addr)
104 return false if @deny.match(addr)
105 return true if @allow.match(addr)
113 def install_list(list)
116 permission, domain = list.slice(i,2)
117 case permission.downcase
123 raise "Invalid ACL entry #{list.to_s}"
134 allow ::ffff:192.168.1.2
138 addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
141 p acl.allow_addr?(addr)
143 acl = ACL.new(list, ACL::DENY_ALLOW)
144 p acl.allow_addr?(addr)