Archive for the 'LDAP Beginner Training' Category

ldapsearch limit returned results

Problem
You want to perform an ldap search but only receive a limited number of records in return.

Solution
Use -z # to restrict the number of records returned.

Example
Search and return only 5 records.ldapsearch -x -z 5 -v-D"cn=Manager,dc=demo,dc=net"-w secret \-b"dc=demo,dc=net" "(lastlogin>=99999999)"

Reference
Technorati Tags: , LDAP Training SchoolLDAP Docs - Quick Start Guide

Recommended

ldapsearch greater than

Problem
You want to search for a field greater than a value, in your LDAP search.

Solution
To search for a field with a value greater than a given figure, we use >=. If you try to just use > it chucks out an error.

Example
This is how to perform a greater than LDAP search.ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret […]

LDAP LDIF Perl search script

Problem
You want to search an LDIF file for a given dn, or pattern.

Solution
Multi-line pattern search and output - useful for LDIFs! Written in Perl - see example tab.

Example
Replace pattern to a given name, etc and filename to LDIF output file.perl -ane '$/="dn" ;print,"\n\n" if($_ =~/pattern/);' filenameFor example:$ cat user.ldifdn: cn=user0,dc=subdiv,dc=demo,dc=netobjectClass: personsn: Usercn: user0userPassword: today321dn: […]

ldapsearch logical NOT

Problem
You want to perform an LDAP search, matching entries which do not match certain criteria.

Solution
To perform a logical NOT we just use the exclamation mark ! - see example.

Example
This is how to perform a logical OR LDAP search.ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret \-b"dc=demo,dc=net" "(!(sn=Doe))"

Reference
Technorati Tags: ldapsearch syntax, openldap ldapsearch, LDAP Training SchoolLDAP Docs - […]

ldapsearch logical AND

Problem
You want to match more than one field, in your LDAP search.

Solution
To match more than one field we use the ampersand - “&” with ldapsearch.

Example
This is how to perform a logical AND LDAP search.ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret \-b"dc=demo,dc=net" "(&(givenname=John)(sn=Smith))"

Reference
Technorati Tags: ldapsearch syntax, openldap ldapsearch, LDAP Training SchoolLDAP Docs - Quick Start Guide

Recommended

ldapsearch with logical OR

Problem
You want to match more one or another pattern, in your LDAP search.

Solution
To match more one pattern or another we use the pipe symbol “|” .

Example
This is how to perform a logical OR LDAP search.ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret \-b"dc=demo,dc=net" "(|(sn=Doe)(sn=Smith))"

Reference
Technorati Tags: ldapsearch syntax, openldap ldapsearch, LDAP Training SchoolLDAP Docs - Quick Start Guide

Recommended
[…]

Deleting LDAP Record

Problem
You want to delete a LDAP entry.

Solution
In this example, we just use ldapdelete from the command line.Remember to take a backup. ldapsearch with -L

Example
Here is an example of deleting a record in LDAP:ldapdelete -v -D'cn=Manager..' -w ${passwd} \ […]

Modify LDAP record entry

Problem
You want to modify or change a record in LDAP.Supplanting one value with another.

Solution
Use ldapmodify from the command line.Again take a backup with -L - just to be sure.

Example
Here is an example of modifying a record in LDAP, when you need to modify an entry to an existing record:ldapmodify -x -v-D”cn=Manager,dc=demo,dc=net”-w secret<<EOTdn: cn=jdoe,dc=demo,dc=netchangetype: […]

Beginning ldap - modify a record

Problem
You want to modify an LDAP record.For example change telephone number, address, etc.

Solution
Use ldapmodify from command line. I might seem daunting to start with, but it is the best way.Plus you should perform a search with -L option, to take a backup to file.

Example
Here is an example of modifying a record in LDAP, when […]

Adding LDAP record

Problem
You want to add an LDAP record. Effectively create a record.

Solution
To add a record to LDAP, you simply run an ldapmodify with the -a flag.

Example
ldapmodify -x -a -v-D”cn=Manager,dc=demo,dc=net”-w secret < ldifFileWhere ldifFile is a file either hand crafted or generated with ldapsearch -L.

Reference
Technorati Tags: ldapadd, ldapmodify, LDAP Training SchoolLDAP Docs - Quick […]