diff --git a/src/main/java/org/xbill/DNS/Master.java b/src/main/java/org/xbill/DNS/Master.java index ab1576724..b6c683e8a 100644 --- a/src/main/java/org/xbill/DNS/Master.java +++ b/src/main/java/org/xbill/DNS/Master.java @@ -28,6 +28,8 @@ public class Master implements AutoCloseable { private Generator generator; private List generators; private boolean noExpandGenerate; +private boolean noExpandIncludes; +private boolean includeThrowsException; Master(File file, Name origin, long initialTTL) throws IOException { if (origin != null && !origin.isAbsolute()) { @@ -314,6 +316,12 @@ else if ((token.value).charAt(0) == '$') { st.getEOL(); continue; } else if (s.equalsIgnoreCase("$INCLUDE")) { + if (noExpandIncludes) { + if (includeThrowsException) { + throw st.exception("$INCLUDE encountered, but processing disabled in strict mode"); + } + continue; + } String filename = st.getString(); File newfile; if (file != null) { @@ -391,6 +399,33 @@ else if ((token.value).charAt(0) == '$') { return rec; } +/** + * Disable processing of $INCLUDE directives. + * When disabled, $INCUDE statements will not be processed. + * Depending on the contents of the file that would have been included, + * this may cause the zone to be invalid. + * (e.g. if there is no SOA or NS at the apex) + */ +public void +disableIncludes() { + disableIncludes(false); +} + +/** + * Disable processing of $INCLUDE directives. + * When disabled, $INCUDE statements will not be processed. + * Depending on the contents of the file that would have been included, + * this may cause the zone to be invalid. + * (e.g. if there's no SOA or NS at the apex) + * + * @param strict If true, an exception will be thrown if $INCLUDE is encountered. + */ +public void +disableIncludes(boolean strict) { + noExpandIncludes = true; + includeThrowsException = strict; +} + /** * Specifies whether $GENERATE statements should be expanded. Whether * expanded or not, the specifications for generated records are available