blib/lib/CGI/Untaint/hostname.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 47 CC 2 SCAR 10.6
CC
2
Cov
0%
is_ok
6.0
BEGIN
2.0
_untaint_re
2.0
CRAP 2.9
1  
2 package CGI::Untaint::hostname;
3 use strict;
4  
5 BEGIN {
6 use Exporter ();
7 use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
8 $VERSION = 0.1;
9 @ISA = qw (Exporter);
10 #Give a hoot don't pollute, do not export more than needed by default
11 @EXPORT = qw ();
12 @EXPORT_OK = qw ();
13 %EXPORT_TAGS = ();
14 }
15  
16  
17 ########################################### main pod documentation begin ##
18 # Below is the stub of documentation for your module. You better edit it!
19  
20  
21 =head1 NAME
22  
23 CGI::Untaint::hostname - untaint DNS host names
24  
25 =head1 SYNOPSIS
26  
27 use CGI::Untaint::hostname
28 my $handler = CGI::Untaint->new( $q->Vars() );
29 my $filename = $handler->extract( -as_hostname => 'some-host.some-domain.com' );
30  
31  
32 =head1 DESCRIPTION
33  
34 This module untaints and validates DNS host names. Validation means that the
35 name has the correct syntax specified in RFC 1035 section 3.5 (page 10), not
36 that it exists (after all you could use this in a web front-end to a dns zone
37 maintenance system) anywhere in any form.
38  
39 =head1 INSTALLATION
40  
41 to install the module...
42  
43 perl Build.PL
44 ./Build
45 ./Build test
46 ./Build install
47  
48  
49 =head1 BUGS
50  
51 None known.
52  
53 =head1 SUPPORT
54  
55 E-mail the author
56  
57 =head1 AUTHOR
58  
59 Dana Hudes
60 CPAN ID: DHUDES
61 dhudes@hudes.org
62 http://www.hudes.org
63  
64 =head1 COPYRIGHT
65  
66 This program is free software; you can redistribute
67 it and/or modify it under the same terms as Perl itself.
68  
69 The full text of the license can be found in the
70 LICENSE file included with this module.
71  
72  
73 =head1 SEE ALSO
74  
75 perl(1), CGI::Untaint, RFC 1035.
76  
77 =cut
78  
79 ############################################# main pod documentation end ##
80  
81 use base 'CGI::Untaint::object';
82  
83  
84 sub _untaint_re {
85 return qr/^([\p{IsAlnum}\-.]+)$/;
86 }
87  
88  
89 ################################################ subroutine header begin ##
90  
91 =head2 is_valid
92  
93 Usage : $self->is_valid
94 Purpose : Ensure that the hostname name is completely valid including length checking
95 Returns : true if the name is valid
96 Argument : the string to validate is in $self object
97 Throws : nothing
98 Comments :
99  
100 See Also : is_ok
101  
102 =cut
103  
104 ################################################## subroutine header end ##
105  
106 sub is_valid {
107 my $self = shift;
108 return is_ok ( $self->value);
109 }
110  
111 ################################################ subroutine header begin ##
112  
113 =head2 is_ok
114  
115 Usage : $self->is_ok($value)
116 Purpose : Perform syntax and length checking to validate the name
117 Returns : true if the name is valid
118 Argument : the string to validate
119 Throws : nothing of its own
120 Comments : RFC 1304 section 3.5 specificies the syntax and length limits on the names. Each section, separated by '.',
121 : must start with a letter, end with a letter or digit, and have as interior
122 : characters only letters, digits, and hyphen. The length of each section is 63 characters maximum.
123 : While it is customary to have a two or three letter "top-level domain" suffix, this is not
124 : required (cf ".arpa")
125 : N.B. while empirically it seems that registrars are registering names starting with digits, (e.g., 123.com) I find no
126 : basis for this in any RFC.
127 See Also : is_ok
128  
129 =cut
130  
131 ################################################## subroutine header end ##
132 sub is_ok {
133 my $value = shift;
134 my @parts = split/\./,$value;
135 my $label;
136 my $valid=1;
137 foreach $label (@parts)
138 {
139 $valid=0 unless (length $label <= 63) and ($label !~/^\-/);
140 }
141 return $valid;
142 }
143 1; #this line is important and will help the module return a true value
144 __END__