New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LDAP password policy #5364
Merged
Merged
LDAP password policy #5364
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
acbc67e
Correction to work good with the Net_LDAP2 2.2.0
ZiBiS 5322e91
LDAP password driver for password policy
ZiBiS 0b07f37
LDAP password policy driver files
ZiBiS 0efb682
New constant PASSWORD_IN_HISTORY added for ldap_ppolicy plugin.
ZiBiS 0c093b0
Added the missing changes
ZiBiS 191396d
The error log is redirected to logs/ldap_ppolicy.err
ZiBiS c22d4bc
The correction of the script path and log_dir from the rc
ZiBiS 7254a89
get log_dir from config
ZiBiS 0695657
Change parameters names to the standard.
ZiBiS fa533a4
Revert "Correction to work good with the Net_LDAP2 2.2.0"
ZiBiS File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/** | ||
* ldap_ppolicy driver | ||
* | ||
* Driver that adds functionality to change the user password via | ||
* the 'change_ldap_pass.pl' command respecting password policy (history) in LDAP. | ||
* | ||
* | ||
* @version 1.0 | ||
* @author Zbigniew Szmyd <zbigniew.szmyd@linseco.pl> | ||
* | ||
|
||
*/ | ||
|
||
class rcube_ldap_ppolicy_password | ||
{ | ||
public function save($currpass, $newpass) | ||
{ | ||
$rcmail = rcmail::get_instance(); | ||
$this->debug = $rcmail->config->get('ldap_debug'); | ||
|
||
$cmd = $rcmail->config->get('password_ldap_ppolicy_cmd'); | ||
$uri = $rcmail->config->get('password_ldap_uri'); | ||
$baseDN = $rcmail->config->get('password_ldap_basedn'); | ||
$filter = $rcmail->config->get('password_ldap_search_filter'); | ||
$bindDN = $rcmail->config->get('password_ldap_searchDN'); | ||
$bindPW = $rcmail->config->get('password_ldap_searchPW'); | ||
$cafile = $rcmail->config->get('password_ldap_cafile'); | ||
|
||
$descriptorspec = array( | ||
0 => array("pipe", "r"), // stdin is a pipe that the child will read from | ||
1 => array("pipe", "w"), // stdout is a pipe that the child will write to | ||
2 => array("file", "/tmp/ppolicy_ldap.err", "a") // stderr is a file to write to | ||
); | ||
|
||
$cwd = 'plugins/password/drivers/'; | ||
$cmd = $cwd.$cmd; | ||
$this->_debug('CWD: '. $cwd); | ||
$this->_debug("parameters:\ncmd:$cmd\nuri:$uri\nbaseDN:$baseDN\nfilter:$filter"); | ||
$process = proc_open($cmd, $descriptorspec, $pipes); | ||
|
||
if (is_resource($process)) { | ||
// $pipes now looks like this: | ||
// 0 => writeable handle connected to child stdin | ||
// 1 => readable handle connected to child stdout | ||
// Any error output will be appended to /tmp/error-output.txt | ||
|
||
fwrite($pipes[0], $uri."\n"); | ||
fwrite($pipes[0], $baseDN."\n"); | ||
fwrite($pipes[0], $filter."\n"); | ||
fwrite($pipes[0], $bindDN."\n"); | ||
fwrite($pipes[0], $bindPW."\n"); | ||
fwrite($pipes[0], $_SESSION['username']."\n"); | ||
fwrite($pipes[0], $currpass."\n"); | ||
fwrite($pipes[0], $newpass."\n"); | ||
fwrite($pipes[0], $cafile); | ||
fclose($pipes[0]); | ||
|
||
$result = stream_get_contents($pipes[1]); | ||
fclose($pipes[1]); | ||
|
||
$this->_debug('Result:'.$result); | ||
|
||
switch ($result) { | ||
case "OK": | ||
return PASSWORD_SUCCESS; | ||
case "Password is in history of old passwords": | ||
return PASSWORD_IN_HISTORY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PASSWORD_IN_HISTORY constant does not exist. Did you forget to commit password.php changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're right. I've made new commit with it. |
||
|
||
case "Cannot connect to any server": | ||
return PASSWORD_CONNECT_ERROR; | ||
default: | ||
rcube::raise_error(array( | ||
'code' => 600, | ||
'type' => 'php', | ||
'file' => __FILE__, 'line' => __LINE__, | ||
'message' => $result | ||
), true, false); | ||
} | ||
|
||
return PASSWORD_ERROR; | ||
} | ||
} | ||
|
||
private function _debug($str) | ||
{ | ||
if ($this->debug) { | ||
rcube::write_log('ldap_ppolicy', $str); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/perl | ||
=pod | ||
Script to change the LDAP password using the set_password method | ||
to proper setting the password policy attributes | ||
author: Zbigniew Szmyd (zbigniew.szmyd@linseco.pl) | ||
version 1.0 2016-02-22 | ||
=cut | ||
|
||
use Net::LDAP; | ||
use Net::LDAP::Extension::SetPassword; | ||
use URI; | ||
use utf8; | ||
binmode(STDOUT, ':utf8'); | ||
|
||
my %PAR = (); | ||
if (my $param = shift @ARGV){ | ||
print "Password change in LDAP\n\n"; | ||
print "Run script without any parameter and pass the following data:\n"; | ||
print "URI\nbaseDN\nFilter\nbindDN\nbindPW\nLogin\nuserPass\nnewPass\nCAfile\n"; | ||
exit; | ||
} | ||
|
||
foreach my $param ('uri','base','filter','binddn','bindpw','user','pass','new_pass','ca'){ | ||
$PAR{$param} = <>; | ||
$PAR{$param} =~ s/\r|\n//g; | ||
} | ||
|
||
my @servers = split (/\s+/, $PAR{'uri'}); | ||
my $active_server = 0; | ||
|
||
my $ldap; | ||
while ((my $serwer = shift @servers) && !($active_server)){ | ||
my $ldap_uri = URI->new($serwer); | ||
if ($ldap_uri->secure){ | ||
$ldap = Net::LDAP->new($ldap_uri->as_string, | ||
version => 3, | ||
verify => 'require', | ||
sslversion => 'tlsv1', | ||
cafile => $PAR{'ca'}); | ||
} else { | ||
$ldap = Net::LDAP->new($ldap_uri->as_string, version => 3); | ||
} | ||
$active_server = 1 if ($ldap); | ||
} | ||
|
||
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'}, | ||
scope => 'sub', | ||
filter => $PAR{'filter'}, | ||
attrs => ['1.1'], | ||
); | ||
my $result = $ldap->search( @search_args ); | ||
if ($result->code){ | ||
print $result->error; | ||
} else { | ||
my $count = $result->count; | ||
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){ | ||
print $result->error; | ||
} else { | ||
print "OK"; | ||
} | ||
} | ||
} else { | ||
print "User not found in LDAP\n" if $count == 0; | ||
print "Found $count users\n"; | ||
} | ||
|
||
} | ||
} | ||
$ldap->unbind(); | ||
} else { | ||
print "Cannot connect to any server"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a path to helpers directory? Also does the command need to be configurable at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to logs directory. This can be useful in case of any errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all you should use log_dir option to get the logs dir location. Second, I was talking about 'plugins/password/drivers/'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I missed that path is not correct and log_dir should be get in propper way now.