LDAP - Quelques commandes
Alasta 24 Juillet 2016 bash ldap bash shell cli
Description : Voici quelques commandes LDAP.
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
$ ldapsearch -x -h localhost -p 389 -LL -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
## ou
$ ldapsearch -x -H ldap://localhost -LL -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
version: 1
dn: ou=Users,dc=openstack,dc=org
objectClass: organizationalUnit
ou: Users
dn: cn=Robert Smith,ou=Users,dc=openstack,dc=org
objectClass: inetOrgPerson
cn: Robert Smith
cn: Robert J Smith
cn: bob smith
sn: smith
uid: rjsmith
userPassword:: ckpzbWl0SA==
carLicense: HISCAR 123
homePhone: 555-111-2222
mail: r.smith@example.com
mail: rsmith@example.com
mail: bob.smith@example.com
description: swell guy
ou: Human Resources
dn: cn=Larry Cai,ou=Users,dc=openstack,dc=org
objectClass: inetOrgPerson
cn: Larry Cai
sn: Cai
uid: larrycai
userPassword:: TGFycnlDYWk=
carLicense: HISCAR 123
homePhone: 555-111-2222
mail: larry.caiyu@gmail.com
description: hacker guy
ou: Development Department
en LDAP SSL/TLS
$ ldapsearch -xv -ZZZ -LLL -h localhost -p 389 -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
## ou
$ ldapsearch -x -H ldap://localhost -LL -b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
en LDAPS
$ ldapsearch -xv -LLL -H ldaps://localhost:686 b "ou=Users,dc=openstack,dc=org" -D "cn=admin,dc=openstack,dc=org" -w password
## ou
$ 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
$ ldapdelete -xv -h localhost -D "cn=admin,dc=openstack,dc=org" -w password "cn=Robert Smith,ou=Users,dc=openstack,dc=org"
En masse
$ cat delete_masse.txt
cn=Larry Cai,ou=Users,dc=openstack,dc=org
cn=Robert Smith,ou=Users,dc=openstack,dc=org
$ ldapdelete -xv -h localhost -D "cn=admin,dc=openstack,dc=org" -w password -f ./delete_masse.txt
Ajout
## Fichier LDIF à ajouter :
$ cat more.ldif
dn: cn=Robert Smith,ou=Users,dc=openstack,dc=org
objectclass: inetOrgPerson
cn: Robert Smith
cn: Robert J Smith
cn: bob smith
sn: smith
uid: rjsmith
userpassword: rJsmitH
carlicense: HISCAR 123
homephone: 555-111-2222
mail: r.smith@example.com
mail: rsmith@example.com
mail: bob.smith@example.com
description: swell guy
ou: Human Resources
dn: cn=Larry Cai,ou=Users,dc=openstack,dc=org
objectclass: inetOrgPerson
cn: Larry Cai
sn: Cai
uid: larrycai
userpassword: LarryCai
carlicense: HISCAR 123
homephone: 555-111-2222
mail: larry.caiyu@gmail.com
description: hacker guy
ou: Development Department
$ ldapadd -x -D cn=admin,dc=openstack,dc=org -w password -c -f more.ldif
adding new entry "cn=Robert Smith,ou=Users,dc=openstack,dc=org"
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.