Contexte

Pour le passage des commandes (LDAP) j'ai utilisé un conteneur Docker avec openLDAP que vous pouvez retrouver à l'adresse suivante.

Recherche dans l'annuaire LDAP

en LDAP

 1 $ ldapsearch -x -h localhost -p 389 -LL -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
 2 
 3 ## ou
 4 
 5 $ ldapsearch -x -H ldap://localhost -LL -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
 6 version: 1
 7 
 8 dn: ou=Users,dc=openstack,dc=org
 9 objectClass: organizationalUnit
10 ou: Users
11 
12 dn: cn=Robert Smith,ou=Users,dc=openstack,dc=org
13 objectClass: inetOrgPerson
14 cn: Robert Smith
15 cn: Robert J Smith
16 cn: bob  smith
17 sn: smith
18 uid: rjsmith
19 userPassword:: ckpzbWl0SA==
20 carLicense: HISCAR 123
21 homePhone: 555-111-2222
22 mail: r.smith@example.com
23 mail: rsmith@example.com
24 mail: bob.smith@example.com
25 description: swell guy
26 ou: Human Resources
27 
28 dn: cn=Larry Cai,ou=Users,dc=openstack,dc=org
29 objectClass: inetOrgPerson
30 cn: Larry Cai
31 sn: Cai
32 uid: larrycai
33 userPassword:: TGFycnlDYWk=
34 carLicense: HISCAR 123
35 homePhone: 555-111-2222
36 mail: larry.caiyu@gmail.com
37 description: hacker guy
38 ou: Development Department

en LDAP SSL/TLS

1 $ ldapsearch -xv -ZZZ -LLL -h localhost -p 389 -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
2 ## ou
3 $ ldapsearch -x -H ldap://localhost -LL -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password

en LDAPS

1 $ ldapsearch -xv -LLL  -H ldaps://localhost:686 b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
2 ## ou
3 $ A tester avec -h et port 686

Options :

  • -b : Base DN, point dans l'arbre LDAP ou l'on se positionne pour commencer la recherche
  • -D : Bind DN, utilisateur avec lequel on se connecte à LDAP
  • -s : Scope
  • -w : Bind Password, on fournit le password dans la ligne de commande
  • -W : Bind Password, on sera prompter lors du lancement de la commande
  • -v : verbose

Suppression

Unitairement

1 $ ldapdelete -xv  -h localhost -D "cn=admin,dc=openstack,dc=org" -w password "cn=Robert Smith,ou=Users,dc=openstack,dc=org"

En masse

1 $ cat delete_masse.txt
2 cn=Larry Cai,ou=Users,dc=openstack,dc=org
3 cn=Robert Smith,ou=Users,dc=openstack,dc=org
4 
5 
6 $ ldapdelete -xv  -h localhost -D "cn=admin,dc=openstack,dc=org" -w password -f ./delete_masse.txt

Ajout

 1 ## Fichier LDIF à ajouter :
 2 $ cat more.ldif
 3 dn: cn=Robert Smith,ou=Users,dc=openstack,dc=org
 4 objectclass: inetOrgPerson
 5 cn: Robert Smith
 6 cn: Robert J Smith
 7 cn: bob  smith
 8 sn: smith
 9 uid: rjsmith
10 userpassword: rJsmitH
11 carlicense: HISCAR 123
12 homephone: 555-111-2222
13 mail: r.smith@example.com
14 mail: rsmith@example.com
15 mail: bob.smith@example.com
16 description: swell guy
17 ou: Human Resources
18 
19 dn: cn=Larry Cai,ou=Users,dc=openstack,dc=org
20 objectclass: inetOrgPerson
21 cn: Larry Cai
22 sn: Cai
23 uid: larrycai
24 userpassword: LarryCai
25 carlicense: HISCAR 123
26 homephone: 555-111-2222
27 mail: larry.caiyu@gmail.com
28 description: hacker guy
29 ou: Development Department
30 
31 
32 
33 $ ldapadd -x -D cn=admin,dc=openstack,dc=org -w password -c -f more.ldif
34 adding new entry "cn=Robert Smith,ou=Users,dc=openstack,dc=org"
35 
36 adding new entry "cn=Larry Cai,ou=Users,dc=openstack,dc=org"

Note : si une entrée existe déjà elle ne sera pas remplacé ni modifié, il faudra utiliser ldapmodify.