Source

iredapd / libs / ldap_conn_utils.py

Diff from to

File libs/ldap_conn_utils.py

 import settings
 from libs import SMTP_ACTIONS
 
+
 def get_account_ldif(conn, account, attrlist=None):
     logging.debug('[+] Getting LDIF data of account: %s' % account)
 
 
     logging.debug('search filter: %s' % ldap_filter)
     logging.debug('search attributes: %s' % str(attrlist))
-    #if attrlist:
-    #    logging.debug('search attributes: %s' % str(attrlist))
-    #else:
-    #    # Attribute list must be None if it's a empty list.
-    #    attrlist = None
+    if not isinstance(attrlist, list):
+        # Attribute list must be None or non-empty list
+        attrlist = None
 
     try:
         result = conn.search_s(settings.ldap_basedn,
         logging.debug('!!! ERROR !!! result: %s' % str(e))
         return (None, None)
 
+
 def get_allowed_senders_of_mail_list(conn,
                                      base_dn,
                                      dn_of_mail_list,
         searchFilter = "(&(|(objectclass=mailUser)(objectClass=mailExternalUser))(accountStatus=active)(memberOfGroup=%s))" % (recipient, )
 
         # Get both mail and shadowAddress.
-        searchAttrs = ['mail', 'shadowAddress',]
+        searchAttrs = ['mail', 'shadowAddress', ]
 
     elif policy in ['allowedonly', 'moderatorsonly', 'moderators']:
         # Get mail list moderators.
         # Policy: policy==membersAndModeratorsOnly or not set.
         # Filter used to get both members and moderators.
         searchFilter = "(|(&(|(objectClass=mailUser)(objectClass=mailExternalUser))(memberOfGroup=%s))(&(objectclass=mailList)(mail=%s)))" % (recipient, recipient, )
-        searchAttrs = ['mail', 'shadowAddress', 'listAllowedUser',]
+        searchAttrs = ['mail', 'shadowAddress', 'listAllowedUser', ]
 
     logging.debug('base dn: %s' % basedn)
     logging.debug('search scope: %s' % searchScope)
                 searchFilter += '(mail=%s)' % i
             searchFilter += '))'
 
-            searchAttrs = ['shadowAddress',]
+            searchAttrs = ['shadowAddress', ]
 
             logging.debug('base dn: %s' % basedn)
             logging.debug('search scope: 2 (ldap.SCOPE_SUBTREE)')
 
             try:
                 resultOfShadowAddresses = conn.search_s(
-                    'ou=Users,'+domaindn,
+                    'ou=Users,' + domaindn,
                     2,  # ldap.SCOPE_SUBTREE
                     searchFilter,
-                    ['mail', 'shadowAddress',],
+                    ['mail', 'shadowAddress', ],
                 )
 
                 for obj in resultOfShadowAddresses:
         logging.debug('Error: %s' % str(e))
         return []
 
+
 def apply_plugin(plugin, **kwargs):
     action = SMTP_ACTIONS['default']
 
         logging.debug('<!> Error: %s' % str(e))
 
     return action
-