From e6709243247dd81998d47ef19e571f6de5dd500d Mon Sep 17 00:00:00 2001 From: William Brown Date: Sat, 30 Nov 2019 18:43:01 +1000 Subject: [PATCH] Update assert to debug assert, add Makefile, and resolve an issue with reindexing --- Makefile | 11 ++++++++ kanidmd/src/lib/be/idl_sqlite.rs | 10 +++++++- kanidmd/src/lib/be/mod.rs | 43 +++++++++++++++++++++++++++++++- kanidmd/src/lib/schema.rs | 10 ++------ kanidmd/src/lib/server.rs | 33 ++++++++++++++++++------ 5 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..8410017cd --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ + +docker-kanidmd: + docker build -f kanidmd/Dockerfile -t kanidmd:latest . + +docker-radiusd: + docker build -f kanidm_rlm_python/Dockerfile -t kanidm_radius:latest kanidm_rlm_python + +vendor-prep: + cargo vendor + tar -czf vendor.tar.gz vendor + diff --git a/kanidmd/src/lib/be/idl_sqlite.rs b/kanidmd/src/lib/be/idl_sqlite.rs index 5f09ff79c..973ea4ab9 100644 --- a/kanidmd/src/lib/be/idl_sqlite.rs +++ b/kanidmd/src/lib/be/idl_sqlite.rs @@ -174,6 +174,13 @@ pub trait IdlSqliteTransaction { // have a corrupted index ..... None => IDLBitRange::new(), }; + audit_log!( + audit, + "Got idl for index {:?} {:?} -> {:?}", + itype, + attr, + idl + ); Ok(Some(idl)) } @@ -497,7 +504,7 @@ impl IdlSqliteWriteTransaction { audit_log!(audit, "removing idx_table -> {:?}", idx_table); self.conn .prepare(format!("DROP TABLE {}", idx_table).as_str()) - .and_then(|mut stmt| stmt.query(NO_PARAMS).map(|_| ())) + .and_then(|mut stmt| stmt.execute(NO_PARAMS).map(|_| ())) .map_err(|e| { audit_log!(audit, "sqlite error {:?}", e); OperationError::SQLiteError @@ -512,6 +519,7 @@ impl IdlSqliteWriteTransaction { "rustqlite error {:?}", OperationError::SQLiteError ); + audit_log!(audit, "purge id2entry ..."); Ok(()) } diff --git a/kanidmd/src/lib/be/mod.rs b/kanidmd/src/lib/be/mod.rs index 1ae9747bc..25a4e8d57 100644 --- a/kanidmd/src/lib/be/mod.rs +++ b/kanidmd/src/lib/be/mod.rs @@ -474,7 +474,9 @@ impl BackendWriteTransaction { .into_iter() .map(|e| { id_max = id_max + 1; - e.to_valid_committed_id(id_max) + let ev = e.to_valid_committed_id(id_max); + // audit_log!(au, "assigned {} to {}", id_max, ev.get_uuid()); + ev }) .collect(); @@ -809,6 +811,35 @@ impl BackendWriteTransaction { OperationError::SerdeJsonError ); + // Filter all elements that have a UUID in the system range. + /* + use crate::constants::UUID_ANONYMOUS; + use crate::be::dbentry::DbEntryVers; + use crate::be::dbvalue::DbValueV1; + let uuid_anonymous = UUID_ANONYMOUS.clone(); + let dbentries: Vec = dbentries.into_iter() + .filter(|e| { + let e_uuid = match &e.ent { + DbEntryVers::V1(dbe) => dbe.attrs.get("uuid") + .and_then(|dbvs| dbvs.first()) + .and_then(|dbv| { + match dbv { + DbValueV1::UU(u) => Some(u), + _ => panic!(), + } + }) + .unwrap() + }; + + e_uuid > &uuid_anonymous + }) + .collect(); + + dbentries.iter().for_each(|e| { + audit_log!(audit, "importing -> {:?}", e); + }); + */ + // Now, we setup all the entries with new ids. let mut id_max = 0; let identries: Result, _> = dbentries @@ -827,6 +858,16 @@ impl BackendWriteTransaction { self.idlayer.write_identries(audit, identries?)?; + // for debug + /* + self.idlayer.get_identry(audit, &IDL::ALLIDS) + .unwrap() + .iter() + .for_each(|dbe| { + audit_log!(audit, "dbe -> {:?}", dbe.id); + }); + */ + // Reindex now we are loaded. self.reindex(audit)?; diff --git a/kanidmd/src/lib/schema.rs b/kanidmd/src/lib/schema.rs index b5e2c87e1..1e004fc9c 100644 --- a/kanidmd/src/lib/schema.rs +++ b/kanidmd/src/lib/schema.rs @@ -1108,15 +1108,9 @@ impl SchemaInner { uuid: Uuid::parse_str(UUID_SCHEMA_CLASS_ACCESS_CONTROL_PROFILE) .expect("unable to parse static uuid"), description: String::from("System Access Control Profile Class"), - systemmay: vec![ - "acp_enable".to_string(), - "description".to_string() - ], + systemmay: vec!["acp_enable".to_string(), "description".to_string()], may: vec![], - systemmust: vec![ - "acp_receiver".to_string(), - "acp_targetscope".to_string(), - ], + systemmust: vec!["acp_receiver".to_string(), "acp_targetscope".to_string()], must: vec![], }, ); diff --git a/kanidmd/src/lib/server.rs b/kanidmd/src/lib/server.rs index 46f7b2df8..a3f684bd0 100644 --- a/kanidmd/src/lib/server.rs +++ b/kanidmd/src/lib/server.rs @@ -1477,7 +1477,7 @@ impl<'a> QueryServerWriteTransaction<'a> { |e: Entry| self.internal_migrate_or_create(audit, e) )); audit_log!(audit, "internal_migrate_or_create_str -> result {:?}", res); - assert!(res.is_ok()); + debug_assert!(res.is_ok()); res } @@ -1495,6 +1495,12 @@ impl<'a> QueryServerWriteTransaction<'a> { // // NOTE: gen modlist IS schema aware and will handle multivalue // correctly! + audit_log!( + audit, + "internal_migrate_or_create operating on {:?}", + e.get_uuid() + ); + let filt = match e.filter_from_attrs(&vec![String::from("uuid")]) { Some(f) => f, None => return Err(OperationError::FilterGeneration), @@ -1541,7 +1547,7 @@ impl<'a> QueryServerWriteTransaction<'a> { |e: Entry| self.internal_assert_or_create(audit, e) )); audit_log!(audit, "internal_assert_or_create_str -> result {:?}", res); - assert!(res.is_ok()); + debug_assert!(res.is_ok()); res } @@ -1555,6 +1561,12 @@ impl<'a> QueryServerWriteTransaction<'a> { // else, if not exists, create it. IE no extra or excess // attributes and classes. + audit_log!( + audit, + "internal_assert_or_create operating on {:?}", + e.get_uuid() + ); + // Create a filter from the entry for assertion. let filt = match e.filter_from_attrs(&vec![String::from("uuid")]) { Some(f) => f, @@ -1601,7 +1613,8 @@ impl<'a> QueryServerWriteTransaction<'a> { self.internal_migrate_or_create(audit, e.invalidate()) }) .collect(); - assert!(r.is_ok()); + audit_log!(audit, "initialise_schema_core -> result {:?}", r); + debug_assert!(r.is_ok()); r } @@ -1633,7 +1646,8 @@ impl<'a> QueryServerWriteTransaction<'a> { .map(|e_str| self.internal_migrate_or_create_str(&mut audit_si, e_str)) .collect(); audit.append_scope(audit_si); - assert!(r.is_ok()); + audit_log!(audit, "initialise_schema_idm -> result {:?}", r); + debug_assert!(r.is_ok()); r.map(|_| ()) } @@ -1648,7 +1662,8 @@ impl<'a> QueryServerWriteTransaction<'a> { .internal_assert_or_create_str(&mut audit_an, JSON_SYSTEM_INFO_V1) .and_then(|_| self.internal_migrate_or_create_str(&mut audit_an, JSON_DOMAIN_INFO_V1)); audit.append_scope(audit_an); - assert!(res.is_ok()); + audit_log!(audit, "initialise_idm p1 -> result {:?}", res); + debug_assert!(res.is_ok()); if res.is_err() { return res; } @@ -1672,7 +1687,8 @@ impl<'a> QueryServerWriteTransaction<'a> { .map(|e_str| self.internal_migrate_or_create_str(&mut audit_an, e_str)) .collect(); audit.append_scope(audit_an); - assert!(res.is_ok()); + audit_log!(audit, "initialise_idm p2 -> result {:?}", res); + debug_assert!(res.is_ok()); if res.is_err() { return res; } @@ -1735,7 +1751,8 @@ impl<'a> QueryServerWriteTransaction<'a> { .map(|e_str| self.internal_migrate_or_create_str(&mut audit_an, e_str)) .collect(); audit.append_scope(audit_an); - assert!(res.is_ok()); + audit_log!(audit, "initialise_idm p3 -> result {:?}", res); + debug_assert!(res.is_ok()); if res.is_err() { return res; } @@ -1912,7 +1929,7 @@ impl<'a> QueryServerWriteTransaction<'a> { changed_schema: _, changed_acp: _, } = self; - assert!(!committed); + debug_assert!(!committed); // Begin an audit. // Validate the schema as we just loaded it. let r = schema.validate(audit);