Skip to content

Commit 0f36a98

Browse files
jdreedibauersachs
authored andcommitted
Add support for disabling $INCLUDE (dnsjava#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
1 parent f237c5b commit 0f36a98

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/main/java/org/xbill/DNS/Master.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class Master implements AutoCloseable {
2828
private Generator generator;
2929
private List<Generator> generators;
3030
private boolean noExpandGenerate;
31+
private boolean noExpandIncludes;
32+
private boolean includeThrowsException;
3133

3234
Master(File file, Name origin, long initialTTL) throws IOException {
3335
if (origin != null && !origin.isAbsolute()) {
@@ -314,6 +316,12 @@ else if ((token.value).charAt(0) == '$') {
314316
st.getEOL();
315317
continue;
316318
} else if (s.equalsIgnoreCase("$INCLUDE")) {
319+
if (noExpandIncludes) {
320+
if (includeThrowsException) {
321+
throw st.exception("$INCLUDE encountered, but processing disabled in strict mode");
322+
}
323+
continue;
324+
}
317325
String filename = st.getString();
318326
File newfile;
319327
if (file != null) {
@@ -391,6 +399,33 @@ else if ((token.value).charAt(0) == '$') {
391399
return rec;
392400
}
393401

402+
/**
403+
* Disable processing of $INCLUDE directives.
404+
* When disabled, $INCUDE statements will not be processed.
405+
* Depending on the contents of the file that would have been included,
406+
* this may cause the zone to be invalid.
407+
* (e.g. if there is no SOA or NS at the apex)
408+
*/
409+
public void
410+
disableIncludes() {
411+
disableIncludes(false);
412+
}
413+
414+
/**
415+
* Disable processing of $INCLUDE directives.
416+
* When disabled, $INCUDE statements will not be processed.
417+
* Depending on the contents of the file that would have been included,
418+
* this may cause the zone to be invalid.
419+
* (e.g. if there's no SOA or NS at the apex)
420+
*
421+
* @param strict If true, an exception will be thrown if $INCLUDE is encountered.
422+
*/
423+
public void
424+
disableIncludes(boolean strict) {
425+
noExpandIncludes = true;
426+
includeThrowsException = strict;
427+
}
428+
394429
/**
395430
* Specifies whether $GENERATE statements should be expanded. Whether
396431
* expanded or not, the specifications for generated records are available

0 commit comments

Comments
 (0)