aboutsummaryrefslogtreecommitdiffstats
path: root/bin/common/srtool_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/common/srtool_utils.py')
-rwxr-xr-xbin/common/srtool_utils.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/bin/common/srtool_utils.py b/bin/common/srtool_utils.py
index e411c413..b48582dc 100755
--- a/bin/common/srtool_utils.py
+++ b/bin/common/srtool_utils.py
@@ -33,6 +33,8 @@ from common.srt_schema import ORM
# Setup:
verbose = False
+cmd_skip = 0
+cmd_count = 0
srtDbName = 'srt.sqlite'
@@ -110,10 +112,56 @@ def settings():
#################################
+# fix_new_reserved
+#
+
+# Is this reserved by Mitre? Is '** RESERVED **' within the first 20 char positions?
+def fix_new_reserved():
+ global cmd_skip
+ global cmd_count
+
+ conn = sqlite3.connect(srtDbName)
+ cur = conn.cursor()
+ cur_write = conn.cursor()
+
+ cur.execute('SELECT * FROM orm_cve WHERE status = "%s"' % ORM.STATUS_NEW)
+ i = 0
+ j = 0
+ for cve in cur:
+ i += 1
+
+ # Progress indicator support
+ if 0 == i % 10:
+ print('%05d: %20s\r' % (i,cve[ORM.CVE_NAME]), end='')
+ if (0 == i % 200):
+ conn.commit()
+ # Development/debug support
+ if cmd_skip:
+ if i < cmd_skip:
+ continue
+ if cmd_count:
+ if (i - cmd_skip) > cmd_count:
+ print("Count return: %s,%s" % (i,cmd_count))
+ break
+
+ reserved_pos = cve[ORM.CVE_DESCRIPTION].find('** RESERVED **')
+ if (0 <= reserved_pos) and (20 > reserved_pos):
+ print("STATUS_NEW_RESERVED:%s:%s:%s" % (cve[ORM.CVE_STATUS],cve[ORM.CVE_NAME],cve[ORM.CVE_DESCRIPTION][:40]))
+ sql = ''' UPDATE orm_cve
+ SET status = ?
+ WHERE id = ?'''
+ cur_write.execute(sql, (ORM.STATUS_NEW_RESERVED, cve[ORM.CVE_ID],))
+ j += 1
+ print("\nCVE COUNT=%5d,%5d" % (i,j))
+ conn.commit()
+
+#################################
# main loop
#
def main(argv):
global verbose
+ global cmd_skip
+ global cmd_count
# setup
parser = argparse.ArgumentParser(description='srtool.py: manage the SRTool database')
@@ -123,12 +171,20 @@ def main(argv):
parser.add_argument('--force', '-f', action='store_true', dest='force', help='Force the update')
parser.add_argument('--verbose', '-v', action='store_true', dest='verbose', help='Debugging: verbose output')
+ parser.add_argument('--skip', dest='skip', help='Debugging: skip record count')
+ parser.add_argument('--count', dest='count', help='Debugging: short run record count')
+
+ parser.add_argument('--fix-new-reserved', action='store_const', const='fix_new_reserved', dest='command', help='Reset new reserved CVEs to NEW_RESERVED')
args = parser.parse_args()
master_log = open(os.path.join(script_pathname, "update_logs/master_log.txt"), "a")
verbose = args.verbose
+ if None != args.skip:
+ cmd_skip = int(args.skip)
+ if None != args.count:
+ cmd_count = int(args.count)
if args.sources:
if args.sources.startswith('s'):
@@ -145,6 +201,8 @@ def main(argv):
sources('reset')
elif 'settings' == args.command:
settings()
+ elif 'fix_new_reserved' == args.command:
+ fix_new_reserved()
else:
print("Command not found")
master_log.close()