[Oval-commits] r96 - trunk/tools/oval/definition
Pavel Vinogradov
blaze-guest at alioth.debian.org
Thu Aug 2 08:16:45 UTC 2007
Author: blaze-guest
Date: 2007-08-02 08:16:45 +0000 (Thu, 02 Aug 2007)
New Revision: 96
Modified:
trunk/tools/oval/definition/generator.py
Log:
Implement proper release test generation. Some optimizations.
Modified: trunk/tools/oval/definition/generator.py
===================================================================
--- trunk/tools/oval/definition/generator.py 2007-08-01 17:46:42 UTC (rev 95)
+++ trunk/tools/oval/definition/generator.py 2007-08-02 08:16:45 UTC (rev 96)
@@ -56,7 +56,7 @@
statesCurId = 1
releaseArchHash = {"2.0" : 2, "2.1" : 4, "2.2": 6, "3.0" : 11, "3.1" : 12, "4.0" : 11}
-testsHash = {"arch" : {}, "release": {}, "dpkgObj": {}, "dpkgSte": {}}
+testsHash = {"arch" : {}, "release": {}, "obj": {}, "fileSte": {}, "dpkgSte": {}}
def __trimzero (val):
value = val[:]
@@ -88,10 +88,10 @@
return (result)
-def __createOVALObject (name):
- """ Generate OVAL object definition """
+def __createOVALDpkginfoObject (name):
+ """ Generate OVAL dpkginfo_object definition """
- if not testsHash["dpkgObj"].has_key(name):
+ if not testsHash["obj"].has_key(name):
objectId = __getNewId ("object");
object = __createXMLElement("dpkginfo_object",
attrs={"id":objectId,
@@ -100,10 +100,29 @@
object.appendChild ( __createXMLElement ("name", name))
objects.appendChild (object)
- testsHash["dpkgObj"][name] = objectId
+ testsHash["obj"][name] = objectId
- return (testsHash["dpkgObj"][name])
+ return (testsHash["obj"][name])
+def __createOVALTextfilecontentObject (pattern, path = "/etc", filename = "debian_version"):
+ """ Generate OVAL textfilecontent_object definition """
+ name = path + filename + pattern
+
+ if not testsHash["obj"].has_key(name):
+ objectId = __getNewId ("object");
+ object = __createXMLElement("textfilecontent_object",
+ attrs={"id":objectId,
+ "version":"1",
+ "xmlns":"http://oval.mitre.org/XMLSchema/oval-definitions-5#independent"})
+ object.appendChild ( __createXMLElement ("path", path))
+ object.appendChild ( __createXMLElement ("filename", filename))
+ object.appendChild ( __createXMLElement ("line", pattern, attrs={"operation" : "pattern match"}))
+ objects.appendChild (object)
+
+ testsHash["obj"][name] = objectId
+
+ return (testsHash["obj"][name])
+
def __createOVALState (value, operation = "less than"):
""" Generate OVAL state definition
@@ -126,6 +145,27 @@
return (testsHash["dpkgSte"][operation][value])
+def __createOVALTextfilecontentState (value, operation = "equals"):
+ """ Generate OVAL state definition
+
+ Use state hash for optimization of resulted XML
+ """
+ #TODO: Add arch state generation
+ if not testsHash["fileSte"].has_key(operation) or not testsHash["fileSte"][operation].has_key(value):
+ stateId = __getNewId ("state")
+
+ state = __createXMLElement("textfilecontent_state",
+ attrs={"id":stateId,
+ "version":"1",
+ "xmlns":"http://oval.mitre.org/XMLSchema/oval-definitions-5#independent"})
+ state.appendChild ( __createXMLElement ("line", value,
+ {"operation":operation}))
+ states.appendChild (state)
+
+ testsHash["fileSte"][operation] = {value : stateId}
+
+ return (testsHash["fileSte"][operation][value])
+
def __createDPKGTest(name, version):
""" Generate OVAL DPKG test """
@@ -138,28 +178,43 @@
"comment":"%s is earlier than %s" % (name, version),
"xmlns":"http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
})
- test.appendChild ( __createXMLElement("object", attrs={"object_ref" : __createOVALObject (name)}))
+ test.appendChild ( __createXMLElement("object", attrs={"object_ref" : __createOVALDpkginfoObject (name)}))
test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALState (version)}))
tests.appendChild(test)
return (ref)
+def __createArchTest (arch, packages):
+ ref = __getNewId("test")
+
def __createTest(testType, value):
- """ Generate OVAL test for debian_version or architecture cases"""
+ """ Generate OVAL test for release or architecture cases"""
if not testsHash[testType].has_key(value):
comment = None
-
+
ref = __getNewId("test")
if testType == "release":
- objectId = __createOVALObject ("debian_version")
+ objectId = __createOVALTextfilecontentObject ("\d\.\d")
comment = "Debian GNU/Linux %s is installed" % value
+
+ test = __createXMLElement("textfilecontent_test",
+ attrs={"id":ref,
+ "version":"1",
+ "check":"all",
+ "check_existence":"at_least_one_exists",
+ "comment":comment,
+ "xmlns":"http://oval.mitre.org/XMLSchema/oval-definitions-5#independent"
+ })
+ test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
+ test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALTextfilecontentState (value, "equals")}))
+
else:
- objectId = __createOVALObject ("architecture")
+ objectId = __createOVALDpkginfoObject ("architecture")
comment = "Installed architecture is %s" % value
- test = __createXMLElement("dpkginfo_test",
+ test = __createXMLElement("dpkginfo_test",
attrs={"id":ref,
"version":"1",
"check":"all",
@@ -167,9 +222,9 @@
"comment":comment,
"xmlns":"http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
})
+ test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
+ test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALState (value, "equals")}))
- test.appendChild ( __createXMLElement("object", attrs={"object_ref" : objectId}))
- test.appendChild ( __createXMLElement("state", attrs={"state_ref" : __createOVALState (value, "equals")}))
tests.appendChild(test)
testsHash[testType][value] = ref
@@ -352,13 +407,17 @@
definition.appendChild ( metadata )
### Definition : Criteria ###
- platformCriteria = __createXMLElement ("criteria", attrs = {"comment" : "Platform section", "operator" : "OR"})
+ if len(dsaref["release"]) > 1:
+ #f we have more than one release - generate additional criteria section
+ platformCriteria = __createXMLElement ("criteria", attrs = {"comment" : "Platform section", "operator" : "OR"})
+ definition.appendChild (platformCriteria)
+ else:
+ platformCriteria = definition
for platform in dsaref["release"]:
data = dsaref["release"][platform]
platformCriteria.appendChild (createPlatformDefinition(platform, data, dsa))
-
- definition.appendChild (platformCriteria)
+
### Definition : Criteria END ###
return (definition)
@@ -375,13 +434,14 @@
root = __createXMLElement ("oval_definitions",
attrs= {
- "xsi:schemaLocation" : "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd",
- "xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
+ "xsi:schemaLocation" : "http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd",
+ "xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
+ "xmlns:ind-def " : "http://oval.mitre.org/XMLSchema/oval-definitions-5#independent",
"xmlns:linux-def" : "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux",
"xmlns:oval-def" : "http://oval.mitre.org/XMLSchema/oval-definitions-5",
"xmlns:unix-def" : "http://oval.mitre.org/XMLSchema/oval-definitions-5#unix",
- "xmlns" : "http://oval.mitre.org/XMLSchema/oval-definitions-5",
- "xmlns:oval" : "http://oval.mitre.org/XMLSchema/oval-common-5"
+ "xmlns" : "http://oval.mitre.org/XMLSchema/oval-definitions-5",
+ "xmlns:oval" : "http://oval.mitre.org/XMLSchema/oval-common-5"
}
)
doc.appendChild (root)
More information about the Oval-commits
mailing list