Changeset 983

Show
Ignore:
Timestamp:
05/01/03 23:08:44 (21 years ago)
Author:
jalet
Message:

More work on LDAP

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldap.py

    r979 r983  
    2121# 
    2222# $Log$ 
     23# Revision 1.4  2003/05/01 21:08:44  jalet 
     24# More work on LDAP 
     25# 
    2326# Revision 1.3  2003/04/30 17:40:02  jalet 
    2427# I've got my assigned number for LDAP by the IANA. 
     
    5861            self.database = ldap.initialize(host)  
    5962            self.database.simple_bind_s(user, passwd) 
    60             # TODO : dbname will be the base dn 
     63            self.basedn = dbname 
    6164        except ldap.SERVER_DOWN :     
    6265            raise PyKotaStorageError, "LDAP backend for PyKota seems to be down !" # TODO : translate 
     
    7073            self.closed = 1 
    7174         
    72     def doQuery(self, query) : 
    73         """Does a query.""" 
    74         pass 
    75          
    76     def doQuote(self, field) : 
    77         """Quotes a field for use as a string in LDAP queries.""" 
    78         pass 
    79          
    80     def doParseResult(self, result) : 
    81         """Returns the result as a list of Python mappings.""" 
    82         pass 
     75    def doSearch(self, key, fields, base="") : 
     76        """Does an LDAP search query.""" 
     77        try : 
     78            # prepends something more restrictive at the beginning of the base dn 
     79            newbase = ",".join([base, self.basedn]) 
     80            if newbase.startswith(",") : 
     81                newbase = newbase[1:] 
     82            result = self.database.search_s(newbase, ldap.SCOPE_SUBTREE, key, fields) 
     83        except ldap.NO_SUCH_OBJECT :     
     84            return 
     85        else :      
     86            return result 
    8387         
    8488    def getMatchingPrinters(self, printerpattern) : 
     
    100104    def getUserId(self, username) : 
    101105        """Returns a userid given a username.""" 
    102         pass 
     106        result = self.doSearch("uid=%s" % username, ["uid"], base="ou=People") 
     107        if result is not None : 
     108            (userid, dummy) = result[0] 
     109            return userid 
    103110             
    104111    def getGroupId(self, groupname) : 
    105112        """Returns a groupid given a grupname.""" 
    106         pass 
     113        result = self.doSearch("cn=%s" % groupname, ["cn"], base="ou=Group") 
     114        if result is not None : 
     115            (groupid, dummy) = result[0] 
     116            return groupid 
    107117             
    108118    def getJobHistoryId(self, jobid, userid, printerid) :