summaryrefslogtreecommitdiffstats
path: root/bin/update-db
blob: b990ce84301882d7499f47ffe654dfd5c9993e6d (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
#!/usr/bin/python

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 = 'data/security.db'
try:
    db = security_db.DB(db_file, verbose=True)
    new_file = False
except security_db.SchemaMismatch:
    os.unlink(db_file)
    db = security_db.DB(db_file, verbose=True)
    new_file = True
    
cursor = db.writeTxn()

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

try:
    warnings = db.readBugs(cursor, 'data')
except debian_support.ParseError, e:
    e.printOut(sys.stderr)
    sys.exit(1)
except security_db.InsertError, e:
    for err in e.errors:
        print err
    sys.exit(1)
if warnings:
    for x in warnings:
        print x
    sys.exit(1)

# Packages

db.readPackages(cursor, 'data/packages')

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

# Removed packages

db.readRemovedPackages(cursor, 'data/packages/removed-packages')

# Calculate vulnerability information.

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

# Everything worked well.
    
db.commit(cursor)

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