Package: tiny-ldap-manager
Tiny LDAP ManagerThis CLI tool allows you to easily perform basic operations (changes) on your
LDAP server. It's aimed to ease these kind of tasks, without having to, necessarily,
deal withLDIFfiles. Moreover, it permits you to do some of these things, in bulk!.FeaturesMore precisely, this program, allows you to:Modify LDAP attributes (replace,addanddeletemodes, are supported!).Delete LDAP entries.Add LDAP entries with their correspondingattributes, by importing them
from a CSV file!.Query the LDAP attributes of a particular entry, based on its DN.Search for entries matching anLDAP filter.Perform the following LDAP operations in bulk:addentries,deleteentries andmodifyLDAP attributes!.RequirementsThis is what it needs, in order to work:Python 3(>=3.7)python-ldaplibrary (tested
withv3.3.1).DisclaimerI don't take any responsibility on the consequences of the usage of this
program!. Use it at your own risk!!.It's advisable to always have a working backup of your LDAP database, prior to
ANY modification!.InstallationThe recommended way to install this program, is by usingpip:pip install tiny-ldap-managerUsageTo start with, here's the help output:usage: tiny-ldap-manager [-h] [-v]
                         SERVER BINDDN {ls,search,modify,delete,bulk} ...

Easily perform several LDAP operations

positional arguments:
  SERVER                URI formatted address of the LDAP server
  BINDDN                DN of the user to bind the LDAP server
  {ls,search,modify,delete,bulk}
    ls                  List LDAP attributes for specified DN
    search              Perform an LDAP search of DNs
    modify              Modify an LDAP attribute
    delete              Delete an LDAP entry
    bulk                Perform an LDAP operation in bulk

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         Show current versionBasic syntaxThe basic syntax you've to respect is the following:tiny-ldap-manager [SERVER] [BINDDN] [ACTION] [ARGUMENTS]In order of appearance:[SERVER]belongs to theURI formatted addressof your LDAP server.[BINDDN]is theDN("Distinguished Name") of the LDAP user with
permissions for the operation you wish to perform!.[ACTION]is the actual operation you want to perform. At present, there
are five valid operations you can use:ls,search,modify,deleteorbulk. Make sure youonlyprovideone of those!. Please, see below for more details.[ARGUMENTS]: when you perform an[ACTION], any of them requires, at least, one
or more additional arguments. You can add the--helpargument to any of
them, for specific details. Please, see below for more on this.Please, note thatpositional argumentsaremandatory!.Performing different LDAP operationsAuthenticationTake into account that, anauthenticated sessionis always assumed. So you are
gonna be asked for the corresponding credentials, each time you perform an
operation!.Listing attributes of an LDAP entryThelsaction, allows you to quickly see the attributes of a particular LDAP
entry. For this, you have to provide the DN of the latter. For example:tiny-ldap-manager ldap://192.168.100.5 "cn=config" ls "uid=joe,ou=people,dc=somecorp,dc=com"Search for entries matching an LDAP filterYou can use thesearchaction, to get a list of DNs that matches a providedLDAP filter.Make sure to respect the following syntax:tiny-ldap-manager [SERVER] [USERDN] search [BASEDN] [LDAP_FILTER]As shown above, besides the usual required arguments, thesearchaction,
needs the[BASEDN]and[LDAP_FILTER]additional arguments!.Here's an example:tiny-ldap-manager ldaps://192.168.100.5 "cn=config" search "dc=somecorp,dc=com" "mail=*joe*"Based on this example, it'll return every DN, whosemailattribute contains the
string"joe"in it.Modifying an attribute of an LDAP entryFor modifying or adding an attribute to an LDAP entry, you logically use themodifyaction. There are three types of modifications possible to use:REPLACEis to be used whenever you want to modify the value of an existing
attribute. This is the modeused by default!.ADDis for adding a non-existing attribute!.DELETEis, of course, for deleting an existing attribute!.REPLACE modeIf you don't provide any additional arguments, theREPLACEmode is used by
default!. The complete syntax for it, is:tiny-ldap-manager [SERVER] [USERDN] modify [DN] [ATTRIBUTE] [VALUE]Where[DN]is theDistinguished Name(DN) of the LDAP object whose attribute
you wish to modify. The[ATTRIBUTE]is the name of theattributeto be modified,
and[VALUE]is thenew valuefor thatattribute!.Let's see an example:tiny-ldap-manager ldap://192.168.100.5 "cn=config" modify "uid=joe,ou=people,dc=somecorp,dc=com" telephoneNumber "5555"Above, we're modifying the existingtelephoneNumberattribute with a new value
of5555.Make sure that the new value for the attribute you're modifying, is NOT the
same as its current value!. Otherwise, you'll get an error!.ADD modeIn order to use a different mode for making a modification, you've to do it
using the-Margument, as follows:tiny-ldap-manager ldap://192.168.100.5 "cn=config" modify -M ADD "uid=willy,ou=people,dc=somecorp,dc=com" telephoneNumber "8006666"With this latter example, we add thetelephoneNumberattribute, with its
corresponding value.It's important to note that this program iscase-sensitive, so themodification modealways goes with capital letters!.DELETE modeFinally, an example for using theDELETEmode, for removing an existing LDAP attribute:tiny-ldap-manager ldap://192.168.100.5 "cn=config" modify -M DELETE "uid=charles,ou=people,dc=somecorp,dc=com" telephoneNumber ""Note that thedouble quotesat the end of the command,are necessary!.Deleting an LDAP entryYou can simply remove an LDAP entry from your database, by indicating its DN,
as is shown next:tiny-ldap-manager ldap://192.168.100.5 "cn=config" delete "uid=bob,ou=people,dc=somecorp,dc=com"Performing LDAP operations in bulkTo perform an specific operation inbulk, use thebulkactionfollowed by
the desired LDAP operation. Its syntax works as follows:tiny-ldap-manager [SERVER] [BINDDN] bulk [OPERATION] [FILE]As you can see from the syntax described above, eachbulkoperation requires
a[FILE]argument, which can consist either of a simple text file or a CSV
file, depending on each case. Please, see below for details.The followingbulkoperations are supported:--modify-attributes(modify LDAP attributes)--add-entries(add LDAP entries)--delete-entries(delete LDAP entries)Adding LDAP entries in bulkThe way to add entries to an LDAP database withtiny-ldap-manager, is by
creating a CSV file using the header row (first row), to specify the attributes
for each new entry. You must ensure that you use asemi-colon(;) as the CSV
delimiter!.Besides the CSVheader row, the rest of them, are to be used to define the
value of each corresponding attribute.The order in which the LDAP attributes are specified in the CSV file, is not
important, as long as there is a logical correlation between thevalueassigned
to eachattributeand theattributeitself!. Even then, for the sake of
clarity, it's a good idea to always put the DN in the first place!.Now, let's see an example of a CSV file content:dn;objectClass;uid;cn;sn;givenName;displayName;mail
uid=cdarwin,ou=people,dc=scileague,dc=org;['inetOrgPerson','organizationalPerson'];cdarwin;cdarwin;Darwin;Charles;Charles Darwin;charlesdarwin@scileague.org
uid=alovelace,ou=people,dc=scileague,dc=org;inetOrgPerson;alovelace;alovelace;Lovelace;Ada;Ada Lovelace;adalovelace@scileague.org
uid=aeinstein,ou=people,dc=scileague,dc=org;inetOrgPerson;aeinstein;aeinstein;Einstein;Albert;Albert Einstein;alberteinstein@scileague.orgThe following is how you would import such entries:tiny-ldap-manager ldap://192.168.100.5 "cn=config" bulk --add-entries scileague.csvAs you might noticed in the CSV, the entry that belongs toCharles Darwin, has
aformatted listofvaluesfor theobjectClassattribute. That's a
supported way to include more than onevaluefor a givenattribute.As a final note about importing new LDAP entries, if one or many of them, already
exist in the LDAP database, you can be sure that they won't be imported, but
equally important, is the fact that they won't interrupt the whole process
neither. An output message is shown in each case.Removing LDAP entries in bulkThebulkremoval of LDAP entries, works by specifying a plain text file as
an argument, in which each line, contains a DN to be removed. Here's an example:tiny-ldap-manager ldap://192.168.100.5 "cn=config" bulk --delete-entries remove.txtA simple example of the content of the text file:uid=bob,ou=people,dc=somecorp,dc=com
uid=mike,ou=people,dc=somecorp,dc=comModifying LDAP attributes in bulkModifying LDAP attributes inbulk, works based on the premise that you want
to either update the value of an existing LDAPattributeor create it right
away, if it doesn't exist!. This is done by specifying a CSV file as anargument.In each entry, the CSV file must contain the following data:The DN of the LDAP object to work with.The name of the attribute to create or modify, along with its desired
value!.Let's see an example of the CSV file content:dn;telephoneNumber
uid=joe,ou=people,dc=somecorp,dc=com;1111
uid=robert,ou=people,dc=somecorp,dc=com;2222
uid=tom,ou=people,dc=somecorp,dc=com;3333Now, here's an example of how to apply the changes, indicated by
the CSV file above:tiny-ldap-manager ldap://192.168.100.5 "cn=config" bulk --modify-attributes ldap_modify.csvSome remarks to take into account, about the content of the CSV file:Remember to always use asemi-colon(;) as the CSV delimiter!.Use theheader row(first row) for specifying both the DN and theattribute'sname.The ONLY valid LDAPkey namefor the DN, is:dn! (always uselower
cases). Other names will be considered invalid!.The following, is regarding the general behavior when modifying LDAPattributesinbulk:If a provided DN doesn't exist or is invalid, nothing will be done!.Note that if the DN does exist but theattributedoesn't, the latter and
its provided value will be created!.In the case of an already existingattribute, whenever there isn't a match
between its existing value and the one provided by the CSV file, the former
will be updated!.LicenseThis software is distributed under the GPLv3 license.