| 1 | package Parse::Log::Smbd; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use IO::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Devel::CheckOS qw/ os_is die_unsupported /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | ▶ | die_unsupported() if os_is('MicrosoftWindows'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Parse::Log::Smbd - parse log.smbd files to fetch usernames and connections to network shares | ||||||||||
| 14 | |||||||||||
| 15 | =head1 VERSION | ||||||||||
| 16 | |||||||||||
| 17 | Version 0.02 | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 3 | our $VERSION = '0.02'; | |||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||
| 25 | |||||||||||
| 26 | This module retrieves users successfully authenticated and connections to SMB/CIFS network shares from Samba C<log.smbd> files. | ||||||||||
| 27 | |||||||||||
| 28 | use Parse::Log::Smbd; | ||||||||||
| 29 | |||||||||||
| 30 | my $log = Parse::Log::Smbd->new( '/var/log/log.smbd' ); | ||||||||||
| 31 | |||||||||||
| 32 | my @users = $log->users; | ||||||||||
| 33 | my @shares = $log->shares; | ||||||||||
| 34 | |||||||||||
| 35 | =head1 SUBROUTINES/METHODS | ||||||||||
| 36 | |||||||||||
| 37 | =head2 new | ||||||||||
| 38 | |||||||||||
| 39 | Creates a new C<Parse::Log::Smbd> object, with the intended log filename as argument. | ||||||||||
| 40 | |||||||||||
| 41 | =cut | ||||||||||
| 42 | |||||||||||
| 43 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 44 | 1 | my ($class, $file) = @_; | |||||||||
| 45 | 1 | ▶ | croak "Log filename missing" unless defined $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | 1 | my $self = {}; | |||||||||
| 48 | |||||||||||
| 49 | 1 | my $fh = IO::File->new("< $file"); | |||||||||
| 50 | 1 | ▶ | croak "Can't read from $file: $!" unless $fh; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 1 | $self->{fh} = $fh; | |||||||||
| 53 | |||||||||||
| 54 | 1 | _parse_log($self); | |||||||||
| 55 | |||||||||||
| 56 | 1 | bless ($self, $class); | |||||||||
| 57 | 1 | return $self; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 1 | ▶ | sub _parse_log { | ||||||||
|
Subroutine
_parse_log: called CC=4 SCAR=13.9
| |||||||||||
| 61 | 1 | my $self = shift; | |||||||||
| 62 | 1 | my $fh = $self->{fh}; | |||||||||
| 63 | |||||||||||
| 64 | 1 | ▶ | while (<$fh>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 2123 | ▶ | if (/authentication for user \[(\w+)\].*?/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 153 | push @{ $self->{users} }, $1; | |||||||||
| 67 | } | ||||||||||
| 68 | 2123 | ▶ | if (/connect to service (\w+).*?/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 316 | push @{ $self->{shares} }, $1; | |||||||||
| 70 | } | ||||||||||
| 71 | } | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | =head2 users | ||||||||||
| 75 | |||||||||||
| 76 | Lists users that authenticated successfully to the smbd server. Returns a sorted list of unique usernames. | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||
| 79 | |||||||||||
| 80 | 1 | ▶ | sub users { | ||||||||
|
Subroutine
users: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 81 | 1 | my $self = shift; | |||||||||
| 82 | |||||||||||
| 83 | 1 | undef my %seen; | |||||||||
| 84 | 1 | return sort grep(!$seen{$_}++, @{ $self->{users} }); | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | =head2 shares | ||||||||||
| 88 | |||||||||||
| 89 | Lists successful connections to network shares. Returns a sorted list of unique shares. | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 1 | ▶ | sub shares { | ||||||||
|
Subroutine
shares: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 94 | 1 | my $self = shift; | |||||||||
| 95 | |||||||||||
| 96 | 1 | undef my %seen; | |||||||||
| 97 | 1 | return sort grep(!$seen{$_}++, @{ $self->{shares} }); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | =head1 AUTHOR | ||||||||||
| 101 | |||||||||||
| 102 | Ari Constancio, C<< <affc at cpan.org> >> | ||||||||||
| 103 | |||||||||||
| 104 | =head1 BUGS | ||||||||||
| 105 | |||||||||||
| 106 | Please report any bugs or feature requests to C<bug-parse-log-smbd at rt.cpan.org>, or through | ||||||||||
| 107 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Parse-Log-Smbd>. I will be notified, and then you'll | ||||||||||
| 108 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 109 | |||||||||||
| 110 | =head1 SUPPORT | ||||||||||
| 111 | |||||||||||
| 112 | You can find documentation for this module with the perldoc command. | ||||||||||
| 113 | |||||||||||
| 114 | perldoc Parse::Log::Smbd | ||||||||||
| 115 | |||||||||||
| 116 | |||||||||||
| 117 | You can also look for information at: | ||||||||||
| 118 | |||||||||||
| 119 | =over 4 | ||||||||||
| 120 | |||||||||||
| 121 | =item * RT: CPAN's request tracker | ||||||||||
| 122 | |||||||||||
| 123 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Parse-Log-Smbd> | ||||||||||
| 124 | |||||||||||
| 125 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 126 | |||||||||||
| 127 | L<http://annocpan.org/dist/Parse-Log-Smbd> | ||||||||||
| 128 | |||||||||||
| 129 | =item * CPAN Ratings | ||||||||||
| 130 | |||||||||||
| 131 | L<http://cpanratings.perl.org/d/Parse-Log-Smbd> | ||||||||||
| 132 | |||||||||||
| 133 | =item * Search CPAN | ||||||||||
| 134 | |||||||||||
| 135 | L<http://search.cpan.org/dist/Parse-Log-Smbd/> | ||||||||||
| 136 | |||||||||||
| 137 | =back | ||||||||||
| 138 | |||||||||||
| 139 | |||||||||||
| 140 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 141 | |||||||||||
| 142 | Thanks to the Samba Team (L<http://samba.org>) for a great software. | ||||||||||
| 143 | |||||||||||
| 144 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 145 | |||||||||||
| 146 | Copyright 2010 Ari Constancio. | ||||||||||
| 147 | |||||||||||
| 148 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 149 | under the terms of either: the GNU General Public License as published | ||||||||||
| 150 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 151 | |||||||||||
| 152 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 153 | |||||||||||
| 154 | =cut | ||||||||||
| 155 | |||||||||||
| 156 | 3 | 1; # End of Parse::Log::Smbd | |||||||||