Next / Previous / Contents / TCC Help System / NM Tech homepage

25.4. ClientSet.__buildLdapMap(): Extract LDAP's client list

This function encapsulates all our dealings with the LDAP server.

hwscan3.py
# - - -   C l i e n t S e t . _ _ b u i l d L d a p M a p

    def __buildLdapMap(self):
        '''Find all publicly accessible clients from LDAP.

          [ ldap0.nmt.edu contains client info ->
              ldapMap  :=  a dictionary whose keys are the
                non-office machine names from LDAP's client tree,
                and each corresponding value is its tccSpecialOS
                attribute (defaulting to '') ]
        '''

First we create the dictionary to be returned, and the anonymous LDAP binding. The first two arguments to the .bind() method are the login name and password; we pass empty strings to them, giving us an anonymous binding. See Section 6.12, “LDAP_URL.

hwscan3.py
        #-- 1 --
        # [ ldapMap  :=  a new, empty dictionary
        #   binding  :=  an anonymous LDAP binding ]
        ldapMap  =  {}
        binding  =  ldap.initialize ( LDAP_URL )
        binding.bind ( "", "", ldap.AUTH_SIMPLE )

The DN of the clients tree in LDAP is given by Section 6.13, “CLIENTS_DN to find all client systems. The second argument, ldap.SCOPE_ONELEVEL, restricts the search to return only immediate children of the clients tree. The third argument is a trivial filter expression that does not actually filter out any children; see Section 6.14, “NULL_FILTER. The fourth argument is a list of the attribute names we want to retrieve; see Section 6.19, “ATTR_LIST.

hwscan3.py
        #-- 2 --
        # [ resultList  :=  an LDAP query result for children of
        #       CLIENTS_DN ]
        resultList  =  binding.search_s ( CLIENTS_DN,
            ldap.SCOPE_ONELEVEL, NULL_FILTER, ATTR_LIST )

The resultList is a list of 2-tuples. In each tuple, the first element is the DN of the entry, and the second element is a dictionary of attributes. Within this dictionary, the key of each entry is the attribute name, and the corresponding value is a list of attribute values. Once the ldapMap is built, it is returned to the caller. See Section 25.5, “ClientSet.__processLdapEntry(): Process one LDAP client record”.

hwscan3.py
        #-- 3 --
        # [ resultList is an LDAP search result ->
        #     ldapMap  :=  ldapMap with entries added for
        #         results from resultList that are not
        #         office machines, each key is the host name,
        #         and each corresponding value is the
        #         tccSpecialOS attribute value, defaulting to '' ]
        for dn, attrMap in resultList:
            #-- 3 body --
            # [ attrMap is a dictionary whose keys are LDAP
            #   attribute names from RESULT_LIST, and each
            #   corresponding value is a list of the values of
            #   that attribute ->
            #     if attrMap[OFFICE_ATTR][0] != LDAP_TRUE ->
            #       ldapMap  :=  ldapMap with an entry added
            #           whose key is the CN_ATTR attribute from
            #           attrMap and whose corresponding value is
            #           the OS_ATTR value from attrMap,
            #           defaulting to ''
            #     else -> I ]
            self.__processLdapEntry ( ldapMap, attrMap )

        #-- 4 --
        return ldapMap