Author: fw Date: 2006-04-23 12:46:41 +0000 (Sun, 23 Apr 2006) New Revision: 3858 Modified: lib/python/bugs.py lib/python/security_db.py Log: Add support for no-dsa handling to the database. This is still preliminary. lib/python/bugs.py (PackageNoteNoDSA): New class. (BugBase.__init__): Losen assert to include PackageNoteNoDSA. (FileBase.__iter__): Create PackageNoteNoDSA objects. lib/python/security_db.py (DB): Bump schema version to 21. Add package_notes_nodsa table. Add schema migration code. (DB.readBugs): Clear package_notes_nodsa table. Modified: lib/python/bugs.py ==================================================================--- lib/python/bugs.py 2006-04-23 12:39:52 UTC (rev 3857) +++ lib/python/bugs.py 2006-04-23 12:46:41 UTC (rev 3858) @@ -219,6 +219,27 @@ PackageNote.__init__(self, package, version, release, urgency) self.bugs = bugs +class PackageNoteNoDSA: + def __init__(self, package, release, comment, reason=None): + assert type(package) == types.StringType and package <> '''' + assert type(release) == types.StringType and release <> '''' + assert type(comment) == types.StringType + if not reason: + reason = '''' + else: + assert type(reason) == types.StringType + self.package = package + self.release = release + self.comment = comment + self.reason = reason + + def writeDB(self, cursor, bug_name): + cursor.execute("""INSERT INTO package_notes_nodsa + (bug_name, package, release, comment, reason) + VALUES (?, ?, ?, ?, ?)""", + (bug_name, self.package, self.release, + self.comment, self.reason)) + class BugBase: "Base class for entries in the bug list.""" @@ -312,7 +333,9 @@ def __init__(self, fname, lineno, date, name, description, comments, notes, xref, not_for_us=False): - assert len(notes) == 0 or isinstance(notes[0], PackageNote) + for n in notes: + assert isinstance(n, PackageNote) \ + or isinstance(n, PackageNoteNoDSA) assert len(xref) == 0 or type(xref[0]) == types.StringType assert type(not_for_us) == types.BooleanType BugBase.__init__(self, fname, lineno, date, name, @@ -622,14 +645,14 @@ r = r[:-1] comments.append((''NOTE'', r)) elif v == ''no-dsa'': - pkg_notes.append(PackageNoteParsed - (p, None, ''low'', - release=release)) - if d: - # See above. - if r[-1] == ''\n'': - r = r[:-1] - comments.append((''NOTE'', r)) + if not release: + self.raiseSyntaxError( + "no-dsa note needs release specification", + lineno) + pkg_notes.append(PackageNoteNoDSA( + release=release, + package=p, + comment=d)) elif v == ''itp'': x = PackageNoteParsed(p, None, d, release=release) x.package_kind = ''itp'' Modified: lib/python/security_db.py ==================================================================--- lib/python/security_db.py 2006-04-23 12:39:52 UTC (rev 3857) +++ lib/python/security_db.py 2006-04-23 12:46:41 UTC (rev 3858) @@ -113,13 +113,15 @@ self.db = apsw.Connection(name) self.verbose = verbose - self.schema_version = 20 + self.schema_version = 21 self._initFunctions() c = self.cursor() for (v,) in c.execute("PRAGMA user_version"): if v == 0: self.initSchema() + elif v == 20: + self._initSchema20() elif v <> self.schema_version: if self.verbose: print "DB: schema version mismatch: expected %d, got %d" \ @@ -319,7 +321,39 @@ (name TEXT NOT NULL PRIMARY KEY, data TEXT NOT NULL)""") + self._initNoDSA(cursor) + self._initViews(cursor) + + cursor.execute("PRAGMA user_version = %d" % self.schema_version) + + def _initSchema20(self): + cursor = self.db.cursor() + + cursor.execute("PRAGMA user_version = 1") + self._initNoDSA(cursor) + self._initViews(cursor) + cursor.execute("DELETE FROM inodeprints WHERE file =''data/CVE/list''") + cursor.execute("PRAGMA user_version = %d" % self.schema_version) + + def _initNoDSA(self, cursor): cursor.execute( + """CREATE TABLE package_notes_nodsa + (bug_name TEXT NOT NULL, + package TEXT NOT NULL, + release TEXT NOT NULL, + reason TEXT NOT NULL, + comment TEXT NOT NULL, + PRIMARY KEY (bug_name, package, release)) + """) + + def _initViews(self, cursor): + for view in (''testing_status'', ''stable_status'', ''oldstable_status''): + try: + cursor.execute(''DROP VIEW '' + view) + except apsw.SQLError: + pass + + cursor.execute( """CREATE VIEW testing_status AS SELECT DISTINCT sp.name AS package, st.bug_name AS bug, sp.archive AS section, st.urgency AS urgency, @@ -351,7 +385,11 @@ SELECT DISTINCT sp.name AS package, st.bug_name AS bug, sp.archive AS section, st.urgency AS urgency, (SELECT range_remote FROM nvd_data - WHERE cve_name = st.bug_name) AS remote + WHERE cve_name = st.bug_name) AS remote, + (EXISTS (SELECT * FROM package_notes_nodsa AS pnd + WHERE pnd.bug_name = st.bug_name + AND pnd.package = sp.name + AND pnd.release = ''%s'')) AS no_dsa FROM source_package_status AS st, source_packages AS sp WHERE st.vulnerable AND st.urgency <> ''unimportant'' AND sp.rowid = st.package AND sp.release = ''%s'' @@ -364,9 +402,9 @@ AND secst.bug_name = st.bug_name AND secst.package = secp.rowid), 0) ORDER BY sp.name, urgency_to_number(urgency), st.bug_name""" - % (name, nickname, nickname)) + % (name, nickname, nickname, nickname)) - cursor.execute("PRAGMA user_version = %d" % self.schema_version) + def _initFunctions(self): """Registers user-defined SQLite functions.""" @@ -638,7 +676,7 @@ source, source_version, archs) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""", gen()) - + def readBugs(self, cursor, path): if self.verbose: print "readBugs:" @@ -655,6 +693,7 @@ cursor.execute("DELETE FROM package_notes") cursor.execute("DELETE FROM bugs_notes") cursor.execute("DELETE FROM bugs_xref") + cursor.execute("DELETE FROM package_notes_nodsa") # The *_status tables are regenerated anyway, no need to # delete them here.