summaryrefslogtreecommitdiff
path: root/fml/lib/FML/Command/Syntax.pm
blob: 97d2eb4c989ed47977ff8fc94912d44b96c861d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#-*- perl -*-
#
#  Copyright (C) 2004 Ken'ichi Fukamachi
#   All rights reserved. This program is free software; you can
#   redistribute it and/or modify it under the same terms as Perl itself.
#
# $FML: Syntax.pm,v 1.1 2004/04/28 04:10:35 fukachan Exp $
#

package FML::Command::Syntax;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;

=head1 NAME

FML::Command::Syntax - common command syntax checker.

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 METHODS

=head2 check_syntax_address_handler($curproc, $command_args)

verify the syntax command string.
return 0 if it looks insecure.

=cut


# Descriptions: verify the syntax command string.
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args)
# Side Effects: none
# Return Value: NUM(1 or 0)
sub check_syntax_address_handler
{
    my ($self, $curproc, $command_args) = @_;
    my $comname    = $command_args->{ comname }    || '';
    my $comsubname = $command_args->{ comsubname } || '';
    my $options    = $command_args->{ options }    || [];
    my (@test)     = ($comname);
    my $ok         = 0;

    # XXX Let original_command be "admin subscribe ADDRESS".
    # XXX options = [ 'subscribe', ADDRESS ] (not shifted yet here).
    my $command = $options->[ 0 ] || '';
    my $address = $options->[ 1 ] || '';
    push(@test, $command);

    # 1. check address syntax
    if ($address) {
	use FML::Restriction::Base;
	my $dispatch = new FML::Restriction::Base;
	if ($dispatch->regexp_match('address', $address)) {
	    $ok++;
	}
	else {
	    $curproc->logerror("insecure address: <$address>");
	}
    }

    # 2. check other comonents
    use FML::Command;
    my $dispatch = new FML::Command;
    if ($dispatch->safe_regexp_match($curproc, $command_args, \@test)) {
	$ok++;
    }
    else {
	$curproc->logerror("insecure syntax");
    }

    return( $ok == 2 ? 1 : 0 );
}


=head1 CODING STYLE

See C<http://www.fml.org/software/FNF/> on fml coding style guide.

=head1 AUTHOR

Ken'ichi Fukamachi

=head1 COPYRIGHT

Copyright (C) 2004 Ken'ichi Fukamachi

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=head1 HISTORY

FML::Command::Syntax appeared in fml8 mailing list driver package.
See C<http://www.fml.org/> for more details.

=cut


1;