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:
parent
05daa4e8fe
commit
50640d859e
4 changed files with 19 additions and 9 deletions
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
structs::{Class, Type, RR},
|
structs::{Class, Type, RR},
|
||||||
};
|
};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
use diesel::sql_types::Text;
|
||||||
|
|
||||||
use self::schema::records::{self};
|
use self::schema::records::{self};
|
||||||
|
|
||||||
|
@ -31,6 +32,10 @@ struct Record {
|
||||||
pub rdata: Vec<u8>,
|
pub rdata: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sql_function! {
|
||||||
|
fn lower(x: Text) -> Text;
|
||||||
|
}
|
||||||
|
|
||||||
impl Record {
|
impl Record {
|
||||||
pub fn get(
|
pub fn get(
|
||||||
db: &mut PgConnection,
|
db: &mut PgConnection,
|
||||||
|
@ -40,7 +45,11 @@ impl Record {
|
||||||
) -> Result<Vec<Record>, diesel::result::Error> {
|
) -> Result<Vec<Record>, diesel::result::Error> {
|
||||||
let mut query = records::table.into_boxed();
|
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 {
|
if let Some(value) = _type {
|
||||||
query = query.filter(records::_type.eq(value))
|
query = query.filter(records::_type.eq(value))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::structs::RCODE;
|
use crate::structs::{Type, RCODE};
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum ZNSError {
|
pub enum ZNSError {
|
||||||
|
@ -17,8 +17,8 @@ pub enum ZNSError {
|
||||||
|
|
||||||
#[error("DNS Query Format Error: {message:?}")]
|
#[error("DNS Query Format Error: {message:?}")]
|
||||||
Formerr { message: String },
|
Formerr { message: String },
|
||||||
#[error("Domain name does not exist")]
|
#[error("Domain name does not exist: {qtype:?} {domain:?}")]
|
||||||
NXDomain { domain: String },
|
NXDomain { domain: String, qtype: Type },
|
||||||
#[error("NotImplemented Error for {object:?}: {message:?}")]
|
#[error("NotImplemented Error for {object:?}: {message:?}")]
|
||||||
NotImp { object: String, message: String },
|
NotImp { object: String, message: String },
|
||||||
#[error("Authentication Error: {message:?}")]
|
#[error("Authentication Error: {message:?}")]
|
||||||
|
@ -35,10 +35,10 @@ impl ZNSError {
|
||||||
}
|
}
|
||||||
ZNSError::Database { .. } | ZNSError::Reqwest(_) => RCODE::SERVFAIL,
|
ZNSError::Database { .. } | ZNSError::Reqwest(_) => RCODE::SERVFAIL,
|
||||||
|
|
||||||
ZNSError::NotAuth { .. } | ZNSError::PublicKey { .. } => RCODE::NOTAUTH,
|
ZNSError::NotAuth { .. } => RCODE::NOTAUTH,
|
||||||
ZNSError::NXDomain { .. } => RCODE::NXDOMAIN,
|
ZNSError::NXDomain { .. } => RCODE::NXDOMAIN,
|
||||||
ZNSError::NotImp { .. } => RCODE::NOTIMP,
|
ZNSError::NotImp { .. } => RCODE::NOTIMP,
|
||||||
ZNSError::Refused { .. } => RCODE::REFUSED,
|
ZNSError::Refused { .. } | ZNSError::PublicKey { .. } => RCODE::REFUSED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ impl ResponseHandler for QueryHandler {
|
||||||
if rrs.len() == 0 {
|
if rrs.len() == 0 {
|
||||||
return Err(ZNSError::NXDomain {
|
return Err(ZNSError::NXDomain {
|
||||||
domain: question.qname.join("."),
|
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> {
|
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 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![])
|
Ok(vec![])
|
||||||
} else {
|
} else {
|
||||||
let mut qname = question.qname.clone();
|
let mut qname = question.qname.clone();
|
||||||
|
|
|
@ -57,12 +57,12 @@ impl ResponseHandler for UpdateHandler {
|
||||||
.await
|
.await
|
||||||
.is_ok_and(|x| x)
|
.is_ok_and(|x| x)
|
||||||
{
|
{
|
||||||
return Err(ZNSError::NotAuth {
|
return Err(ZNSError::Refused {
|
||||||
message: "Unable to verify authentication".to_string(),
|
message: "Unable to verify authentication".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(ZNSError::NotAuth {
|
return Err(ZNSError::Refused {
|
||||||
message: "No KEY record at the end of request found".to_string(),
|
message: "No KEY record at the end of request found".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue