Skip to content
Permalink
Browse files

Add support for disabling $INCLUDE (#67)

* Add support for disabling $INCLUDE

  - Add support for disabling $INCLUDE when parsing master files

* disableIncludes(): call overload

  - Don't assign to the variables directly
  • Loading branch information...
jdreed authored and ibauersachs committed Jul 14, 2019
1 parent f237c5b commit 0f36a98cd96344fd030fff997e74ae990cc54793
Showing with 35 additions and 0 deletions.
  1. +35 −0 src/main/java/org/xbill/DNS/Master.java
@@ -28,6 +28,8 @@
private Generator generator;
private List<Generator> 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

0 comments on commit 0f36a98

Please sign in to comment.
You can’t perform that action at this time.