Zhang Huangbin avatar Zhang Huangbin committed 2f1b67a

Typo.

Comments (0)

Files changed (1)

     def __init__(self):
         import ldap
 
+        self.ldap = ldap
+
         # Read LDAP server settings.
         self.uri = cfg.get('ldap', 'uri', 'ldap://127.0.0.1:389')
         self.binddn = cfg.get('ldap', 'binddn')
 
         # Initialize ldap connection.
         try:
-            self.conn = ldap.initialize(self.uri)
+            self.conn = self.ldap.initialize(self.uri)
             logging.debug('LDAP connection initialied success.')
         except Exception, e:
             logging.error('LDAP initialized failed: %s.' % str(e))
             try:
                 self.conn.bind_s(self.binddn, self.bindpw)
                 logging.debug('LDAP bind success.')
-            except ldap.INVALID_CREDENTIALS:
+            except self.ldap.INVALID_CREDENTIALS:
                 logging.error('LDAP bind failed: incorrect bind dn or password.')
                 sys.exit()
             except Exception, e:
         try:
             result = self.conn.search_s(
                     self.baseDN,
-                    ldap.SCOPE_SUBTREE,
+                    self.ldap.SCOPE_SUBTREE,
                     '(&(|(mail=%s)(shadowAddress=%s))(|(objectClass=mailUser)(objectClass=mailList)(objectClass=mailAlias)))' % (recipient, recipient),
                     )
             logging.debug('__get_recipient_dn_ldif (result): %s' % str(result))
             return (result[0][0], result[0][1])
         except Exception, e:
-            logging.debug('!!! ERROR !!! __get_recipient_dn_ldif (result): %s' % str(result))
+            logging.debug('!!! ERROR !!! __get_recipient_dn_ldif (result): %s' % str(e))
             return (None, None)
 
     def __get_access_policy(self, recipient):
 
         # Search mail list object.
         searchBasedn = 'mail=%s,ou=Groups,domainName=%s,%s' % (recipient, recipient.split('@')[1], self.baseDN)
-        searchScope = ldap.SCOPE_BASE
+        searchScope = self.ldap.SCOPE_BASE
         searchFilter = cfg.get('ldap', 'filter_maillist')
         searchAttr = cfg.get('ldap', 'attr_access_policy', 'accessPolicy')
 
         try:
             result = self.conn.search_s(searchBasedn, searchScope, searchFilter, [searchAttr])
             logging.debug('__get_access_policy (search result): %s' % str(result))
-        except ldap.NO_SUCH_OBJECT:
+        except self.ldap.NO_SUCH_OBJECT:
             logging.debug('__get_access_policy (not a mail list: %s) Returned (None)' % recipient)
             return (None, None)
         except Exception, e:
         # Set search base dn, scope, filter and attribute list based on access policy.
         if listpolicy == 'membersOnly':
             baseDN = self.baseDN
-            searchScope = ldap.SCOPE_SUBTREE
+            searchScope = self.ldap.SCOPE_SUBTREE
             # Filter used to get domain members.
             searchFilter = cfg.get("ldap", "filter_member")
             searchAttr = cfg.get("ldap", "attr_member")
         else:
             baseDN = listdn
-            searchScope = ldap.SCOPE_BASE   # Use SCOPE_BASE to improve performance.
+            searchScope = self.ldap.SCOPE_BASE   # Use SCOPE_BASE to improve performance.
             # Filter used to get domain moderators.
             searchFilter = cfg.get("ldap", "filter_allowed_senders")
             searchAttr = cfg.get("ldap", "attr_moderator")
         try:
             result = self.conn.search_s(baseDN, searchScope, searchFilter, [searchAttr])
             logging.debug('__get_allowed_senders (search result): %s' % str(result))
-        except ldap.NO_SUCH_OBJECT:
+        except self.ldap.NO_SUCH_OBJECT:
             logging.debug('__get_allowed_senders (not a mail list: %s) Returned (None)' % recipient)
             return None
         except Exception, e:
 
     def handle_data(self, map):
         if 'sender' in map.keys() and 'recipient' in map.keys():
-
             # Get plugin module name and convert plugin list to python list type.
             self.plugins = cfg.get('ldap', 'plugins', '')
             self.plugins = [v.strip() for v in self.plugins.split(',')]
                     try:
                         logging.debug('Apply plugin (%s).' % (module.__name__, ))
                         pluginAction = module.restriction(
-                                ldapConn=self.conn,
-                                ldapBaseDn=self.baseDN,
-                                ldapRecipientDn=recipientDn,
-                                ldapRecipientLdif=recipientLdif,
-                                smtpSessionData=map,
-                                )
+                            ldapConn=self.conn,
+                            ldapBaseDn=self.baseDN,
+                            ldapRecipientDn=recipientDn,
+                            ldapRecipientLdif=recipientLdif,
+                            smtpSessionData=map,
+                        )
 
                         logging.debug('Response from plugin (%s): %s' % (module.__name__, pluginAction))
                         if not pluginAction.startswith('DUNNO'):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.