10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-10-30 05:24:26 +01:00

Fix: NXDOMAIN only when domain does not exist

This commit is contained in:
Xander Bil 2024-10-29 22:30:05 +01:00
parent 9c3d152618
commit a4bf483a82
No known key found for this signature in database
GPG key ID: EC9706B54A278598

View file

@ -35,18 +35,29 @@ impl ResponseHandler for QueryHandler {
match answers { match answers {
Ok(mut rrs) => { Ok(mut rrs) => {
if rrs.is_empty() { if rrs.is_empty() {
rrs.extend(try_wildcard(question, connection)?); let domain_records = get_from_database(
if rrs.is_empty() { &question.qname,
if question.qtype == Type::Type(RRType::SOA) None,
&& Config::get().default_soa question.qclass.clone(),
{ connection,
rrs.extend([get_soa(&question.qname)?]) )?;
} else {
return Err(ZNSError::NXDomain { if domain_records.is_empty() && !question.qname.is_empty() {
domain: question.qname.to_string(), rrs.extend(try_wildcard(question, connection)?);
qtype: question.qtype.clone(), }
});
} if rrs.is_empty()
&& question.qtype == Type::Type(RRType::SOA)
&& Config::get().default_soa
{
rrs.extend([get_soa(&question.qname)?])
}
if rrs.is_empty() && domain_records.is_empty() {
return Err(ZNSError::NXDomain {
domain: question.qname.to_string(),
qtype: question.qtype.clone(),
});
} }
} }
response.header.ancount += rrs.len() as u16; response.header.ancount += rrs.len() as u16;
@ -65,26 +76,20 @@ impl ResponseHandler for QueryHandler {
} }
fn try_wildcard(question: &Question, connection: &mut PgConnection) -> Result<Vec<RR>, ZNSError> { fn try_wildcard(question: &Question, connection: &mut PgConnection) -> Result<Vec<RR>, ZNSError> {
let records = get_from_database(&question.qname, None, question.qclass.clone(), connection)?; let qname = question.qname.clone().to_vec();
qname.to_vec()[0] = String::from("*");
if !records.is_empty() || question.qname.as_slice().is_empty() { Ok(get_from_database(
Ok(vec![]) &qname.into(),
} else { Some(question.qtype.clone()),
let qname = question.qname.clone().to_vec(); question.qclass.clone(),
qname.to_vec()[0] = String::from("*"); connection,
Ok(get_from_database( )?
&qname.into(), .into_iter()
Some(question.qtype.clone()), .map(|mut rr| {
question.qclass.clone(), rr.name.clone_from(&question.qname);
connection, rr
)? })
.into_iter() .collect())
.map(|mut rr| {
rr.name.clone_from(&question.qname);
rr
})
.collect())
}
} }
fn get_soa(name: &LabelString) -> Result<RR, ZNSError> { fn get_soa(name: &LabelString) -> Result<RR, ZNSError> {