Esempio n. 1
0
    def _create_tmp(self):
        global PEER
        logging.critical("PEER in queue: %s", PEER)
        now = time.time()
        uniq = "%s.M%sP%sQ%s-%s-%s-%s" % (
            int(now),
            int(now % 1 * 1e6),
            os.getpid(),
            mailbox.Maildir._count,
            PEER[0],
            sensorName,
            USER,
        )
        path = os.path.join(self._path, 'tmp', uniq)
        try:
            os.stat(path)
        except OSError as e:
            if e.errno == errno.ENOENT:
                mailbox.Maildir._count += 1
                try:
                    return mailbox._create_carefully(path)
                except OSError as e:
                    if e.errno != errno.EEXIST:
                        raise
            else:
                raise

        # Fall through to here if stat succeeded or open raised EEXIST.
        raise mailbox.ExternalClashError(
            'Name clash prevented file creation: %s' % path)
Esempio n. 2
0
 def _create_tmp(self): #pragma NO COVERAGE
     """Create a file in the tmp subdirectory and open and return it."""
     # Skipping coverage because the mailbox module doesn't let us
     # hook the file creation.
     klass = self.__class__
     now = time.time()
     now_i, now_f = math.modf(now)
     hostname = socket.gethostname()
     if '/' in hostname:
         hostname = hostname.replace('/', r'\057')
     if ':' in hostname:
         hostname = hostname.replace(':', r'\072')
     uniq = "%010d.M%06dP%06dQ%06d.%s" % (now,
                                          now_f % 1e6,
                                          os.getpid(),
                                          klass._count,
                                          hostname)
     path = os.path.join(self._path, 'tmp', uniq)
     try:
         os.stat(path)
     except OSError, e:
         if e.errno == errno.ENOENT:
             klass._count += 1
             try:
                 return mailbox._create_carefully(path)
             except OSError, e:
                 if e.errno != errno.EEXIST:
                     raise
Esempio n. 3
0
    def add(self, message, copies=1):
        """Add message and return assigned key."""
        key = self._encryption_key_func()
        try:
            if key:
                es = EncryptingStreamer(key,
                                        dir=os.path.join(self._path, 'tmp'))
            else:
                es = ChecksummingStreamer(dir=os.path.join(self._path, 'tmp'))
            self._dump_message(message, es)
            es.finish()

            # We are using the MD5 to detect file system corruption, not in a
            # security context - so using as little as 40 bits should be fine.
            saved = False
            key = None
            for l in range(10, len(es.outer_md5sum)):
                key = es.outer_md5sum[:l]
                fn = os.path.join(self._path, 'new', key)
                if not os.path.exists(fn):
                    es.save(fn)
                    saved = self._toc[key] = os.path.join('new', key)
                    break
            if not saved:
                raise mailbox.ExternalClashError(_('Could not find a filename '
                                                   'for the message.'))

            for cpn in range(1, copies):
                fn = os.path.join(self._path, 'new', '%s.%s' % (key, cpn))
                es.save_copy(mailbox._create_carefully(fn))

            return key
        finally:
            es.close()
Esempio n. 4
0
    def _create_tmp(self):
        """Create a file in the tmp subdirectory and open and return it. This
        is an intentional override of the parent class, in an attempt to
        overcome the pid-based name generator that might cause conflicts when
        there are two operating threads in a single pid.
        """
        now = time.time()
        uniq = six.text_type(uuid.uuid4())
        uniq = "%sM%s_%s" % (int(now), int(now % 1 * 1e6), uniq)
        path = os.path.join(self._path, 'tmp', uniq)

        return mailbox._create_carefully(path)
Esempio n. 5
0
 def _create_tmp(self):
     now = time.time()
     uniq = "%s.M%sP%sQ%s.%s" % (int(now), int(now % 1 * 1e6), os.getpid(), mailbox.Maildir._count, HASHED_HOSTNAME)
     path = os.path.join(self._path, "tmp", uniq)
     try:
         os.stat(path)
     except OSError, e:
         if e.errno == errno.ENOENT:
             mailbox.Maildir._count += 1
             try:
                 return mailbox._create_carefully(path)
             except OSError, e:
                 if e.errno != errno.EEXIST:
                     raise
Esempio n. 6
0
 def _create_tmp(self):
     now = time.time()
     rand = binascii.hexlify(os.urandom(4)).decode()
     uniq = f"{now:.8f}.{rand}.eml"
     path = os.path.join(self._path, "tmp", uniq)
     try:
         os.stat(path)
     except FileNotFoundError:
         try:
             return mailbox._create_carefully(path)
         except FileExistsError:
             pass
     raise mailbox.ExternalClashError(
         f"name clash prevented file creation: {path}")
Esempio n. 7
0
 def _create_tmp(self):
     now = time.time()
     uniq = "%s.M%sP%sQ%s.%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
                                 mailbox.Maildir._count, HASHED_HOSTNAME)
     path = os.path.join(self._path, 'tmp', uniq)
     try:
         os.stat(path)
     except OSError, e:
         if e.errno == errno.ENOENT:
             mailbox.Maildir._count += 1
             try:
                 return mailbox._create_carefully(path)
             except OSError, e:
                 if e.errno != errno.EEXIST:
                     raise
Esempio n. 8
0
    def _create_tmp(self):
	global PEER
	logging.critical("PEER in queue: %s", PEER)				# Shiva - Appending IP address of source to file name
        now = time.time()
        uniq = "%s.M%sP%sQ%s-%s-%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
                                    mailbox.Maildir._count, PEER[0], sensorName) 
        path = os.path.join(self._path, 'tmp', uniq)
        try:
            os.stat(path)
        except OSError, e:
            if e.errno == errno.ENOENT:
                mailbox.Maildir._count += 1
                try:
                    return mailbox._create_carefully(path)
                except OSError, e:
                    if e.errno != errno.EEXIST:
                        raise
Esempio n. 9
0
    def _create_tmp(self):
        now = time.time()
        uniq = "%s.M%sP%sQ%s.%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
                                    mailbox.Maildir._count, HASHED_HOSTNAME)
        path = os.path.join(self._path, 'tmp', uniq)
        try:
            os.stat(path)
        except OSError as e:
            if e.errno == errno.ENOENT:
                mailbox.Maildir._count += 1
                try:
                    return mailbox._create_carefully(path)
                except OSError as e:
                    if e.errno != errno.EEXIST:
                        raise
            else:
                raise

        # Fall through to here if stat succeeded or open raised EEXIST.
        raise mailbox.ExternalClashError('Name clash prevented file creation: %s' % path)
Esempio n. 10
0
    def _create_tmp(self):
        now = time.time()
        uniq = "%s.M%sP%sQ%s.%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
                                    mailbox.Maildir._count, HASHED_HOSTNAME)
        path = os.path.join(self._path, 'tmp', uniq)
        try:
            os.stat(path)
        except OSError as e:
            if e.errno == errno.ENOENT:
                mailbox.Maildir._count += 1
                try:
                    return mailbox._create_carefully(path)
                except OSError as e:
                    if e.errno != errno.EEXIST:
                        raise
            else:
                raise

        # Fall through to here if stat succeeded or open raised EEXIST.
        raise mailbox.ExternalClashError('Name clash prevented file creation: %s' % path)
Esempio n. 11
0
    def _create_tmp(self):
	#from lamson.server import SMTPReceiver
	global PEER
	logging.critical("PEER in queue: %s", PEER)				# iSapm - Appending IP address of source to file name
        now = time.time()
        #uniq = "%s.M%sP%sQ%s.%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
                                    #mailbox.Maildir._count, HASHED_HOSTNAME)
        uniq = "%s.M%sP%sQ%s-%s-%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
                                    mailbox.Maildir._count, PEER[0], sensorName)		# iSpam - PEER get socket value ('10.91.1.139', 50474). Retrieving IP from it 
        path = os.path.join(self._path, 'tmp', uniq)
        try:
            os.stat(path)
        except OSError, e:
            if e.errno == errno.ENOENT:
                mailbox.Maildir._count += 1
                try:
                    return mailbox._create_carefully(path)
                except OSError, e:
                    if e.errno != errno.EEXIST:
                        raise
Esempio n. 12
0
    def add(self, message, copies=1):
        """Add message and return assigned key."""
        key = self._encryption_key_func()
        es = None
        try:
            tmpdir = os.path.join(self._path, 'tmp')
            if key:
                es = EncryptingStreamer(key,
                                        dir=tmpdir,
                                        name='WERVD',
                                        delimited=False)
            else:
                es = ChecksummingStreamer(dir=tmpdir, name='WERVD')
            self._dump_message(message, es)
            es.finish()

            # We are using the MD5 to detect file system corruption, not in a
            # security context - so using as little as 40 bits should be fine.
            saved = False
            key = None
            for l in range(10, len(es.outer_md5sum)):
                key = es.outer_md5sum[:l]
                fn = os.path.join(self._path, 'new', key)
                if not os.path.exists(fn):
                    es.save(fn)
                    saved = self._toc[key] = os.path.join('new', key)
                    break
            if not saved:
                raise mailbox.ExternalClashError(
                    _('Could not find a filename '
                      'for the message.'))

            for cpn in range(1, copies):
                fn = os.path.join(self._path, 'new', '%s.%s' % (key, cpn))
                with mailbox._create_carefully(fn) as ofd:
                    es.save_copy(ofd)

            return key
        finally:
            if es is not None:
                es.close()
Esempio n. 13
0
 def _create_tmp(self):
     #from lamson.server import SMTPReceiver
     global PEER
     logging.critical(
         "PEER in queue: %s",
         PEER)  # iSapm - Appending IP address of source to file name
     now = time.time()
     #uniq = "%s.M%sP%sQ%s.%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
     #mailbox.Maildir._count, HASHED_HOSTNAME)
     uniq = "%s.M%sP%sQ%s-%s-%s" % (
         int(now), int(now % 1 * 1e6), os.getpid(), mailbox.Maildir._count,
         PEER[0], sensorName
     )  # iSpam - PEER get socket value ('10.91.1.139', 50474). Retrieving IP from it
     path = os.path.join(self._path, 'tmp', uniq)
     try:
         os.stat(path)
     except OSError, e:
         if e.errno == errno.ENOENT:
             mailbox.Maildir._count += 1
             try:
                 return mailbox._create_carefully(path)
             except OSError, e:
                 if e.errno != errno.EEXIST:
                     raise
Esempio n. 14
0
 def update_event(self, inp=-1):
     self.set_output_val(0, mailbox._create_carefully(self.input(0)))