| 1 |
<?xml version="1.0" encoding="UTF-8" ?> |
| 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 |
<xsl:stylesheet version="1.0" |
| 68 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 69 |
xmlns:htm="http://www.w3.org/1999/xhtml" |
| 70 |
xmlns:exsl="http://exslt.org/common" |
| 71 |
xmlns:tpl="http://open-scap.org/xml/fixtemplate#" |
| 72 |
xmlns:dyn="http://exslt.org/dynamic" |
| 73 |
xmlns="http://www.w3.org/1999/xhtml" |
| 74 |
xmlns:cdf="http://checklists.nist.gov/xccdf/1.2" |
| 75 |
> |
| 76 |
|
| 77 |
<xsl:import href="legacy-xccdf-share.xsl" /> |
| 78 |
|
| 79 |
<xsl:output method="text" encoding="UTF-8"/> |
| 80 |
|
| 81 |
|
| 82 |
<xsl:param name='result-id'/> |
| 83 |
<xsl:param name='profile' select='string(/cdf:Benchmark/cdf:TestResult[@id=$result-id]/cdf:profile/@idref)'/> |
| 84 |
<xsl:param name='template' select='"bash"'/> |
| 85 |
|
| 86 |
|
| 87 |
<xsl:variable name='tplfile'> |
| 88 |
<xsl:message>legacy-fix.xsl has been deprecated!</xsl:message> |
| 89 |
<xsl:choose> |
| 90 |
<xsl:when test='contains($template, ".")'> |
| 91 |
<xsl:if test='not(contains($template, "://") or starts-with($template, "/")) and $pwd'><xsl:value-of select='$pwd'/>/</xsl:if><xsl:value-of select='$template'/> |
| 92 |
</xsl:when> |
| 93 |
<xsl:otherwise>legacy-fixtpl-<xsl:value-of select='$template'/>.xml</xsl:otherwise> |
| 94 |
</xsl:choose> |
| 95 |
</xsl:variable> |
| 96 |
|
| 97 |
<xsl:variable name='tpl' select='document($tplfile)'/> |
| 98 |
<xsl:variable name='sys' select='concat(" ", $tpl/tpl:fixtemplate/@system, " ")'/> |
| 99 |
|
| 100 |
<xsl:variable name='dummy'> |
| 101 |
<xsl:if test='not($tpl)'><xsl:message terminate='yes'>Fix template '<xsl:value-of select='$template'/>' failed to load. Aborting.</xsl:message></xsl:if> |
| 102 |
</xsl:variable> |
| 103 |
|
| 104 |
<xsl:variable name='benchmark' select='$root'/> |
| 105 |
<xsl:variable name='testresult' select='$root/cdf:TestResult[@id=$result-id]'/> |
| 106 |
<xsl:variable name='dummy2'> |
| 107 |
<xsl:if test='$result-id and not($testresult)'><xsl:message terminate='yes'>No TestResult '<xsl:value-of select='$result-id'/>'. Aborting.</xsl:message></xsl:if> |
| 108 |
</xsl:variable> |
| 109 |
|
| 110 |
|
| 111 |
<xsl:key name='item' match='cdf:Rule|cdf:Group|cdf:Value' use='@id'/> |
| 112 |
|
| 113 |
|
| 114 |
<xsl:template match='/'> |
| 115 |
<xsl:call-template name='tpl.elem'><xsl:with-param name='elem' select='"before"'/></xsl:call-template> |
| 116 |
<xsl:choose> |
| 117 |
<xsl:when test='$testresult'> |
| 118 |
# Generating fixes for all failed rules in test result '<xsl:value-of select="$result-id"/>'. |
| 119 |
|
| 120 |
<xsl:apply-templates select='$testresult/cdf:rule-result[cdf:result="fail"]'/></xsl:when> |
| 121 |
<xsl:otherwise> |
| 122 |
# Generating fixes for all Rules that are selected in the default profile. |
| 123 |
|
| 124 |
<xsl:apply-templates select='$root//cdf:Rule[@selected="true" or @selected="1"]'/></xsl:otherwise> |
| 125 |
</xsl:choose> |
| 126 |
<xsl:call-template name='tpl.elem'><xsl:with-param name='elem' select='"after"'/></xsl:call-template> |
| 127 |
</xsl:template> |
| 128 |
|
| 129 |
<xsl:template match='cdf:Rule'> |
| 130 |
<xsl:variable name='fix' select='cdf:fix[contains($sys, concat(" ", @system, ""))][1]'/> |
| 131 |
<xsl:variable name='val'><xsl:apply-templates mode='text' select='$fix/node()'/></xsl:variable> |
| 132 |
|
| 133 |
<xsl:if test='$fix'> |
| 134 |
<xsl:choose> |
| 135 |
<xsl:when test='count($fix//cdf:instance) != 0'> |
| 136 |
<xsl:variable name='msg'>Skipping fix generation for rule <xsl:value-of select='@id'/> because it contains instance substitutions</xsl:variable> |
| 137 |
<xsl:message><xsl:value-of select='$msg'/></xsl:message> |
| 138 |
<xsl:call-template name='linecomment'><xsl:with-param name='content' select='$msg'/></xsl:call-template> |
| 139 |
</xsl:when> |
| 140 |
<xsl:otherwise> |
| 141 |
<xsl:call-template name='tpl.elem'> |
| 142 |
<xsl:with-param name='elem' select='"fixentry"'/> |
| 143 |
<xsl:with-param name='val' select='string($val)'/> |
| 144 |
<xsl:with-param name='fix' select='$fix'/> |
| 145 |
<xsl:with-param name='rule' select='.'/> |
| 146 |
</xsl:call-template> |
| 147 |
</xsl:otherwise> |
| 148 |
</xsl:choose> |
| 149 |
</xsl:if> |
| 150 |
</xsl:template> |
| 151 |
|
| 152 |
<xsl:template match='cdf:rule-result'> |
| 153 |
<xsl:variable name='rule' select='key("item", @idref)'/> |
| 154 |
<xsl:variable name='fix' select='(cdf:fix|$rule/cdf:fix)[contains($sys, concat(" ", @system, ""))][last()]'/> |
| 155 |
<xsl:variable name='val'><xsl:apply-templates mode='text' select='$fix/node()'/></xsl:variable> |
| 156 |
|
| 157 |
<xsl:if test='$fix'> |
| 158 |
<xsl:call-template name='tpl.elem'> |
| 159 |
<xsl:with-param name='elem' select='"fixentry"'/> |
| 160 |
<xsl:with-param name='val' select='string($val)'/> |
| 161 |
<xsl:with-param name='fix' select='$fix'/> |
| 162 |
<xsl:with-param name='rule' select='$rule'/> |
| 163 |
<xsl:with-param name='result' select='.'/> |
| 164 |
</xsl:call-template> |
| 165 |
</xsl:if> |
| 166 |
</xsl:template> |
| 167 |
|
| 168 |
<xsl:template name='linecomment'> |
| 169 |
<xsl:param name='content'/> |
| 170 |
<xsl:variable name='cnt' select='normalize-space($content)'/> |
| 171 |
<xsl:variable name='commentbeg' select='$tpl/tpl:fixtemplate/tpl:linecomment[1]'/> |
| 172 |
<xsl:if test='$cnt and $commentbeg'> |
| 173 |
<xsl:value-of select='$commentbeg'/><xsl:value-of select='$cnt'/><xsl:text>
</xsl:text> |
| 174 |
</xsl:if> |
| 175 |
</xsl:template> |
| 176 |
|
| 177 |
<xsl:template match='text()'><xsl:value-of select='normalize-space(.)'/></xsl:template> |
| 178 |
|
| 179 |
|
| 180 |
<xsl:template name='tpl.elem'> |
| 181 |
<xsl:param name='elem'/> |
| 182 |
<xsl:param name='val'/> |
| 183 |
<xsl:param name='fix'/> |
| 184 |
<xsl:param name='rule'/> |
| 185 |
<xsl:param name='result'/> |
| 186 |
|
| 187 |
<xsl:apply-templates mode='fixtpl' select='$tpl/tpl:fixtemplate/tpl:*[local-name()=$elem][1]'> |
| 188 |
<xsl:with-param name='val' select='$val'/> |
| 189 |
<xsl:with-param name='fix' select='$fix'/> |
| 190 |
<xsl:with-param name='rule' select='$rule'/> |
| 191 |
<xsl:with-param name='result' select='$result'/> |
| 192 |
</xsl:apply-templates> |
| 193 |
</xsl:template> |
| 194 |
|
| 195 |
<xsl:template mode='fixtpl' match='tpl:*'> |
| 196 |
<xsl:param name='val'/> |
| 197 |
<xsl:param name='rule'/> |
| 198 |
<xsl:param name='fix'/> |
| 199 |
<xsl:param name='result'/> |
| 200 |
<xsl:apply-templates mode='fixtpl' select='node()'> |
| 201 |
<xsl:with-param name='val' select='$val'/> |
| 202 |
<xsl:with-param name='rule' select='$rule'/> |
| 203 |
<xsl:with-param name='fix' select='$fix'/> |
| 204 |
<xsl:with-param name='result' select='$result'/> |
| 205 |
</xsl:apply-templates> |
| 206 |
</xsl:template> |
| 207 |
|
| 208 |
<xsl:template mode='fixtpl' match='tpl:sub'> |
| 209 |
<xsl:param name='val'/> |
| 210 |
<xsl:param name='rule'/> |
| 211 |
<xsl:param name='fix'/> |
| 212 |
<xsl:param name='result'/> |
| 213 |
<xsl:value-of select='dyn:evaluate(@select)'/> |
| 214 |
</xsl:template> |
| 215 |
|
| 216 |
<xsl:template mode='fixtpl' match='tpl:if'> |
| 217 |
<xsl:param name='val'/> |
| 218 |
<xsl:param name='rule'/> |
| 219 |
<xsl:param name='fix'/> |
| 220 |
<xsl:param name='result'/> |
| 221 |
<xsl:if test='dyn:evaluate(@test)'> |
| 222 |
<xsl:apply-templates mode='fixtpl' select='node()'> |
| 223 |
<xsl:with-param name='val' select='$val'/> |
| 224 |
<xsl:with-param name='rule' select='$rule'/> |
| 225 |
<xsl:with-param name='fix' select='$fix'/> |
| 226 |
<xsl:with-param name='result' select='$result'/> |
| 227 |
</xsl:apply-templates> |
| 228 |
</xsl:if> |
| 229 |
</xsl:template> |
| 230 |
|
| 231 |
<xsl:template mode='fixtpl' match='text()'><xsl:value-of select='.'/></xsl:template> |
| 232 |
|
| 233 |
|
| 234 |
</xsl:stylesheet> |