summaryrefslogtreecommitdiffstats
path: root/bin/update-db
blob: 000ee00606c915e60d6d98630961f89afd88318d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
from __future__ import print_function

import os
import os.path
import string
import sys

def setup_paths():
    check_file = 'lib/python/debian_support.py'
    path = os.getcwd()
    while 1:
        if os.path.exists("%s/%s" % (path, check_file)):
            sys.path = [path + '/lib/python'] + sys.path
            return path
        idx = string.rfind(path, '/')
        if idx == -1:
            raise ImportError("could not setup paths")
        path = path[0:idx]
os.chdir(setup_paths())

import bugs
import debian_support
import security_db

db_file = sys.argv[1]
try:
    db = security_db.DB(db_file)
    new_file = False
except security_db.SchemaMismatch:
    os.unlink(db_file)
    db = security_db.DB(db_file, verbose=True)
    new_file = True
    
db.cursor().execute("PRAGMA synchronous = OFF")
cursor = db.writeTxn()

# Bug lists (CAN/CVE/DSA/DTSA)

try:
    warnings = db.readBugs(cursor, 'data')
except SyntaxError as e:
    if e.filename is None or e.lineno is None:
        print("error:", e)
    else:
        print("%s:%d: %s" % (e.filename, e.lineno, e.msg))
    sys.exit(1)
except debian_support.ParseError as e:
    e.printOut(sys.stderr)
    sys.exit(1)
except security_db.InsertError as e:
    for err in e.errors:
        print(err)
    sys.exit(1)
if warnings:
    for x in warnings:
        print(x)
    sys.exit(1)

# Packages

try:
    db.readPackages(cursor, 'data/packages')
except debian_support.ParseError as e:
    e.printOut(sys.stderr)
    sys.exit(1)

if new_file:
    db.commit(cursor)
    cursor = db.writeTxn()

# Calculate vulnerability information.

warnings = db.calculateVulnerabilities(cursor)
if warnings:
    for x in warnings:
        print(x)
    sys.exit(1)

# debsecan data

db.calculateDebsecan()

# Everything worked well.

db.commit(cursor)

© 2014-2024 Faster IT GmbH | imprint | privacy policy