aboutsummaryrefslogtreecommitdiff
blob: 688ea39503168d2d22ae681316ea8baaecfbd116 (plain)
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
#!/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]
root_path = setup_paths()

import bugs
import debian_support

def do_parse(f):
    names = {}
    errors = False
    try:
        for r in f:
            n = r.name
            if n[0:4] in ('CAN', 'CVE'):
                n = n[4:]
            if names.has_key(n):
                if names[n] <> r.name:
                    sys.stderr.write("error: duplicate CVE entry: %s and %s\n"
                                     % (names[n], r.name))
                else:
                    sys.stderr.write("error: duplicate CVE entry: %s\n"
                                     % r.name)
                errors = True
            names[n] = r.name
    except debian_support.ParseError, e:
        e.printOut(sys.stderr)
        errors = True
    if errors:
        sys.exit(1)

def construct(c, name):
    if name == '-':
        f = sys.stdin
        name = '<stdin>'
    else:
        f  = file(name)
    return c(name, f)
    

def parse_CVE(name):
    f = construct(bugs.CVEFile, name)
    # Relax syntax checking a bit.
    f.no_version_needs_note = False
    do_parse(f)

def parse_DSA(name):
    do_parse(construct(bugs.DSAFile, name))

def parse_DTSA(name):
    do_parse(construct(bugs.DTSAFile, name))

file_types = {'CVE' : parse_CVE,
              'DSA' : parse_DSA,
              'DTSA' : parse_DTSA}

if len(sys.argv) <> 3 or not file_types.has_key(sys.argv[1]):
    l = file_types.keys()
    l.sort()
    sys.stderr.write("usage: check-syntax {%s} file-name\n"
                     % '|'.join(l))
    sys.exit(1)

file_types[sys.argv[1]](sys.argv[2])