| 1 | # Copyright (c) 2003 Ioannis Tambouras <ioannis@earthlink.net> . | ||||||||||
| 2 | # All rights reserved. | ||||||||||
| 3 | |||||||||||
| 4 | package Authen::Tcpdmatch::Grammar; | ||||||||||
| 5 | |||||||||||
| 6 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 11 | ▶ | use Attribute::Handlers; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 11 | ▶ | use Parse::RecDescent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 11 | our $VERSION='0.01'; | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 11 | $Parse::RecDescent::skip = '[, \t]*' ; | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | 11 | our $grammar = q( | |||||||||
| 19 | { use NetAddr::IP; no strict 'refs'} | ||||||||||
| 20 | { our ( $found, $e, $side, $remote, $service, $OK_remote, $OK_service) } | ||||||||||
| 21 | { sub found { $OK_service && $OK_remote or undef }} | ||||||||||
| 22 | { sub init { ($service, $remote)=@_; @_= $OK_remote = $OK_service = $found = undef}} | ||||||||||
| 23 | { sub register { ${"OK_$side"} = !$e} } | ||||||||||
| 24 | { sub tally { register if $_[0] eq ${"$side"} }} | ||||||||||
| 25 | { sub dot_host { (my $ip = $_[0]) =~ s!\.!\\\.!g; register if $remote =~ /$ip$/ }} | ||||||||||
| 26 | { sub ip_dot { (my $ip = $_[0]) =~ s!\.!\\\.!g; register if $remote =~ /^$ip/ }} | ||||||||||
| 27 | { sub ALL { register }} | ||||||||||
| 28 | { sub LOCAL { register if $remote !~ /\./ }} | ||||||||||
| 29 | { sub maskit { my $r = new NetAddr::IP $remote or return; | ||||||||||
| 30 | register if (NetAddr::IP->new(shift)||return) ->contains($r) }} | ||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | Start : { init $arg[0], $arg[1] ; 'true'} | ||||||||||
| 35 | Line(s) /\Z/ | ||||||||||
| 36 | {$return = $found} | ||||||||||
| 37 | Start: {$return = $found} | ||||||||||
| 38 | |||||||||||
| 39 | Line: { $OK_remote = $OK_service = undef } | ||||||||||
| 40 | Line: { $side = 'service', $e=0 } List[''] ':' | ||||||||||
| 41 | { $side = 'remote' , $e=0 } List[''] EOL(?) | ||||||||||
| 42 | { found and $found = 1 } | ||||||||||
| 43 | <reject: $found> | ||||||||||
| 44 | Line: Comment | ||||||||||
| 45 | Line: <resync> | ||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | List : <leftop: Member[$arg[0]](s) 'EXCEPT' List[ $e^=1 ] > | ||||||||||
| 49 | List : Member[ $arg[0] ](s) | ||||||||||
| 50 | |||||||||||
| 51 | Member : Wildcard[ $arg[0] ] | ||||||||||
| 52 | Member : Pattern[ $arg[0] ] | ||||||||||
| 53 | Member : Netmask[ $arg[0] ] | ||||||||||
| 54 | Member : ...!/EXCEPT/i /[A-Za-z]\w*/ | ||||||||||
| 55 | { tally $item[2], $arg[0] ; 'true' } | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | Wildcard: / \b (ALL | LOCAL) \b /x | ||||||||||
| 59 | { &{"$item[1]"}( $arg[0] ) ; 'true'} | ||||||||||
| 60 | Pattern: ...!/\w/ m!\.\S+! | ||||||||||
| 61 | { dot_host $item[-1] ; 'true'} | ||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | Pattern: m!\S+\.! ...!/[\w]/ | ||||||||||
| 65 | { ip_dot $item[1] ; 'true'} | ||||||||||
| 66 | |||||||||||
| 67 | Netmask: {} <rulevar: $octet = qr/\d{1,3}/ > | ||||||||||
| 68 | <rulevar: $o3 = qr/(?:\.$octet){1,3}/ > | ||||||||||
| 69 | Netmask: m! \b $octet $o3 (?: /$octet(?:$o3)? )? \b !xo | ||||||||||
| 70 | { maskit $item[1] , $arg[0] ; 'true'} | ||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | EOL : /[\n]/ | ||||||||||
| 74 | Comment: /#.*\n/ | ||||||||||
| 75 | ); | ||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | 11 | ▶ | sub TcpdParser : ATTR { ${$_[2]} = new Parse::RecDescent( $grammar ) or die } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
TcpdParser: called CC=2 SCAR=7.0
Pod
undocumented
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | 11 | 1; | |||||||||
| 82 | __END__ | ||||||||||