Package easyLDAP :: Module easyLDAP_utils
[frames] | no frames]

Module easyLDAP_utils

source code

Functions
 
is_uppercase(test_str)
Checks, whether all alphabetical characters in a given string are upper case characters.
source code
 
is_lowercase(test_str)
Checks, whether all alphabetical characters in a given string are lower case characters.
source code
 
is_mingledcase(test_str)
Checks, whether lower as well as upper case characters appear in a given string.
source code
 
ia5string(non_ia5_str)
Tries to map special characters in a human readable string to IA5 string characters.
source code
 
days_since_1970()
Calculate number of days since 1970.
source code
 
shadowAgeToday()
Calculate number of days since 1970.
source code
 
crypthash(password)
Generate a crypt password hash for a given plain text password.
source code
 
nthash(password)
Generate a smbpasswd-style NT hash.
source code
 
lmhash(password)
Generate a smbpasswd-style LanManager (Win9x) hash.
source code
 
changeAttrTypeInAttrDescDict(attrdesc_dict, attrtype_alias)
This function is used to replace aliases of attribute types in the easyLDAP internal data structure.
source code
 
is_pyldapobject(pyldapobject, strict=True)
Return True, if the given data structure (a single Python dictionary in a Python list) conforms to the Python LDAP data format and only contains data of a single DN.
source code
 
is_pyldaptree(pyldaptree)
Return True, if the given data structure (several Python dictionaries in a Python list) conforms to the Python LDAP data format and all the contained LDAP DNs form a coherent LDAP (sub)tree.
source code
 
to_list_of_strings(values)
Convert any object of a standard Pythonian variable type to a list of strings.
source code
 
generate_ldif(from_single_pyldapobject, to_single_pyldapobject)
Generate an ldif formatted text, that can be used with official OpenLDAP Utils (ldapadd, ldapmodify) or any other LDIF capable LDAP tool.
source code
 
generate_modlist(from_single_pyldapobject, to_single_pyldapobject)
Generate a modification list, that can be used with the Python LDAP methods:
source code
 
get_onelevel_dnlist(dn_list, level)
Return LDAP DNs that have all the same depth level in an LDAP tree hierarchy.
source code
 
get_sorted_dnlist(dn_list)
Sort a DN list so that it can be looked at as an LDAP tree after sorting.
source code
 
genpasswd(length=8, chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
Generate a random password.
source code
 
split_dn(dn, basedn=None)
Split a DN into its RDN components.
source code
 
get_parent_dn(dn, basedn=None)
Return the parent DN of a given DN.
source code
 
get_rdn(dn, basedn=None)
Return the RDN of a given DN.
source code
 
is_dn_syntax(dn)
Check if DN has a valid syntax.
source code
 
get_naming_attribute_value(dn)
Detect the nameing attribute type of a given DN.
source code
 
intersect(l1, l2)
Find the (mathematical) intersection of two different sets of items.
source code
Variables
  EASY_LDAP = {'AdminRDN': 'cn=admin', 'AutomountRDN': 'ou=autom...
  __package__ = 'easyLDAP'
  except_dict = {'CANNOT_DELETE_BASEDN_OBJECT': 'The LDAP server...
  key = 'NO_PARENTOBJECT_FOR_GIVEN_DN'
Function Details

is_uppercase(test_str)

source code 

Checks, whether all alphabetical characters in a given string are upper case characters.

Parameters:
  • test_str (str) - string that shall be tested for uppercase characters

is_lowercase(test_str)

source code 

Checks, whether all alphabetical characters in a given string are lower case characters.

Parameters:
  • test_str (str) - string that shall be tested for lowercase characters

is_mingledcase(test_str)

source code 

Checks, whether lower as well as upper case characters appear in a given string.

Parameters:
  • test_str (str) - string that shall be tested for mixed lowercase and uppercase characters

ia5string(non_ia5_str)

source code 

Tries to map special characters in a human readable string to IA5 string characters.

Parameters:
  • non_ia5_str (str) - string that shall be mapped to an IA5 string

crypthash(password)

source code 

Generate a crypt password hash for a given plain text password.

Parameters:
  • password (str) - plain text password that is to be hashed with the Crypt algorithm

nthash(password)

source code 

Generate a smbpasswd-style NT hash.

Parameters:
  • password (str) - plain text password that is to be hashed with the NT hash algorithm (MD4)

lmhash(password)

source code 

Generate a smbpasswd-style LanManager (Win9x) hash.

Parameters:
  • password (str) - plain text password that is to be hashed with the LanManager hash algorithm

changeAttrTypeInAttrDescDict(attrdesc_dict, attrtype_alias)

source code 

This function is used to replace aliases of attribute types in the easyLDAP internal data structure.

The function expects a dictionary of attribute descriptions and their values (i.e. dictionary keys of the form <attrType>;<attrOption>).

The function will fail if the attribute descriptions (i.e. the dictionary keys) are not all of the same attribute type. It furtheron expects an alias of the attribute type name that shall replace the commonly used attribute type in the formerly named dictionary.

The attribute options, however, must be supported by the LDAPv3 protocol. Attribute description values must be given as multi-valued or single-valued lists (depending on the attribute's properties in the server's LDAP schema).

Example:

   attrdesc_dict = { 'ou': ['network administration team',],
                     'ou;lang-de': ['NETZWERKTEAM',],}

   attrtype_alias = 'organizationalUnit'

   result = { 'organizationalUnit': ['network administration team',],
              'organizationalUnit;lang-de': ['NETZWERKTEAM',],}

If the function fails, the value None is returned.

Parameters:
  • attrdesc_dict (dict) - attribute description dictionary (pre-requisites, see above)
  • attrtype_alias - alias attribute type name that will replace attribute type names in the dictionary keys of attrdesc_dict

is_pyldapobject(pyldapobject, strict=True)

source code 

Return True, if the given data structure (a single Python dictionary in a Python list) conforms to the Python LDAP data format and only contains data of a single DN.

Parameters:
  • pyldapobject (list) - the LDAP data structure to be tested for Python LDAP compliancy
  • strict (bool) - test if the LDAP object also contains objectClass values

is_pyldaptree(pyldaptree)

source code 

Return True, if the given data structure (several Python dictionaries in a Python list) conforms to the Python LDAP data format and all the contained LDAP DNs form a coherent LDAP (sub)tree.

Parameters:
  • pyldaptree (list) - the LDAP data structure to be tested for Python LDAP compliancy

to_list_of_strings(values)

source code 

Convert any object of a standard Pythonian variable type to a list of strings.

Parameters:
  • values - value(s) to be converted @type values; tuple, list

generate_ldif(from_single_pyldapobject, to_single_pyldapobject)

source code 

Generate an ldif formatted text, that can be used with official OpenLDAP Utils (ldapadd, ldapmodify) or any other LDIF capable LDAP tool.

The method expects two Python LDAP objects that only contain a single DN each. To create an LDIF output it is also a pre-requisite that both LDAP objects share the same DN.

The method returns a list, each item represents a line of the LDIF output format.

If this function returns an empty list it means that both Python LDAP objects are identical.

If this function returns None it means that we met an error on our way.

Parameters:
  • from_single_pyldapobject (list) - current LDAP object in database
  • to_single_pyldapobject (list) - LDAP object containing the database changes that shall be represented in the expected LDIF output text

generate_modlist(from_single_pyldapobject, to_single_pyldapobject)

source code 

Generate a modification list, that can be used with the Python LDAP methods:

   ldap.ldap_modify()
   ldap.modify_s()

The method expects two Python LDAP objects that only contain a single DN each. To create an LDAP modlist it is also a pre-requisite that both LDAP objects share the same DN.

If this function returns an empty list it means that both Python LDAP objects are identical.

If this function returns None it means that we met an error on our way.

Parameters:
  • from_single_pyldapobject (list) - current LDAP object in database
  • to_single_pyldapobject (list) - LDAP object containing the database changes that shall be represented in the expected Python LDAP stylish list of modifications

get_onelevel_dnlist(dn_list, level)

source code 

Return LDAP DNs that have all the same depth level in an LDAP tree hierarchy.

Parameters:
  • dn_list (list) - list of LDAP DN strings
  • level (int) - depth level in the LDAP tree

get_sorted_dnlist(dn_list)

source code 

Sort a DN list so that it can be looked at as an LDAP tree after sorting.

Parameters:
  • dn_list (list) - list of LDAP DN strings

genpasswd(length=8, chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')

source code 

Generate a random password.

Parameters:
  • length (int) - password length
  • chars (str) - choice of characters for the random password

split_dn(dn, basedn=None)

source code 

Split a DN into its RDN components.

Parameters:
  • dn (str) - DN to be split
  • basedn (str) - if given, the base DN at the end of the DN will not be split into RDNs

get_parent_dn(dn, basedn=None)

source code 

Return the parent DN of a given DN.

If the given DN already is the base DN of the LDAP tree, then the Base DN is returned.

Parameters:
  • dn (str) - child DN
  • basedn (str) - if the given DN equals the base DN then the base DN will be returned

get_rdn(dn, basedn=None)

source code 

Return the RDN of a given DN.

If the given DN already is the base DN of the LDAP tree, then the Base DN is returned.

Parameters:
  • dn (str) - find out RDN of this DN
  • basedn (str) - if the given DN equals the base DN then the base DN will be returned

is_dn_syntax(dn)

source code 

Check if DN has a valid syntax.

Parameters:
  • dn (str) - DN to be checked for valid syntax

get_naming_attribute_value(dn)

source code 

Detect the nameing attribute type of a given DN.

Parameters:
  • dn (str) - detect naming attribute type from this DN

intersect(l1, l2)

source code 

Find the (mathematical) intersection of two different sets of items.

Parameters:
  • l1 (list) - first list of items for intersection
  • l2 - second list of items for intersection type l2: list

Variables Details

EASY_LDAP

Value:
{'AdminRDN': 'cn=admin',
 'AutomountRDN': 'ou=automount',
 'BaseDN': 'dc=localdomain',
 'BindDN': '',
 'BindPW': '',
 'CacheHistorySize': 50,
 'ExcludeFromCharsetEncoding': ['jpegPhoto', 'photo', 'audio'],
 'ForceLocaleCharsetEncoding': '',
...

except_dict

Value:
{'CANNOT_DELETE_BASEDN_OBJECT': 'The LDAP server\'s base DN object can\
not be deleted from the LDAP tree, modify its values instead.',
 'NO_PARENTOBJECT_FOR_GIVEN_DN': 'Your object can not be created as it\
 will have no parent object, create the parent object first.',
 'ORPHANED_OBJECTS_IN_TREE': 'There are objects in the LDAP cache tree\
 that have no parent, this should not happen...'}