Esempio n. 1
0
    def smtp_AUTH(self, arg):
        if 'PLAIN' in arg or self.auth_type == 'PLAIN':
            if arg == 'PLAIN':
                self.authenticating = True
                self.auth_type = 'PLAIN'
                self.push('334 ')
            else:
                split_args = arg.split(' ')
                if len(split_args) == 2:
                    auth_arg = split_args[1]
                else:
                    auth_arg = arg
                self.authenticating = False
                # second arg is Base64-encoded string of blah\0username\0password
                authbits = decode_b64(auth_arg).split('\0')
                self.username = authbits[1]
                self.password = authbits[2]
                if self.credential_validator and self.credential_validator.validate(
                        self.username, self.password):
                    self.authenticated = True
                    self.push('235 Authentication successful.')
                else:
                    self.push('454 Temporary authentication failure.')
                    raise ExitNow()
        elif 'LOGIN' in arg or self.auth_type == 'LOGIN':
            self.authenticating = True
            split_args = arg.split(' ')

            # Some implmentations of 'LOGIN' seem to provide the username
            # along with the 'LOGIN' stanza, hence both situations are
            # handled.
            if len(split_args) == 2:
                self.username = decode_b64(arg.split(' ')[1])
                self.push('334 ' + encode_b64('Username'))
            else:
                self.push('334 ' + encode_b64('Username'))
        elif not self.username:
            self.username = decode_b64(arg)
            self.push('334 ' + encode_b64('Password'))
            self.push('334 ' + encode_b64('Password'))
        else:
            self.authenticating = False
            self.password = decode_b64(arg)
            if self.credential_validator and self.credential_validator.validate(
                    self.username, self.password):
                self.authenticated = True
                self.push('235 Authentication successful.')
            else:
                self.push('454 Temporary authentication failure.')
                raise ExitNow()
Esempio n. 2
0
    def smtp_AUTH(self, arg):
        if 'LOGIN' in arg:
            self.authenticating = True
            split_args = arg.split(' ')

            # Some implmentations of 'LOGIN' seem to provide the username
            # along with the 'LOGIN' stanza, hence both situations are
            # handled.
            if len(split_args) == 2:
                self.username = base64.b64decode(arg.split(' ')[1])
                self.push('334 ' + base64.b64encode('Username'))
            else:
                self.push('334 ' + base64.b64encode('Username'))

        elif not self.username:
            self.username = base64.b64decode(arg)
            self.push('334 ' + base64.b64encode('Password'))
        else:
            self.authenticating = False
            self.password = base64.b64decode(arg)
            if self.credential_validator and self.credential_validator.validate(
                    self.username, self.password):
                self.authenticated = True
                self.push('235 Authentication successful.')
            else:
                self.push('454 Temporary authentication failure.')
                raise ExitNow()
Esempio n. 3
0
 def smtp_AUTH(self, arg):
     if 'PLAIN' in arg:
         split_args = arg.split(' ')
         self.smtp_server.auth_params = decode_b64(
             split_args[1]).split('\0')
         logging.getLogger("lucterios.mailing.test").info(
             "smtp_AUTH %s", self.smtp_server.auth_params)
         self.push('235 Authentication successful.')
     else:
         self.push('454 Temporary authentication failure.')
         raise ExitNow()
Esempio n. 4
0
    def smtp_AUTH(self, arg):
        if 'PLAIN' in arg:
            split_args = arg.split(' ')
            # second arg is Base64-encoded string of blah\0username\0password
            authbits = decode_b64(split_args[1]).split('\0')
            self.username = authbits[1]
            self.password = authbits[2]
            if self.credential_validator and self.credential_validator.validate(self.username, self.password):
                self.authenticated = True
                self.push('235 2.7.0 Authentication successful')
            else:
                self.push('454 Temporary authentication failure')
                raise ExitNow()

        elif 'LOGIN' in arg:
            self.authenticating = True
            split_args = arg.split(' ')

            # Some implmentations of 'LOGIN' seem to provide the username
            # along with the 'LOGIN' stanza, hence both situations are
            # handled.
            if len(split_args) == 2:
                self.username = decode_b64(arg.split(' ')[1])
                self.push('334 DYT3jf4sdDR5')
            else:
                self.push('334 DYT3jf4sdDR5')

        elif not self.username:
            self.username = decode_b64(arg)
            self.push('334 LIRdf2pekwW3')
        else:
            self.authenticating = False
            self.password = decode_b64(arg)
            if self.credential_validator and self.credential_validator.validate(self.username, self.password):
                self.authenticated = True
                self.push('235 2.7.0 Authentication successful')
            else:
                self.push('454 Temporary authentication failure')
                raise ExitNow()
Esempio n. 5
0
 def smtp_QUIT(self, arg):
     self.push('221 Bye')
     self.close_when_done()
     raise ExitNow()
    def found_terminator(self):
        line = EMPTYSTRING.join(self.__line)

        if self.debug:
            self.logger.info('found_terminator(): data: %s' % repr(line))

        self.__line = []
        if self.__state == self.COMMAND:
            if not line:
                self.push('500 Error: bad syntax')
                return
            method = None
            i = line.find(' ')

            if self.authenticating:
                # If we are in an authenticating state, call the
                # method smtp_AUTH.
                arg = line.strip()
                command = 'AUTH'
            elif i < 0:
                command = line.upper()
                arg = None
            else:
                command = line[:i].upper()
                arg = line[i + 1:].strip()

            # White list of operations that are allowed prior to AUTH.
            if not command in ['AUTH', 'EHLO', 'HELO', 'NOOP', 'RSET', 'QUIT']:
                if self.require_authentication and not self.authenticated:
                    self.push('530 Authentication required')
                    return

            method = getattr(self, 'smtp_' + command, None)
            if not method:
                self.push('502 Error: command "%s" not implemented' % command)
                return
            method(arg)
            return
        else:
            if self.__state != self.DATA:
                self.push('451 Internal confusion')
                return
            # Remove extraneous carriage returns and de-transparency according
            # to RFC 821, Section 4.5.2.
            data = []
            for text in line.split('\r\n'):
                if text and text[0] == '.':
                    data.append(text[1:])
                else:
                    data.append(text)
            self.__data = NEWLINE.join(data)

            if self.debug:
                self.logger.info(
                    "DATA: %s %s %s" %
                    (self.__mailfrom, self.username, self.password))
                self.logger.info(
                    "DATA: %s" % self.credential_validator.validate_mailfrom(
                        self.__mailfrom, self.username, self.password))

            # Control domain and address
            if self.credential_validator.validate_mailfrom(
                    self.__mailfrom, self.username, self.password):
                status = self.__server.process_message(self.__peer,
                                                       self.__mailfrom,
                                                       self.__rcpttos,
                                                       self.__data)
                self.__rcpttos = []
                self.__mailfrom = None
                self.__state = self.COMMAND
                self.set_terminator(b'\r\n')
                if not status:
                    self.push('250 Ok')
                else:
                    self.push(status)
            else:
                self.push('500 Error: No allow send email with %s' %
                          self.__mailfrom)
                raise ExitNow()