| 1 | package Net::Connection::Match::Username; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Net::Connection::Match::Username - Runs a username check against a Net::Connection object. | ||||||||||
| 10 | |||||||||||
| 11 | =head1 VERSION | ||||||||||
| 12 | |||||||||||
| 13 | Version 0.0.0 | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | 2 | our $VERSION = '0.0.0'; | |||||||||
| 18 | |||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||
| 20 | |||||||||||
| 21 | use Net::Connection::Match::Username; | ||||||||||
| 22 | use Net::Connection; | ||||||||||
| 23 | |||||||||||
| 24 | my $connection_args={ | ||||||||||
| 25 | foreign_host=>'10.0.0.1', | ||||||||||
| 26 | foreign_port=>'22', | ||||||||||
| 27 | local_host=>'10.0.0.2', | ||||||||||
| 28 | local_port=>'12322', | ||||||||||
| 29 | proto=>'tcp4', | ||||||||||
| 30 | state=>'ESTABLISHED', | ||||||||||
| 31 | }; | ||||||||||
| 32 | |||||||||||
| 33 | my $conn=Net::Connection->new( $connection_args ); | ||||||||||
| 34 | |||||||||||
| 35 | my %args=( | ||||||||||
| 36 | usernames=>[ | ||||||||||
| 37 | 'root', | ||||||||||
| 38 | 'slapd', | ||||||||||
| 39 | ], | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | my $checker=Net::Connection::Match::Username->new( \%args ); | ||||||||||
| 43 | |||||||||||
| 44 | if ( $checker->match( $conn ) ){ | ||||||||||
| 45 | print "It matches.\n"; | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | =head1 METHODS | ||||||||||
| 49 | |||||||||||
| 50 | =head2 new | ||||||||||
| 51 | |||||||||||
| 52 | This intiates the object. | ||||||||||
| 53 | |||||||||||
| 54 | It takes a hash reference with one key. One key is required and | ||||||||||
| 55 | that is 'usernames', which is a array of usernames to match. | ||||||||||
| 56 | |||||||||||
| 57 | Atleast one protocol must be present. | ||||||||||
| 58 | |||||||||||
| 59 | If the new method fails, it dies. | ||||||||||
| 60 | |||||||||||
| 61 | my %args=( | ||||||||||
| 62 | usernames=>[ | ||||||||||
| 63 | 'root', | ||||||||||
| 64 | 'slapd', | ||||||||||
| 65 | ], | ||||||||||
| 66 | ); | ||||||||||
| 67 | |||||||||||
| 68 | my $checker=Net::Connection::Match::Username->new( \%args ); | ||||||||||
| 69 | |||||||||||
| 70 | =cut | ||||||||||
| 71 | |||||||||||
| 72 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||
| 73 | 2 | my %args; | |||||||||
| 74 | 2 | ▶ | if ( defined( $_[1] ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 1 | %args = %{ $_[1] }; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | # run some basic checks to make sure we have the minimum stuff required to work | ||||||||||
| 79 | 2 | ▶ | if ( !defined( $args{usernames} ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 1 | die('No usernames key specified in the argument hash'); | |||||||||
| 81 | } | ||||||||||
| 82 | 1 | ▶ | if ( ref( $args{usernames} ) ne 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | die('The usernames key is not a array'); | |||||||||
| 84 | } | ||||||||||
| 85 | 1 | ▶ | if ( !defined $args{usernames}[0] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | die('No states defined in the protos array'); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 1 | my $self = { usernames => $args{usernames}, }; | |||||||||
| 90 | 1 | bless $self; | |||||||||
| 91 | |||||||||||
| 92 | 1 | return $self; | |||||||||
| 93 | } ## end sub new | ||||||||||
| 94 | |||||||||||
| 95 | =head2 match | ||||||||||
| 96 | |||||||||||
| 97 | Checks if a single Net::Connection object matches the stack. | ||||||||||
| 98 | |||||||||||
| 99 | One argument is taken and that is a Net::Connection object. | ||||||||||
| 100 | |||||||||||
| 101 | The returned value is a boolean. | ||||||||||
| 102 | |||||||||||
| 103 | if ( $checker->match( $conn ) ){ | ||||||||||
| 104 | print "The connection matches.\n"; | ||||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | =cut | ||||||||||
| 108 | |||||||||||
| 109 | 4 | ▶ | sub match { | ||||||||
|
Subroutine
match: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||
| 110 | 4 | my $self = $_[0]; | |||||||||
| 111 | 4 | my $object = $_[1]; | |||||||||
| 112 | |||||||||||
| 113 | 4 | ▶ | if ( !defined($object) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 1 | return 0; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 3 | ▶ | if ( ref($object) ne 'Net::Connection' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 1 | return 0; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | # does not have a user.... we won't match | ||||||||||
| 122 | 2 | ▶ | if ( !defined( $object->username ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | return 0; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | # check for matches | ||||||||||
| 127 | 2 | foreach my $username ( @{ $self->{usernames} } ) { | |||||||||
| 128 | 3 | ▶ | if ( $username eq $object->username ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | 1 | return 1; | |||||||||
| 130 | } | ||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 1 | return 0; | |||||||||
| 134 | } ## end sub match | ||||||||||
| 135 | |||||||||||
| 136 | =head1 AUTHOR | ||||||||||
| 137 | |||||||||||
| 138 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||
| 139 | |||||||||||
| 140 | =head1 BUGS | ||||||||||
| 141 | |||||||||||
| 142 | Please report any bugs or feature requests to C<bug-net-connection-match at rt.cpan.org>, or through | ||||||||||
| 143 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Match>. I will be notified, and then you'll | ||||||||||
| 144 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 145 | |||||||||||
| 146 | |||||||||||
| 147 | |||||||||||
| 148 | |||||||||||
| 149 | =head1 SUPPORT | ||||||||||
| 150 | |||||||||||
| 151 | You can find documentation for this module with the perldoc command. | ||||||||||
| 152 | |||||||||||
| 153 | perldoc Net::Connection::Match | ||||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | You can also look for information at: | ||||||||||
| 157 | |||||||||||
| 158 | =over 4 | ||||||||||
| 159 | |||||||||||
| 160 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||
| 161 | |||||||||||
| 162 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Match> | ||||||||||
| 163 | |||||||||||
| 164 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 165 | |||||||||||
| 166 | L<http://annocpan.org/dist/Net-Connection-Match> | ||||||||||
| 167 | |||||||||||
| 168 | =item * CPAN Ratings | ||||||||||
| 169 | |||||||||||
| 170 | L<https://cpanratings.perl.org/d/Net-Connection-Match> | ||||||||||
| 171 | |||||||||||
| 172 | =item * Search CPAN | ||||||||||
| 173 | |||||||||||
| 174 | L<https://metacpan.org/release/Net-Connection-Match> | ||||||||||
| 175 | |||||||||||
| 176 | =back | ||||||||||
| 177 | |||||||||||
| 178 | |||||||||||
| 179 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 180 | |||||||||||
| 181 | |||||||||||
| 182 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 183 | |||||||||||
| 184 | Copyright 2019 Zane C. Bowers-Hadley. | ||||||||||
| 185 | |||||||||||
| 186 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 187 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||
| 188 | copy of the full license at: | ||||||||||
| 189 | |||||||||||
| 190 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||
| 191 | |||||||||||
| 192 | Any use, modification, and distribution of the Standard or Modified | ||||||||||
| 193 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||
| 194 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||
| 195 | or distribute the Package, if you do not accept this license. | ||||||||||
| 196 | |||||||||||
| 197 | If your Modified Version has been derived from a Modified Version made | ||||||||||
| 198 | by someone other than you, you are nevertheless required to ensure that | ||||||||||
| 199 | your Modified Version complies with the requirements of this license. | ||||||||||
| 200 | |||||||||||
| 201 | This license does not grant you the right to use any trademark, service | ||||||||||
| 202 | mark, tradename, or logo of the Copyright Holder. | ||||||||||
| 203 | |||||||||||
| 204 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||
| 205 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||
| 206 | otherwise transfer the Package with respect to any patent claims | ||||||||||
| 207 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||
| 208 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||
| 209 | counterclaim) against any party alleging that the Package constitutes | ||||||||||
| 210 | direct or contributory patent infringement, then this Artistic License | ||||||||||
| 211 | to you shall terminate on the date that such litigation is filed. | ||||||||||
| 212 | |||||||||||
| 213 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||
| 214 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||
| 215 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||
| 216 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||
| 217 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||
| 218 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||
| 219 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||
| 220 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||
| 221 | |||||||||||
| 222 | |||||||||||
| 223 | =cut | ||||||||||
| 224 | |||||||||||
| 225 | 2 | 1; # End of Net::Connection::Match | |||||||||