aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alice.ferrazzi@gmail.com>2017-08-23 01:18:24 +0900
committerAlice Ferrazzi <alice.ferrazzi@gmail.com>2017-08-23 01:18:24 +0900
commit16aec9ee51ae9eea52ab3d596f222716c08bb1b9 (patch)
tree18fc19ecde6a69b6bccd10b061f9c9d9e15daf7a
parentadded debug option to get_kernel_Sources function (diff)
downloadelivepatch-16aec9ee51ae9eea52ab3d596f222716c08bb1b9.tar.gz
elivepatch-16aec9ee51ae9eea52ab3d596f222716c08bb1b9.tar.bz2
elivepatch-16aec9ee51ae9eea52ab3d596f222716c08bb1b9.zip
added shelve db for remember already installed cve patch
readded __call__ as is throwing error without added clear argument for reset the shelve db for debug purpose
-rw-r--r--elivepatch_client/client/argsparser.py1
-rw-r--r--elivepatch_client/client/cli.py26
2 files changed, 25 insertions, 2 deletions
diff --git a/elivepatch_client/client/argsparser.py b/elivepatch_client/client/argsparser.py
index 5ee6590..c38af93 100644
--- a/elivepatch_client/client/argsparser.py
+++ b/elivepatch_client/client/argsparser.py
@@ -43,6 +43,7 @@ class ArgsParser(object):
parser.add_argument("-p","--patch", help="patch to convert.")
parser.add_argument("-k","--config", help="set kernel config file manually.")
parser.add_argument("-a","--kernel_version", help="set kernel version manually.")
+ parser.add_argument("-l","--clear", action='store_true', help="Clear the already installed cve db (Use with caution!).")
parser.add_argument("-u","--url", help="set elivepatch server url.")
parser.add_argument("-d","--debug", action='store_true', help="set the debug option.")
parser.add_argument("-v","--version", action='store_true', help="show the version.")
diff --git a/elivepatch_client/client/cli.py b/elivepatch_client/client/cli.py
index 800fc93..ee690ee 100644
--- a/elivepatch_client/client/cli.py
+++ b/elivepatch_client/client/cli.py
@@ -6,6 +6,7 @@
import sys
import os
+import shelve
from elivepatch_client.client.checkers import Kernel
from elivepatch_client.client import restful
@@ -42,10 +43,28 @@ class Main(object):
print("CVE repository already present.")
print("updating...")
# TODO: update repository
+ if config.clear:
+ os.remove('cve_ids')
cve_patch_list = cve_repository.cve_git_id()
- for cve_id, cve_patch in cve_patch_list:
- print(cve_id, cve_patch)
+ new_cve_patch_list = cve_patch_list
+ cve_previous_patch_list = []
+ # checking if we have a previous cve_ids list
+ if os.path.isfile('cve_ids'):
+ cve_db = shelve.open('cve_ids')
+ for i in (list(cve_db.keys())):
+ cve_previous_patch_list.append([i, cve_db[i]])
+ cve_db.close()
+ new_cve_patch_list = []
+ # checking if there is any new cve patch in the repository
+ for cve_patch_id in cve_patch_list:
+ if cve_patch_id not in cve_previous_patch_list:
+ new_cve_patch_list.append(cve_patch_id)
+ # converting new cve to live patch
+ for cve_id, cve_patch in new_cve_patch_list:
+ with shelve.open('cve_ids') as cve_db:
+ cve_db[cve_id] = cve_patch
livepatch(config.url, config.kernel_version, config.config, cve_patch, applied_patches_list)
+ print(new_cve_patch_list)
elif config.patch:
patch_manager = patch.ManaGer()
applied_patches_list = patch_manager.list(config.kernel_version)
@@ -58,6 +77,9 @@ class Main(object):
print('--help for help\n\
you need at list --patch or --cve')
+ def __call__(self):
+ pass
+
def livepatch(url, kernel_version, config, main_patch, incremental_patch_names_list):
"""