Commits

Zhang Huangbin committed 91d72b1

Fixed: check returned sender/recipient LDIF data first.

Comments (0)

Files changed (4)

libs/ldaplib/modeler.py

                          'recipient': recipient,
                          'recipient_domain': recipient.split('@', 1)[-1],
                          'sender_dn': None,
-                         'sender_ldif': None,
+                         'sender_ldif': {},
                          'recipient_dn': None,
-                         'recipient_ldif': None}
+                         'recipient_ldif': {}}
 
         # TODO Perform addition plugins which don't require sender/recipient info
         # e.g.

plugins/ldap_amavisd_block_blacklisted_senders.py

     smtp_session_data = kwargs['smtp_session_data']
     recipient_ldif = kwargs['recipient_ldif']
 
-    if not 'amavisAccount' in recipient_ldif['objectClass']:
+    if not 'amavisAccount' in recipient_ldif.get('objectClass', []):
         return 'DUNNO (Not a amavisdAccount object)'
 
     sender = smtp_session_data.get('sender').lower()

plugins/ldap_maillist_access_policy.py

 
 
 def restriction(**kwargs):
+    recipient_ldif = kwargs['recipient_ldif']
+
+    # Return if recipient is not a mail list object.
+    if not 'mailList' in recipient_ldif.get('objectClass', []):
+        return 'DUNNO (Not mail list)'
+
     conn = kwargs['conn']
     base_dn = kwargs['base_dn']
     sender = kwargs['sender']
     recipient = kwargs['recipient']
     recipient_dn = kwargs['recipient_dn']
-    recipient_ldif = kwargs['recipient_ldif']
-
-    # Return if recipient is not a mail list object.
-    if not 'mailList' in recipient_ldif['objectClass']:
-        return 'DUNNO (Not mail list)'
 
     recipient_alias_domains = []
-
     policy = recipient_ldif.get('accessPolicy', ['public'])[0].lower()
 
     # Log access policy and description

plugins/ldap_recipient_restrictions.py

 # Author:   Zhang Huangbin <zhb _at_ iredmail.org>
-# Updated:  2012-12-30
-# Purpose:  Check whether local user (sender) is allowed to mail to recipient
+# Purpose:  Check whether local user (sender) is allowed to mail to recipient.
 
 # Value of mailWhitelistRecipient and mailBlacklistRecipient:
 #   - Single address:   user@domain.ltd
 
 def restriction(**kwargs):
     sender_ldif = kwargs['sender_ldif']
-    smtp_session_data = kwargs['smtp_session_data']
+    if not sender_ldif:
+        return 'DUNNO (Sender is Not a local mail user.)'
 
     # Get recipient address.
+    smtp_session_data = kwargs['smtp_session_data']
     recipient = smtp_session_data.get('recipient').lower()
     splited_recipient_domain = str(recipient.split('@')[-1]).split('.')
 
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.