Skip to content

Commit

Permalink
Add support for disabling $INCLUDE (#67)
Browse files Browse the repository at this point in the history
* 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 0f36a98
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main/java/org/xbill/DNS/Master.java
Expand Up @@ -28,6 +28,8 @@ public class Master implements AutoCloseable {
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()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0f36a98

Please sign in to comment.