diff --git a/sddi-urban/Dockerfile b/sddi-urban/Dockerfile index 8ee135b..60c76f0 100644 --- a/sddi-urban/Dockerfile +++ b/sddi-urban/Dockerfile @@ -258,7 +258,7 @@ COPY supervisor/supervisord.conf /etc/supervisor COPY supervisor/start-supervisor.sh /srv/app/docker-afterinit.d # tmp debug clamav ##### -#COPY clamav/__init__.py /usr/local/lib/python3.8/dist-packages/clamd/__init__.py +COPY clamav/__init__.py /usr/local/lib/python3.8/dist-packages/clamd/__init__.py RUN set -ex && \ ckan config-tool "${CKAN_INI}" "ckan.plugins = ${CKAN__PLUGINS}" && \ diff --git a/sddi-urban/clamav/__init__.py b/sddi-urban/clamav/__init__.py index 7b51bb0..9941cd0 100644 --- a/sddi-urban/clamav/__init__.py +++ b/sddi-urban/clamav/__init__.py @@ -16,9 +16,6 @@ import contextlib import re import base64 -import logging - -log = logging.getLogger(__name__) scan_response = re.compile(r"^(?P.*): ((?P.+) )?(?P(FOUND|OK|ERROR))$") EICAR = base64.b64decode(b'WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5E' \ @@ -115,21 +112,12 @@ def shutdown(self): self._close_socket() def scan(self, file): - f = open('/srv/app/data/MB_clamd_init_01', 'w') - f.writelines('SCAN', file) - f.close() return self._file_system_scan('SCAN', file) def contscan(self, file): - f = open('/srv/app/data/MB_clamd_init_02', 'w') - f.writelines('CONTSCAN', file) - f.close() return self._file_system_scan('CONTSCAN', file) def multiscan(self, file): - f = open('/srv/app/data/MB_clamd_init_03', 'w') - f.writelines('MULTISCAN', file) - f.close() return self._file_system_scan('MULTISCAN', file) def _basic_command(self, command): @@ -174,15 +162,6 @@ def _file_system_scan(self, command, file): filename, reason, status = self._parse_response(result) dr[filename] = (status, reason) - f = open('/srv/app/data/MB_clamd_init_04', 'w') - f.writelines(result) - f.writelines(filename) - f.writelines(dr[filename]) - f.close() - f = open('/srv/app/data/MB_clamd_init_04_2', 'w') - f.writelines(dr) - f.close() - return dr finally: @@ -201,87 +180,34 @@ def instream(self, buff): - BufferTooLongError: if the buffer size exceeds clamd limits - ConnectionError: in case of communication problem """ - f = open('/srv/app/data/MB_clamav_instream_01', 'w') - f.writelines("self\n") - f.writelines(str(self)) - f.writelines("\n") - f.writelines("buff\n") - f.writelines(str(buff)) - f.writelines("\n") - f.close() - print("MB_clamav_instream_01") - #f.close() try: self._init_socket() - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_02\n") - f.close() self._send_command('INSTREAM') - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_03\n") - f.close() max_chunk_size = 1024 # MUST be < StreamMaxLength in /etc/clamav/clamd.conf chunk = buff.read(max_chunk_size) - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_04\n") - f.writelines("chunk\n") - f.writelines(str(chunk)) - f.writelines("\n") - f.close() + while chunk: - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_05\n") - f.close() + print('XXXXXXXXXXX 1') size = struct.pack(b'!L', len(chunk)) - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("size\n") - f.writelines(str(size)) - f.writelines("\n") - f.close() + print('XXXXXXXXXXX 2') + print(size) self.clamd_socket.send(size + chunk) chunk = buff.read(max_chunk_size) - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("chunk-2") - f.writelines(str(chunk)) - f.writelines("\n") - f.close() + print('XXXXXXXXXXX 3') self.clamd_socket.send(struct.pack(b'!L', 0)) - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_06\n") - f.close() result = self._recv_response() - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_07\n") - f.writelines("result\n") - f.writelines(str(result) + '\n') - f.close() if len(result) > 0: - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_08, len(result) > 0\n") - f.close() if result == 'INSTREAM size limit exceeded. ERROR': - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_08, INSTREAM size limit exceeded\n") - f.close() raise BufferTooLongError(result) filename, reason, status = self._parse_response(result) - f = open('/srv/app/data/MB_clamav_instream_01', 'a') - f.writelines("MB_clamav_instream_09\n") - f.writelines("filename\n") - f.writelines(str(filename) + '\n') - f.writelines("status\n") - f.writelines(str(status) + '\n') - f.writelines("reason\n") - f.writelines(str(reason) + '\n') - f.close() return {filename: (status, reason)} finally: