my $audit_auth_log = '/var/log/samba/audit_auth.log';
my $audit_auth_log = '/var/log/samba/audit_auth.log';
@ -25,14 +28,31 @@ if (not defined $samba_tool or not defined $pdbedit){
GetOptions(
GetOptions(
'pretty' => \$pretty,
'pretty' => \$pretty,
'since=i' => \$since,
'since=i' => \$since,
'audit-auth-log=s' => \$audit_auth_log
'audit-auth-log=s' => \$audit_auth_log,
'general' => \$general,
'ou=s' => \$ou
);
);
if ($since !~ m/^\d+$/){
if ($since !~ m/^\d+$/){
die "Invalid value for since\n";
die "Invalid value for since\n";
}
}
my $json = {
my $json = {};
if (defined $ou){
$json = {
objects => 0
};
if ($ou !~ m/^(?<RDN>(?<Key>(?:\\[0-9A-Fa-f]{2}|\\\[^=\,\\]|[^=\,\\]+)+)\=(?<Value>(?:\\[0-9A-Fa-f]{2}|\\\[^=\,\\]|[^=\,\\]+)+))(?:\s*\,\s*(?<RDN>(?<Key>(?:\\[0-9A-Fa-f]{2}|\\\[^=\,\\]|[^=\,\\]+)+)\=(?<Value>(?:\\[0-9A-Fa-f]{2}|\\\[^=\,\\]|[^=\,\\]+)+)))*$/){
die "Invalid OU\n";
}
foreach (qx($samba_tool ou listobjects '$ou')){
die "Error while counting objects of OU $ou\n" if ($? != 0);
chomp;
$json->{objects}++;
}
} elsif ($general){
$json = {
accounts => {
accounts => {
users => 0,
users => 0,
inactive_users => 0,
inactive_users => 0,
@ -74,12 +94,12 @@ my $json = {
},
},
since => $since
since => $since
}
}
};
};
# Get the numbers of users. pdbedit is prefered here because we can
# Get the numbers of users. pdbedit is prefered here because we can
# differentiate active and inactive users, which samba-tool can't do
# differentiate active and inactive users, which samba-tool can't do
# While at it, also get the computers
# While at it, also get the computers
foreach (qx($pdbedit -L -v)){
foreach (qx($pdbedit -L -v)){
next unless (m/^Account Flags:\s+\[(.*)\]/);
next unless (m/^Account Flags:\s+\[(.*)\]/);
my $flags = $1;
my $flags = $1;
if ($flags =~ m/U/){
if ($flags =~ m/U/){
@ -92,38 +112,38 @@ foreach (qx($pdbedit -L -v)){
} elsif ($flags =~ m/W/){
} elsif ($flags =~ m/W/){
$json->{accounts}->{computers}++;
$json->{accounts}->{computers}++;
}
}
}
}
# Now count groups
# Now count groups
foreach (qx($samba_tool group list)){
foreach (qx($samba_tool group list)){
$json->{accounts}->{groups}++;
$json->{accounts}->{groups}++;
}
}
# Get replication status
# Get replication status
# We want just a quick summary, so only output the first line
# We want just a quick summary, so only output the first line
# manual checks will be needed to get the details, but if this field doesn't contains [ALL GOOD],
# manual checks will be needed to get the details, but if this field doesn't contains [ALL GOOD],