|
|
|
@ -29,9 +29,9 @@ my @servers = split (/\s+/, $PAR{'uri'});
|
|
|
|
|
my $active_server = 0;
|
|
|
|
|
|
|
|
|
|
my $ldap;
|
|
|
|
|
while ((my $serwer = shift @servers) && !($active_server)){
|
|
|
|
|
while ((my $serwer = shift @servers) && !($active_server)) {
|
|
|
|
|
my $ldap_uri = URI->new($serwer);
|
|
|
|
|
if ($ldap_uri->secure){
|
|
|
|
|
if ($ldap_uri->secure) {
|
|
|
|
|
$ldap = Net::LDAP->new($ldap_uri->as_string,
|
|
|
|
|
version => 3,
|
|
|
|
|
verify => 'require',
|
|
|
|
@ -43,34 +43,33 @@ while ((my $serwer = shift @servers) && !($active_server)){
|
|
|
|
|
$active_server = 1 if ($ldap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($active_server){
|
|
|
|
|
my $mesg = $ldap->bind( $PAR{'binddn'}, password => $PAR{'bindpw'} );
|
|
|
|
|
if ($mesg->code != 0){
|
|
|
|
|
if ($active_server) {
|
|
|
|
|
my $mesg = $ldap->bind($PAR{'binddn'}, password => $PAR{'bindpw'});
|
|
|
|
|
if ($mesg->code != 0) {
|
|
|
|
|
print "Cannot login: ". $mesg->error;
|
|
|
|
|
} else {
|
|
|
|
|
# Wyszukanie usera wg filtra
|
|
|
|
|
$PAR{'filter'} =~ s/\%login/$PAR{'user'}/;
|
|
|
|
|
my @search_args = (base => $PAR{'base'},
|
|
|
|
|
my @search_args = (
|
|
|
|
|
base => $PAR{'base'},
|
|
|
|
|
scope => 'sub',
|
|
|
|
|
filter => $PAR{'filter'},
|
|
|
|
|
attrs => ['1.1'],
|
|
|
|
|
);
|
|
|
|
|
my $result = $ldap->search( @search_args );
|
|
|
|
|
if ($result->code){
|
|
|
|
|
my $result = $ldap->search(@search_args);
|
|
|
|
|
if ($result->code) {
|
|
|
|
|
print $result->error;
|
|
|
|
|
} else {
|
|
|
|
|
my $count = $result->count;
|
|
|
|
|
if ($count == 1){
|
|
|
|
|
if ($count == 1) {
|
|
|
|
|
my @users = $result->entries;
|
|
|
|
|
my $dn = $users[0]->dn();
|
|
|
|
|
$result = $ldap->bind($dn, password => $PAR{'pass'});
|
|
|
|
|
if ($result->code){
|
|
|
|
|
print $result->error;
|
|
|
|
|
} else {
|
|
|
|
|
$result = $ldap->set_password(
|
|
|
|
|
newpasswd => $PAR{'new_pass'},
|
|
|
|
|
);
|
|
|
|
|
if ($result->code){
|
|
|
|
|
$result = $ldap->set_password(newpasswd => $PAR{'new_pass'});
|
|
|
|
|
if ($result->code) {
|
|
|
|
|
print $result->error;
|
|
|
|
|
} else {
|
|
|
|
|
print "OK";
|
|
|
|
@ -80,7 +79,6 @@ if ($active_server){
|
|
|
|
|
print "User not found in LDAP\n" if $count == 0;
|
|
|
|
|
print "Found $count users\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$ldap->unbind();
|
|
|
|
|