Skip to content

Commit 7fbc4b5

Browse files
committed
backend openLdap
1 parent 360e080 commit 7fbc4b5

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

backends/openldap/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Backend LDAP
2+
## Installation
3+
### Debian
4+
```
5+
#apt-get install libnet-ldap-perl
6+
#apt-get install libjson-perl
7+
```

backends/openldap/bin/changepasswd

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/perl -n
2+
use JSON;
3+
use Net::LDAP;
4+
BEGIN: {
5+
sub readConfig()
6+
{
7+
%param=();
8+
$param{'host'}="***REMOVED***";
9+
$param{'dn'}="cn=manager,cn=internal,dc=lyon,dc=archi,dc=fr";
10+
$param{'pwd'}="***REMOVED***";
11+
$param{'base'}="dc=lyon,dc=archi,dc=fr";
12+
return %param;
13+
}
14+
}
15+
my $params=decode_json($_);
16+
$uid=$params->{'uid'};
17+
$oldPassword=$params->{'oldPassword'};
18+
$newPassword=$params->{'newPassword'};
19+
#connection
20+
%p=readConfig();
21+
#Ouverture de la connexion LDAP
22+
$ldap=Net::LDAP->new($p{'host'});
23+
#bind
24+
my $mesg=$ldap->bind($p{'dn'},password =>$p{'pwd'});
25+
if ($mesg->code() > 0)
26+
{
27+
print STDERR "erreur connexion";
28+
exit 1;
29+
}
30+
#recherche si l uid existe et sont dn
31+
my $mesg=$ldap->search(base =>$p{'base'},scope=>2,filter=>"mail=$uid");
32+
if ($mesg->count == 0)
33+
{
34+
print STDERR "Erreur authentification";
35+
exit 2;
36+
}
37+
my $myDn=$mesg->entry(0)->dn();
38+
#rebind du dn pour verifier son mdp
39+
my $mesg=$ldap->bind($myDn,password =>$oldPassword);
40+
if ($mesg->code() > 0)
41+
{
42+
print STDERR "Erreur authentification";
43+
exit 3;
44+
}
45+
#Ok la connexion est bonne on change le mot de passe
46+
my $mesg=$ldap->search(base =>$myDn,scope=>0,filter=>"objectclass=*");
47+
$entry=$mesg->entry(0);
48+
$entry->replace("userPassword" => $newPassword);
49+
$mesg=$entry->update($ldap);
50+
if ($mesg->{resultCode} > 0)
51+
{
52+
print STDERR "Server error : " . $mesg->error ;
53+
exit 3
54+
}
55+
print "OK";
56+
exit 0;

backends/openldap/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
name: 'openldap'
3+
description: 'Backend for openldap'
4+
active: 1
5+
actions:
6+
CHANGEPWD:
7+
exec: "changepasswd"
8+
onError: 'stop'
9+
ADDIDENT:
10+
exec: 'dummy.sh'
11+
UPDATEIDENT:
12+
exec: 'dummy.sh'
13+
DELIDENT:
14+
exec: 'dummy.sh'
15+
PING:
16+
exec: 'ping.sh'
17+

0 commit comments

Comments
 (0)