Ticket #133: ldapplugin_tls.2.patch

File ldapplugin_tls.2.patch, 2.4 kB (added by tizianomueller, 2 years ago)

Improved version. SSL works now too.

  • ldapplugin-0.10/ldapplugin/model.py

    old new  
    3333                       'group_bind', 'store_bind', 
    3434                       'user_rdn', 'group_rdn' ] 
    3535 
    36 LDAP_DIRECTORY_PARAMS = [ 'host', 'port', 'basedn', 
     36LDAP_DIRECTORY_PARAMS = [ 'uri', 'basedn', 
    3737                          'bind_user', 'bind_passwd', 
    3838                          'groupname', 'groupmember', 
    39                           'groupattr', 'uidattr', 'permattr'] 
     39                          'groupattr', 'uidattr', 'permattr', 
     40                          'start_tls', 'cacertdir', 'cacertfile', 
     41                          'keyfile','certfile'] 
    4042                           
    4143GROUP_PREFIX = '@' 
    4244 
     
    501503    def __init__(self, log, bind=False, **ldap): 
    502504        self.log = log 
    503505        self.bind = bind 
    504         self.host = 'localhost' 
    505         self.port = 389 
     506        self.uri = 'ldap://localhost:389' 
    506507        self.groupname = 'groupofnames' 
    507508        self.groupmember = 'member' 
    508509        self.groupattr = 'cn' 
     
    511512        self.bind_user = None 
    512513        self.bind_passwd = None 
    513514        self.basedn = None 
     515        self.start_tls = False 
     516        self.cacertdir = '/etc/ssl/certs' 
     517        self.cacertfile = '' 
     518        self.keyfile = '' 
     519        self.certfile = '' 
    514520        for k, v in ldap.items(): 
    515521            self.__setattr__(k, v.encode('ascii')) 
    516         if not isinstance(self.port, int): 
    517             self.port = int(self.port) 
    518522        if self.basedn is None: 
    519523            raise TracError, "No basedn is defined" 
    520524 
     
    592596    def _open(self): 
    593597        """Open and optionnally bind a new connection to the LDAP directory""" 
    594598        try: 
    595             self._ds = ldap.initialize('ldap://%s:%d/' % (self.host, self.port)
     599            self._ds = ldap.initialize(self.uri
    596600            self._ds.protocol_version = ldap.VERSION3 
     601            self._ds.x_tls_cacertdir = self.cacertdir 
     602            self._ds.x_tls_cacertfile = self.cacertfile 
     603            self._ds.x_tls_keyfile = self.keyfile 
     604            self._ds.x_tls_certfile = self.certfile 
     605 
     606            if self.start_tls == 'true': 
     607                self.log.debug("Starting TLS encryption.") 
     608                self._ds.start_tls_s() 
     609 
    597610            if self.bind: 
    598611                if not self.bind_user: 
    599612                    raise TracError("Bind enabled but credentials not defined")