Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarguru Nathan committed Nov 22, 2012
0 parents commit 5de0993
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Modules_required
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Net::LDAP
JSON::Parse
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An simple tool to set password policy for your deepOfix mail server. Modify config/setting.yaml to suit your needs.
69 changes: 69 additions & 0 deletions bin/password-policy.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env perl

use Net::LDAP;
use FindBin;
use JSON::Parse 'json_to_perl';

open my $qcontrol, '<', '/var/qmail/control/ldapbasedn';
my $base = <$qcontrol>;
close $qcontrol;
chomp($base);

print "Password plzz \n";
chomp($pass = <STDIN>);

my $cfg_loc = "$FindBin::Bin/../config/settings.json";
local $/;

open my $config_json, '<', $cfg_loc ;
my $json_txt = <$config_json>;
chomp($json_txt);
my $config = json_to_perl ($json_txt);
my $ldap = Net::LDAP->new("localhost", timeout=>10) or die "failed";
my $msg = $ldap->bind("uid=easypush,ou=People,$base", password=>"$pass");
my $base_search = $ldap->search( filter=>'(objectClass=qmailUser)', base=>"ou=people,$base") ;

my @base_entries = $base_search->entries;
my $exflag = 0;

foreach $base_entry (@base_entries) {
my $uidn = $base_entry->get_value(uid);
my $search = $ldap->search( filter=>"(uid=$uidn)", base=>"ou=people,$base");

my @entries = $search->entries;
foreach my $exuser (@{ $config->{excluded_users} }) {
$exflag = $exflag + 1 if($exuser eq $uidn );
}
#print "$exflag $uidn \n";
if ( ( $search->count != 1 ) || ($exflag != 0)) {
warn "entry not found or excluded user $uidn" ;
$exflag=0;
}

else {
my $dn = @entries[0]->dn;
my $dse = int (time/86400);
my $shadowMaxval = $config->{expiry_days};
my $shadowWarnval = $config->{warn_days};
my @reparray;
push @reparray, 'shadowMax', $shadowMaxval ;
push @reparray, 'shadowWarning', $shadowWarnval ;
push @reparray, 'shadowLastChange', $dse ;

if ( $#reparray > 0 ){
push @whatToChange, 'replace';
push @whatToChange, \@reparray;
}

else {
print "no changes folks";
}

my $result = $ldap->modify($dn,
changes => [
@whatToChange
]
);

}
}
8 changes: 8 additions & 0 deletions config/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"warn_days": "90",
"expiry_days": "100",
"excluded_users": [
"admin",
"test"
]
}

0 comments on commit 5de0993

Please sign in to comment.