10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-10-29 21:14:27 +01:00

fix case sensitive and better error logging

This commit is contained in:
Xander Bil 2024-07-15 22:17:33 +02:00
parent 05daa4e8fe
commit 50640d859e
No known key found for this signature in database
GPG key ID: EC9706B54A278598
4 changed files with 19 additions and 9 deletions

View file

@ -3,6 +3,7 @@ use crate::{
structs::{Class, Type, RR},
};
use diesel::prelude::*;
use diesel::sql_types::Text;
use self::schema::records::{self};
@ -31,6 +32,10 @@ struct Record {
pub rdata: Vec<u8>,
}
sql_function! {
fn lower(x: Text) -> Text;
}
impl Record {
pub fn get(
db: &mut PgConnection,
@ -40,7 +45,11 @@ impl Record {
) -> Result<Vec<Record>, diesel::result::Error> {
let mut query = records::table.into_boxed();
query = query.filter(records::name.eq(name).and(records::class.eq(class)));
query = query.filter(
lower(records::name)
.eq(name.to_lowercase())
.and(records::class.eq(class)),
);
if let Some(value) = _type {
query = query.filter(records::_type.eq(value))

View file

@ -1,6 +1,6 @@
use thiserror::Error;
use crate::structs::RCODE;
use crate::structs::{Type, RCODE};
#[derive(Error, Debug)]
pub enum ZNSError {
@ -17,8 +17,8 @@ pub enum ZNSError {
#[error("DNS Query Format Error: {message:?}")]
Formerr { message: String },
#[error("Domain name does not exist")]
NXDomain { domain: String },
#[error("Domain name does not exist: {qtype:?} {domain:?}")]
NXDomain { domain: String, qtype: Type },
#[error("NotImplemented Error for {object:?}: {message:?}")]
NotImp { object: String, message: String },
#[error("Authentication Error: {message:?}")]
@ -35,10 +35,10 @@ impl ZNSError {
}
ZNSError::Database { .. } | ZNSError::Reqwest(_) => RCODE::SERVFAIL,
ZNSError::NotAuth { .. } | ZNSError::PublicKey { .. } => RCODE::NOTAUTH,
ZNSError::NotAuth { .. } => RCODE::NOTAUTH,
ZNSError::NXDomain { .. } => RCODE::NXDOMAIN,
ZNSError::NotImp { .. } => RCODE::NOTIMP,
ZNSError::Refused { .. } => RCODE::REFUSED,
ZNSError::Refused { .. } | ZNSError::PublicKey { .. } => RCODE::REFUSED,
}
}
}

View file

@ -34,6 +34,7 @@ impl ResponseHandler for QueryHandler {
if rrs.len() == 0 {
return Err(ZNSError::NXDomain {
domain: question.qname.join("."),
qtype: question.qtype.clone(),
});
}
}
@ -55,7 +56,7 @@ impl ResponseHandler for QueryHandler {
fn try_wildcard(question: &Question, connection: &mut PgConnection) -> Result<Vec<RR>, ZNSError> {
let records = get_from_database(&question.qname, None, question.qclass.clone(), connection)?;
if records.len() > 0 {
if records.len() > 0 || question.qname.len() == 0 {
Ok(vec![])
} else {
let mut qname = question.qname.clone();

View file

@ -57,12 +57,12 @@ impl ResponseHandler for UpdateHandler {
.await
.is_ok_and(|x| x)
{
return Err(ZNSError::NotAuth {
return Err(ZNSError::Refused {
message: "Unable to verify authentication".to_string(),
});
}
} else {
return Err(ZNSError::NotAuth {
return Err(ZNSError::Refused {
message: "No KEY record at the end of request found".to_string(),
});
}