rthalley / dnspython

a powerful DNS toolkit for python
http://www.dnspython.org
Other
2.46k stars 519 forks source link

dns.zonefile.read_rrsets cannot handle lines with classes in them #1134

Closed paulehoffman closed 2 months ago

paulehoffman commented 2 months ago

Describe the bug dns.zonefile.read_rrsets cannot handle lines with classes in them

To Reproduce Using the three lines:

example1.tld. 900 in a 1.2.3.4
example2.tld. in 900 a 1.2.3.4
example3.tld. 900 a 1.2.3.4

Only the third line can be parsed. The first two get unknown rdatatype 'in'. All three are legitimate according to RFC 1035.

Context (please complete the following information):

paulehoffman commented 2 months ago

Sorry for not saying so above, but origin= and relativize= don't help. In fact, the third example on the doc page also fails with unknown rdatatype 'IN'.

rthalley commented 2 months ago

It can do it, you just need to tell it that's what you want, as by default it assumes you don't want classes at all (as this is more convenient for people say filling in a text box). To get what you want, just say rdclass=None in the call. This will make it not assume that the rdclass is always IN, but instead will try to parse it, and if not present will use the default_rdclass parameter.

import dns.zonefile

input = """example1.tld. 900 in a 1.2.3.4
example2.tld. in 900 a 1.2.3.4
example3.tld. 900 a 1.2.3.4"""

for rrs in dns.zonefile.read_rrsets(input, rdclass=None):
    print(rrs)
rthalley commented 2 months ago

Also the third example on the doc page works for me; did you have the rdclass=None?

rthalley commented 2 months ago

Also, I take responsibility for perhaps suboptimal API design here, but we're stuck with it now!

paulehoffman commented 2 months ago

Got it. The doc made it unclear that, if the input might have classes, you need rdclass=None.