fixes #661 and also contains a cleanup of config access (only for e2ee and mdns)

This commit is contained in:
holger krekel
2019-10-02 20:30:41 +02:00
parent 92438737c9
commit 5c1b9c83f7
7 changed files with 17 additions and 45 deletions

View File

@@ -299,11 +299,7 @@ impl Chat {
so that E2EE is no longer available at a later point (reset, changed settings), so that E2EE is no longer available at a later point (reset, changed settings),
we do not send the message out at all */ we do not send the message out at all */
do_guarantee_e2ee = false; do_guarantee_e2ee = false;
e2ee_enabled = context e2ee_enabled = context.get_config_bool(Config::E2eeEnabled);
.sql
.get_config_int(context, "e2ee_enabled")
.unwrap_or_else(|| 1)
== 1;
if e2ee_enabled && msg.param.get_int(Param::ForcePlaintext).unwrap_or_default() == 0 { if e2ee_enabled && msg.param.get_int(Param::ForcePlaintext).unwrap_or_default() == 0 {
let mut can_encrypt = 1; let mut can_encrypt = 1;
let mut all_mutual = 1; let mut all_mutual = 1;

View File

@@ -25,7 +25,6 @@ impl Default for MoveState {
// some defaults // some defaults
const DC_E2EE_DEFAULT_ENABLED: i32 = 1; const DC_E2EE_DEFAULT_ENABLED: i32 = 1;
pub const DC_MDNS_DEFAULT_ENABLED: i32 = 1;
const DC_INBOX_WATCH_DEFAULT: i32 = 1; const DC_INBOX_WATCH_DEFAULT: i32 = 1;
const DC_SENTBOX_WATCH_DEFAULT: i32 = 1; const DC_SENTBOX_WATCH_DEFAULT: i32 = 1;
const DC_MVBOX_WATCH_DEFAULT: i32 = 1; const DC_MVBOX_WATCH_DEFAULT: i32 = 1;

View File

@@ -13,6 +13,7 @@ use mmime::other::*;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use crate::chat::{self, Chat}; use crate::chat::{self, Chat};
use crate::config::Config;
use crate::constants::*; use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
@@ -371,10 +372,7 @@ unsafe fn add_parts(
// maybe this can be optimized later, by checking the state before the message body is downloaded // maybe this can be optimized later, by checking the state before the message body is downloaded
let mut allow_creation = 1; let mut allow_creation = 1;
if mime_parser.is_system_message != SystemMessage::AutocryptSetupMessage && msgrmsg == 0 { if mime_parser.is_system_message != SystemMessage::AutocryptSetupMessage && msgrmsg == 0 {
let show_emails = context let show_emails = context.get_config_int(Config::ShowEmails);
.sql
.get_config_int(context, "show_emails")
.unwrap_or_default();
if show_emails == 0 { if show_emails == 0 {
*chat_id = 3; *chat_id = 3;
allow_creation = 0 allow_creation = 0
@@ -737,10 +735,7 @@ unsafe fn handle_reports(
server_folder: impl AsRef<str>, server_folder: impl AsRef<str>,
server_uid: u32, server_uid: u32,
) { ) {
let mdns_enabled = context let mdns_enabled = context.get_config_bool(Config::MdnsEnabled);
.sql
.get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| DC_MDNS_DEFAULT_ENABLED);
for report_root in &mime_parser.reports { for report_root in &mime_parser.reports {
let report_root = *report_root; let report_root = *report_root;
@@ -759,7 +754,7 @@ unsafe fn handle_reports(
&& (*(*report_root).mm_data.mm_multipart.mm_mp_list).count >= 2 && (*(*report_root).mm_data.mm_multipart.mm_mp_list).count >= 2
{ {
// to get a clear functionality, do not show incoming MDNs if the options is disabled // to get a clear functionality, do not show incoming MDNs if the options is disabled
if 0 != mdns_enabled { if mdns_enabled {
let report_data = (if !if !(*(*report_root).mm_data.mm_multipart.mm_mp_list) let report_data = (if !if !(*(*report_root).mm_data.mm_multipart.mm_mp_list)
.first .first
.is_null() .is_null()

View File

@@ -46,12 +46,8 @@ pub struct EncryptHelper {
impl EncryptHelper { impl EncryptHelper {
pub fn new(context: &Context) -> Result<EncryptHelper> { pub fn new(context: &Context) -> Result<EncryptHelper> {
let prefer_encrypt = context let prefer_encrypt =
.sql EncryptPreference::from_i32(context.get_config_int(Config::E2eeEnabled)).unwrap();
.get_config_int(&context, "e2ee_enabled")
.and_then(EncryptPreference::from_i32)
.unwrap_or_default();
let addr = match context.get_config(Config::ConfiguredAddr) { let addr = match context.get_config(Config::ConfiguredAddr) {
None => { None => {
bail!("addr not configured!"); bail!("addr not configured!");

View File

@@ -195,13 +195,9 @@ pub fn render_setup_file(context: &Context, passphrase: &str) -> Result<String>
let self_addr = e2ee::ensure_secret_key_exists(context)?; let self_addr = e2ee::ensure_secret_key_exists(context)?;
let private_key = Key::from_self_private(context, self_addr, &context.sql) let private_key = Key::from_self_private(context, self_addr, &context.sql)
.ok_or(format_err!("Failed to get private key."))?; .ok_or(format_err!("Failed to get private key."))?;
let ac_headers = match context let ac_headers = match context.get_config_bool(Config::E2eeEnabled) {
.sql false => None,
.get_config_int(context, Config::E2eeEnabled) true => Some(("Autocrypt-Prefer-Encrypt", "mutual")),
.unwrap_or(1)
{
0 => None,
_ => Some(("Autocrypt-Prefer-Encrypt", "mutual")),
}; };
let private_key_asc = private_key.to_asc(ac_headers); let private_key_asc = private_key.to_asc(ac_headers);
let encr = dc_pgp_symm_encrypt(&passphrase, private_key_asc.as_bytes())?; let encr = dc_pgp_symm_encrypt(&passphrase, private_key_asc.as_bytes())?;

View File

@@ -318,10 +318,7 @@ impl Job {
} }
_ => { _ => {
if 0 != msg.param.get_int(Param::WantsMdn).unwrap_or_default() if 0 != msg.param.get_int(Param::WantsMdn).unwrap_or_default()
&& 0 != context && context.get_config_bool(Config::MdnsEnabled)
.sql
.get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| 1)
{ {
let folder = msg.server_folder.as_ref().unwrap(); let folder = msg.server_folder.as_ref().unwrap();

View File

@@ -13,6 +13,7 @@ use mmime::mmapstring::*;
use mmime::other::*; use mmime::other::*;
use crate::chat::{self, Chat}; use crate::chat::{self, Chat};
use crate::config::Config;
use crate::constants::*; use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::{get_version_str, Context}; use crate::context::{get_version_str, Context};
@@ -106,15 +107,10 @@ impl<'a> MimeFactory<'a> {
} }
pub fn load_mdn(context: &'a Context, msg_id: u32) -> Result<MimeFactory, Error> { pub fn load_mdn(context: &'a Context, msg_id: u32) -> Result<MimeFactory, Error> {
if 0 == context if !context.get_config_bool(Config::MdnsEnabled) {
.sql // MDNs not enabled - check this is late, in the job. the
.get_config_int(context, "mdns_enabled") // user may have changed its choice while offline ...
.unwrap_or_else(|| 1) bail!("MDNs meanwhile disabled")
{
// MDNs not enabled - check this is late, in the job. the use may have changed its
// choice while offline ...
bail!("MDNs disabled ")
} }
let msg = Message::load_from_db(context, msg_id)?; let msg = Message::load_from_db(context, msg_id)?;
@@ -727,10 +723,7 @@ impl<'a> MimeFactory<'a> {
} }
if command != SystemMessage::AutocryptSetupMessage if command != SystemMessage::AutocryptSetupMessage
&& command != SystemMessage::SecurejoinMessage && command != SystemMessage::SecurejoinMessage
&& 0 != context && context.get_config_bool(Config::MdnsEnabled)
.sql
.get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| 1)
{ {
factory.req_mdn = true; factory.req_mdn = true;
} }