~ubuntu-branches/debian/sid/shorewall/sid

« back to all changes in this revision

Viewing changes to Perl/Shorewall/Accounting.pm

  • Committer: Package Import Robot
  • Author(s): Roberto C. Sanchez
  • Date: 2013-05-03 08:17:42 UTC
  • mfrom: (1.3.52)
  • Revision ID: package-import@ubuntu.com-20130503081742-qo8p6k2z0dnbfqo8
Tags: 4.5.16.1-1
* New Upstream Version
* debian/patches/01_debian_configuration.patch: Refreshed
* debian/patches/02_correct_dnat_snat_behavior.patch: Removed
* Update lintian overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#
4
4
#     This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
5
5
#
6
 
#     (c) 2007,2008,2009,2010,2011 - Tom Eastep (teastep@shorewall.net)
 
6
#     (c) 2007,2008,2009,2010,2011,2012,2013 - Tom Eastep (teastep@shorewall.net)
7
7
#
8
8
#       Complete documentation is available at http://shorewall.net
9
9
#
35
35
our @ISA = qw(Exporter);
36
36
our @EXPORT = qw( setup_accounting );
37
37
our @EXPORT_OK = qw( );
38
 
our $VERSION = '4.5_3';
 
38
our $VERSION = '4.5_16';
39
39
 
40
40
#
41
41
# Per-IP accounting tables. Each entry contains the associated network.
42
42
#
43
 
my %tables;
 
43
our %tables;
44
44
 
45
 
my $jumpchainref;
46
 
my %accountingjumps;
47
 
my $asection;
48
 
my $defaultchain;
49
 
my $ipsecdir;
50
 
my $defaultrestriction;
51
 
my $restriction;
52
 
my $accounting_commands = { COMMENT => 0, SECTION => 2 };
53
 
my $sectionname;
54
 
my $acctable;
 
45
our $jumpchainref;
 
46
our %accountingjumps;
 
47
our $asection;
 
48
our $defaultchain;
 
49
our $ipsecdir;
 
50
our $defaultrestriction;
 
51
our $restriction;
 
52
our $sectionname;
 
53
our $acctable;
55
54
 
56
55
#
57
56
# Sections in the Accounting File
139
138
    $asection = $newsect;
140
139
}
141
140
 
 
141
sub split_nfacct_list( $;$ ) {
 
142
    my ($list, $origlist ) = @_;
 
143
 
 
144
    fatal_error( "Invalid nfacct list (" . ( $origlist ? $origlist : $list ) . ')' ) if $list =~ /^,|,$|,,$/;
 
145
 
 
146
    split /,/, $list;
 
147
}
 
148
 
142
149
#
143
150
# Accounting
144
151
#
145
 
sub process_accounting_rule( ) {
 
152
sub process_accounting_rule1( $$$$$$$$$$$ ) {
 
153
 
 
154
    my ($action, $chain, $source, $dest, $proto, $ports, $sports, $user, $mark, $ipsec, $headers ) = @_;
146
155
 
147
156
    $acctable = $config{ACCOUNTING_TABLE};
148
157
 
149
158
    $jumpchainref = 0;
150
159
 
151
 
    my ($action, $chain, $source, $dest, $proto, $ports, $sports, $user, $mark, $ipsec, $headers ) =
152
 
        split_line1 'Accounting File', { action => 0, chain => 1, source => 2, dest => 3, proto => 4, dport => 5, sport => 6, user => 7, mark => 8, ipsec => 9, headers => 10 }, $accounting_commands;
153
 
 
154
 
    fatal_error 'ACTION must be specified' if $action eq '-';
155
 
 
156
 
    if ( $action eq 'COMMENT' ) {
157
 
        process_comment;
158
 
        return 0;
159
 
    }
160
 
 
161
 
    if ( $action eq 'SECTION' ) {
162
 
        process_section( $chain );
163
 
        return 0;
164
 
    }
165
 
 
166
160
    $asection = LEGACY if $asection < 0;
167
161
 
168
162
    our $disposition = '';
204
198
    fatal_error "USER/GROUP may only be specified in the OUTPUT section" unless $user eq '-' || $asection == OUTPUT;
205
199
 
206
200
    my $rule = do_proto( $proto, $ports, $sports ) . do_user ( $user ) . do_test ( $mark, $globals{TC_MASK} ) . do_headers( $headers );
 
201
    my $prerule = '';
207
202
    my $rule2 = 0;
208
203
    my $jump  = 0;
209
204
 
236
231
            }
237
232
        } elsif ( $action =~ /^NFLOG/ ) {
238
233
            $target = validate_level $action;
 
234
        } elsif ( $action =~ /^NFACCT\((.+)\)$/ ) {
 
235
            require_capability 'NFACCT_MATCH', 'The NFACCT action', 's';
 
236
            $target = '';
 
237
            for ( my @objects = split_nfacct_list $1 ) {
 
238
                validate_nfobject( $_, 1 );
 
239
                if ( s/!$// ) {
 
240
                    $prerule .= do_nfacct( $_ );
 
241
                } else {
 
242
                    $rule .= do_nfacct( $_ );
 
243
                }
 
244
            }
 
245
        } elsif ( $action eq 'INLINE' ) {
 
246
            $rule .= get_inline_matches;
239
247
        } else {
240
248
            ( $action, my $cmd ) = split /:/, $action;
241
249
 
276
284
                expand_rule(
277
285
                            ensure_rules_chain ( 'accountout' ) ,
278
286
                            OUTPUT_RESTRICT ,
 
287
                            $prerule ,
279
288
                            $rule ,
280
289
                            $source ,
281
290
                            $dest = ALLIP ,
369
378
    expand_rule
370
379
        $chainref ,
371
380
        $restriction ,
 
381
        $prerule ,
372
382
        $rule ,
373
383
        $source ,
374
384
        $dest ,
394
404
    }
395
405
 
396
406
    if ( $rule2 ) {
397
 
        expand_rule
398
 
            $jumpchainref ,
399
 
            $restriction ,
400
 
            $rule ,
401
 
            $source ,
402
 
            $dest ,
403
 
            '' ,
404
 
            '' ,
405
 
            '' ,
406
 
            '' ,
407
 
            '' ;
 
407
        expand_rule(
 
408
                    $jumpchainref ,
 
409
                    $restriction ,
 
410
                    $prerule ,
 
411
                    $rule ,
 
412
                    $source ,
 
413
                    $dest ,
 
414
                    '' ,
 
415
                    '' ,
 
416
                    '' ,
 
417
                    '' ,
 
418
                    '' );
408
419
    }
409
420
 
410
421
    return 1;
411
422
}
412
423
 
 
424
sub process_accounting_rule( ) {
 
425
 
 
426
    my ($action, $chain, $source, $dest, $protos, $ports, $sports, $user, $mark, $ipsec, $headers ) =
 
427
        split_line1 'Accounting File', { action => 0, chain => 1, source => 2, dest => 3, proto => 4, dport => 5, sport => 6, user => 7, mark => 8, ipsec => 9, headers => 10 };
 
428
 
 
429
    my $nonempty = 0;
 
430
 
 
431
    for my $proto ( split_list $protos, 'Protocol' ) {
 
432
        fatal_error 'ACTION must be specified' if $action eq '-';
 
433
 
 
434
        if ( $action eq 'SECTION' ) {
 
435
            process_section( $chain );
 
436
        } else {
 
437
            for my $proto ( split_list $protos, 'Protocol' ) {
 
438
                $nonempty |= process_accounting_rule1( $action, $chain, $source, $dest, $proto, $ports, $sports, $user, $mark, $ipsec, $headers );
 
439
            }
 
440
        }
 
441
    }
 
442
 
 
443
    $nonempty;
 
444
}
 
445
 
413
446
sub setup_accounting() {
414
447
 
415
 
    if ( my $fn = open_file 'accounting' ) {
 
448
    if ( my $fn = open_file 'accounting', 1, 1 ) {
416
449
 
417
450
        first_entry "$doing $fn...";
418
451
 
420
453
 
421
454
        $nonEmpty |= process_accounting_rule while read_a_line( NORMAL_READ );
422
455
 
423
 
        clear_comment;
424
 
 
425
456
        if ( $nonEmpty ) {
426
457
            my $tableref = $chain_table{$acctable};
427
458