mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 20:47:01 +01:00
Add pragma integrity check to verify (#175)
This commit is contained in:
parent
559222206f
commit
a55f277ac3
|
@ -39,6 +39,7 @@ pub enum ConsistencyError {
|
||||||
InvalidAttributeType(String),
|
InvalidAttributeType(String),
|
||||||
DuplicateUniqueAttribute(String),
|
DuplicateUniqueAttribute(String),
|
||||||
InvalidSPN(u64),
|
InvalidSPN(u64),
|
||||||
|
SqliteIntegrityFailure,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::be::{IdEntry, IDL};
|
||||||
use crate::utils::SID;
|
use crate::utils::SID;
|
||||||
use crate::value::IndexType;
|
use crate::value::IndexType;
|
||||||
use idlset::IDLBitRange;
|
use idlset::IDLBitRange;
|
||||||
use kanidm_proto::v1::OperationError;
|
use kanidm_proto::v1::{ConsistencyError, OperationError};
|
||||||
use r2d2::Pool;
|
use r2d2::Pool;
|
||||||
use r2d2_sqlite::SqliteConnectionManager;
|
use r2d2_sqlite::SqliteConnectionManager;
|
||||||
use rusqlite::types::ToSql;
|
use rusqlite::types::ToSql;
|
||||||
|
@ -215,6 +215,37 @@ pub trait IdlSqliteTransaction {
|
||||||
})
|
})
|
||||||
.map_err(|_| OperationError::SQLiteError)
|
.map_err(|_| OperationError::SQLiteError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn verify(&self) -> Vec<Result<(), ConsistencyError>> {
|
||||||
|
let mut stmt = match self.get_conn().prepare("PRAGMA integrity_check;") {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(_) => return vec![Err(ConsistencyError::SqliteIntegrityFailure)],
|
||||||
|
};
|
||||||
|
|
||||||
|
let r = match stmt.query(NO_PARAMS) {
|
||||||
|
Ok(mut rows) => {
|
||||||
|
match rows.next() {
|
||||||
|
Ok(Some(v)) => {
|
||||||
|
// println!("{:?}", v.column_names());
|
||||||
|
let r: Result<String, _> = v.get(0);
|
||||||
|
match r {
|
||||||
|
Ok(t) => {
|
||||||
|
if t == "ok" {
|
||||||
|
Vec::new()
|
||||||
|
} else {
|
||||||
|
vec![Err(ConsistencyError::SqliteIntegrityFailure)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => vec![Err(ConsistencyError::SqliteIntegrityFailure)],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => vec![Err(ConsistencyError::SqliteIntegrityFailure)],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => vec![Err(ConsistencyError::SqliteIntegrityFailure)],
|
||||||
|
};
|
||||||
|
r
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdlSqliteTransaction for IdlSqliteReadTransaction {
|
impl IdlSqliteTransaction for IdlSqliteReadTransaction {
|
||||||
|
@ -709,4 +740,16 @@ impl IdlSqlite {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {}
|
mod tests {
|
||||||
|
use crate::audit::AuditScope;
|
||||||
|
use crate::be::idl_sqlite::{IdlSqlite, IdlSqliteTransaction};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_idl_sqlite_verify() {
|
||||||
|
let mut audit = AuditScope::new("run_test");
|
||||||
|
let be = IdlSqlite::new(&mut audit, "", 1).unwrap();
|
||||||
|
let be_w = be.write();
|
||||||
|
let r = be_w.verify();
|
||||||
|
assert!(r.len() == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -394,8 +394,8 @@ pub trait BackendTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify(&self) -> Vec<Result<(), ConsistencyError>> {
|
fn verify(&self) -> Vec<Result<(), ConsistencyError>> {
|
||||||
// TODO: Implement this!!!
|
// Vec::new()
|
||||||
Vec::new()
|
self.get_idlayer().verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backup(&self, audit: &mut AuditScope, dst_path: &str) -> Result<(), OperationError> {
|
fn backup(&self, audit: &mut AuditScope, dst_path: &str) -> Result<(), OperationError> {
|
||||||
|
|
Loading…
Reference in a new issue