diff options
author | 2017-08-04 11:38:58 +0900 | |
---|---|---|
committer | 2017-08-04 11:38:58 +0900 | |
commit | c0c7575f6d41665c108e3c67a4f63beeeff25019 (patch) | |
tree | 1fe18f3f06d07d100ec49f93b6b690a3c320638a | |
parent | server/livepatch.py: run with dropped privileges (diff) | |
download | elivepatch-c0c7575f6d41665c108e3c67a4f63beeeff25019.tar.gz elivepatch-c0c7575f6d41665c108e3c67a4f63beeeff25019.tar.bz2 elivepatch-c0c7575f6d41665c108e3c67a4f63beeeff25019.zip |
initial work for sending multiple patches on the same post
-rw-r--r-- | elivepatch_client/client/checkers.py | 2 | ||||
-rw-r--r-- | elivepatch_client/client/restful.py | 22 | ||||
-rw-r--r-- | elivepatch_server/resources/dispatcher.py | 7 |
3 files changed, 19 insertions, 12 deletions
diff --git a/elivepatch_client/client/checkers.py b/elivepatch_client/client/checkers.py index 98d975f..2754a76 100644 --- a/elivepatch_client/client/checkers.py +++ b/elivepatch_client/client/checkers.py @@ -78,7 +78,7 @@ class Kernel(object): self.rest_manager.build_livepatch() def get_livepatch(self): - self.rest_manager.get_livepatch() + self.rest_manager.get_livepatch(self.patch_fullpath) class CVE(object): diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py index a5eefa5..987c917 100644 --- a/elivepatch_client/client/restful.py +++ b/elivepatch_client/client/restful.py @@ -7,7 +7,7 @@ import requests import os import shutil - +from elivepatch_client.client import patch import sys @@ -51,8 +51,11 @@ class ManaGer(object): 'UUID': self.uuid } # Static patch and config filename - files = {'patch': ('01.patch', open(patch_fullpath, 'rb'), 'multipart/form-data', {'Expires': '0'}), - 'config': ('config', open(temporary_config.name, 'rb'), 'multipart/form-data', {'Expires': '0'})} + patch_01 = open(patch_fullpath, 'rb') + files = [('patch', ('01.patch', patch_01, 'multipart/form-data', {'Expires': '0'})), + ('patch', ('02.patch', patch_01, 'multipart/form-data', {'Expires': '0'})), + ('patch', ('03.patch', patch_01, 'multipart/form-data', {'Expires': '0'})), + ('config', ('config', open(temporary_config.name, 'rb'), 'multipart/form-data', {'Expires': '0'}))] print(str(files)) temporary_config.close() try: @@ -62,8 +65,8 @@ class ManaGer(object): except requests.exceptions.ConnectionError as e: print('connection error: %s' % e) sys.exit(1) - except: - self.catching_exceptions_exit(self.send_file) + #except: + #self.catching_exceptions_exit(self.send_file) return response_dict def build_livepatch(self): @@ -78,8 +81,9 @@ class ManaGer(object): except: self.catching_exceptions_exit(self.build_livepatch) - def get_livepatch(self): + def get_livepatch(self, patch_folder): from io import BytesIO + patch_manager = patch.ManaGer() url = self.server_url+'/elivepatch/api/v1.0/send_livepatch' payload = { 'KernelVersion': self.kernel_version, @@ -100,12 +104,14 @@ class ManaGer(object): except: self.catching_exceptions_exit(self.get_livepatch) + elivepatch_uuid_dir = os.path.join('..', 'elivepatch-'+ self.uuid) + livepatch_fulldir = os.path.join(elivepatch_uuid_dir, 'livepatch.ko') if os.path.exists('myfile.ko'): - elivepatch_uuid_dir = os.path.join('..', 'elivepatch-'+ self.uuid) if not os.path.exists(elivepatch_uuid_dir): os.makedirs(elivepatch_uuid_dir) - shutil.move("myfile.ko", os.path.join(elivepatch_uuid_dir, 'livepatch.ko')) + shutil.copy("myfile.ko", livepatch_fulldir) print('livepatch saved in ' + elivepatch_uuid_dir + '/ folder') + patch_manager.load(patch_folder, livepatch_fulldir) else: print('livepatch not received') diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py index 70a62d7..3b67a95 100644 --- a/elivepatch_server/resources/dispatcher.py +++ b/elivepatch_server/resources/dispatcher.py @@ -147,7 +147,7 @@ class GetFiles(Resource): args = self.reqparse.parse_args() args['UUID'] = check_uuid(args['UUID']) parse = reqparse.RequestParser() - parse.add_argument('patch', type=werkzeug.datastructures.FileStorage, + parse.add_argument('patch', action='append', type=werkzeug.datastructures.FileStorage, location='files') parse.add_argument('config', type=werkzeug.datastructures.FileStorage, location='files') @@ -156,8 +156,9 @@ class GetFiles(Resource): configFile = file_args['config'] configFile_name = file_args['config'].filename - patchfile = file_args['patch'] - patchfile_name = file_args['patch'].filename + for patch in file_args['patch']: + patchfile = patch + patchfile_name = patch.filename configFile_name = os.path.join('/tmp','elivepatch-' + args['UUID'], configFile_name) if os.path.exists('/tmp/elivepatch-' + args['UUID']): |