mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 10:26:29 +03:00
fix(receive_imf): remove recursive sql call
This commit is contained in:
@@ -1659,68 +1659,62 @@ unsafe fn check_verified_properties(
|
|||||||
let to_ids_str = to_string(to_ids_str_c);
|
let to_ids_str = to_string(to_ids_str_c);
|
||||||
free(to_ids_str_c as *mut libc::c_void);
|
free(to_ids_str_c as *mut libc::c_void);
|
||||||
|
|
||||||
let ok = context
|
let rows = context.sql.query_map(
|
||||||
.sql
|
format!(
|
||||||
.query_map(
|
"SELECT c.addr, LENGTH(ps.verified_key_fingerprint) FROM contacts c \
|
||||||
format!(
|
LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.id IN({}) ",
|
||||||
"SELECT c.addr, LENGTH(ps.verified_key_fingerprint) FROM contacts c \
|
&to_ids_str,
|
||||||
LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.id IN({}) ",
|
),
|
||||||
&to_ids_str,
|
params![],
|
||||||
),
|
|row| Ok((row.get::<_, String>(0)?, row.get::<_, i32>(1)?)),
|
||||||
params![],
|
|rows| rows.collect::<Result<Vec<_>, _>>().map_err(Into::into),
|
||||||
|row| Ok((row.get::<_, String>(0)?, row.get::<_, i32>(1)?)),
|
);
|
||||||
|rows| {
|
|
||||||
for row in rows {
|
|
||||||
let (to_addr, mut is_verified) = row?;
|
|
||||||
let mut peerstate = Peerstate::from_addr(context, &context.sql, &to_addr);
|
|
||||||
if mimeparser.e2ee_helper.gossipped_addr.contains(&to_addr)
|
|
||||||
&& peerstate.is_some()
|
|
||||||
{
|
|
||||||
let peerstate = peerstate.as_mut().unwrap();
|
|
||||||
|
|
||||||
// if we're here, we know the gossip key is verified:
|
if rows.is_err() {
|
||||||
// - use the gossip-key as verified-key if there is no verified-key
|
cleanup();
|
||||||
// - OR if the verified-key does not match public-key or gossip-key
|
return 0;
|
||||||
// (otherwise a verified key can _only_ be updated through QR scan which might be annoying,
|
}
|
||||||
// see https://github.com/nextleap-project/countermitm/issues/46 for a discussion about this point)
|
|
||||||
if 0 == is_verified
|
for (to_addr, mut is_verified) in rows.unwrap().into_iter() {
|
||||||
|| peerstate.verified_key_fingerprint
|
let mut peerstate = Peerstate::from_addr(context, &context.sql, &to_addr);
|
||||||
!= peerstate.public_key_fingerprint
|
if mimeparser.e2ee_helper.gossipped_addr.contains(&to_addr) && peerstate.is_some() {
|
||||||
&& peerstate.verified_key_fingerprint
|
let peerstate = peerstate.as_mut().unwrap();
|
||||||
!= peerstate.gossip_key_fingerprint
|
|
||||||
{
|
// if we're here, we know the gossip key is verified:
|
||||||
info!(
|
// - use the gossip-key as verified-key if there is no verified-key
|
||||||
context,
|
// - OR if the verified-key does not match public-key or gossip-key
|
||||||
0,
|
// (otherwise a verified key can _only_ be updated through QR scan which might be annoying,
|
||||||
"{} has verfied {}.",
|
// see https://github.com/nextleap-project/countermitm/issues/46 for a discussion about this point)
|
||||||
as_str((*contact).addr),
|
if 0 == is_verified
|
||||||
to_addr,
|
|| peerstate.verified_key_fingerprint != peerstate.public_key_fingerprint
|
||||||
);
|
&& peerstate.verified_key_fingerprint != peerstate.gossip_key_fingerprint
|
||||||
let fp = peerstate.gossip_key_fingerprint.clone();
|
{
|
||||||
if let Some(fp) = fp {
|
info!(
|
||||||
peerstate.set_verified(0, &fp, 2);
|
context,
|
||||||
peerstate.save_to_db(&context.sql, false);
|
0,
|
||||||
is_verified = 1;
|
"{} has verfied {}.",
|
||||||
}
|
as_str((*contact).addr),
|
||||||
}
|
to_addr,
|
||||||
}
|
);
|
||||||
if 0 == is_verified {
|
let fp = peerstate.gossip_key_fingerprint.clone();
|
||||||
verify_fail(format!(
|
if let Some(fp) = fp {
|
||||||
"{} is not a member of this verified group",
|
peerstate.set_verified(0, &fp, 2);
|
||||||
to_addr
|
peerstate.save_to_db(&context.sql, false);
|
||||||
));
|
is_verified = 1;
|
||||||
cleanup();
|
|
||||||
return Err(failure::format_err!("not a valid memember").into());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
}
|
||||||
},
|
}
|
||||||
)
|
if 0 == is_verified {
|
||||||
.is_ok(); // TODO: Better default
|
verify_fail(format!(
|
||||||
|
"{} is not a member of this verified group",
|
||||||
|
to_addr
|
||||||
|
));
|
||||||
|
cleanup();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cleanup();
|
1
|
||||||
|
|
||||||
ok as libc::c_int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn set_better_msg(mime_parser: &dc_mimeparser_t, better_msg: *mut *mut libc::c_char) {
|
unsafe fn set_better_msg(mime_parser: &dc_mimeparser_t, better_msg: *mut *mut libc::c_char) {
|
||||||
|
|||||||
Reference in New Issue
Block a user