@@ -2688,7 +2688,7 @@ void wallet2::detach_blockchain(uint64_t height)
26882688bool wallet2::deinit ()
26892689{
26902690 m_is_initialized=false ;
2691- m_keys_file_locker. reset ();
2691+ unlock_keys_file ();
26922692 return true ;
26932693}
26942694// ----------------------------------------------------------------------------------------------------
@@ -2858,12 +2858,12 @@ bool wallet2::store_keys(const std::string& keys_file_name, const epee::wipeable
28582858 crypto::chacha20 (account_data.data (), account_data.size (), key, keys_file_data.iv , &cipher[0 ]);
28592859 keys_file_data.account_data = cipher;
28602860
2861- m_keys_file_locker. reset ();
2861+ unlock_keys_file ();
28622862 std::string buf;
28632863 r = ::serialization::dump_binary (keys_file_data, buf);
28642864 r = r && epee::file_io_utils::save_string_to_file (keys_file_name, buf); // and never touch wallet_keys_file again, only read
28652865 CHECK_AND_ASSERT_MES (r, false , " failed to generate wallet keys file " << keys_file_name);
2866- m_keys_file_locker. reset ( new tools::file_locker (m_keys_file) );
2866+ lock_keys_file ( );
28672867
28682868 return true ;
28692869}
@@ -3087,9 +3087,13 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
30873087 * can be used prior to rewriting wallet keys file, to ensure user has entered the correct password
30883088 *
30893089 */
3090- bool wallet2::verify_password (const epee::wipeable_string& password) const
3090+ bool wallet2::verify_password (const epee::wipeable_string& password)
30913091{
3092- return verify_password (m_keys_file, password, m_watch_only || m_multisig, m_account.get_device ());
3092+ // this temporary unlocking is necessary for Windows (otherwise the file couldn't be loaded).
3093+ unlock_keys_file ();
3094+ bool r = verify_password (m_keys_file, password, m_watch_only || m_multisig, m_account.get_device ());
3095+ lock_keys_file ();
3096+ return r;
30933097}
30943098
30953099/* !
@@ -3996,17 +4000,17 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
39964000 boost::system::error_code e;
39974001 bool exists = boost::filesystem::exists (m_keys_file, e);
39984002 THROW_WALLET_EXCEPTION_IF (e || !exists, error::file_not_found, m_keys_file);
3999- m_keys_file_locker. reset ( new tools::file_locker (m_keys_file) );
4000- THROW_WALLET_EXCEPTION_IF (!m_keys_file_locker-> locked (), error::wallet_internal_error, " internal error: \" " + m_keys_file + " \" is opened by another wallet program" );
4003+ lock_keys_file ( );
4004+ THROW_WALLET_EXCEPTION_IF (!is_keys_file_locked (), error::wallet_internal_error, " internal error: \" " + m_keys_file + " \" is opened by another wallet program" );
40014005
40024006 // this temporary unlocking is necessary for Windows (otherwise the file couldn't be loaded).
4003- m_keys_file_locker. reset ();
4007+ unlock_keys_file ();
40044008 if (!load_keys (m_keys_file, password))
40054009 {
40064010 THROW_WALLET_EXCEPTION_IF (true , error::file_read_error, m_keys_file);
40074011 }
40084012 LOG_PRINT_L0 (" Loaded wallet keys file, with public address: " << m_account.get_public_address_str (m_nettype));
4009- m_keys_file_locker. reset ( new tools::file_locker (m_keys_file) );
4013+ lock_keys_file ( );
40104014
40114015 // keys loaded ok!
40124016 // try to load wallet file. but even if we failed, it is not big problem
@@ -6047,6 +6051,33 @@ bool wallet2::is_output_blackballed(const crypto::public_key &output) const
60476051 catch (const std::exception &e) { return false ; }
60486052}
60496053
6054+ bool wallet2::lock_keys_file ()
6055+ {
6056+ if (m_keys_file_locker)
6057+ {
6058+ MDEBUG (m_keys_file << " is already locked." );
6059+ return false ;
6060+ }
6061+ m_keys_file_locker.reset (new tools::file_locker (m_keys_file));
6062+ return true ;
6063+ }
6064+
6065+ bool wallet2::unlock_keys_file ()
6066+ {
6067+ if (!m_keys_file_locker)
6068+ {
6069+ MDEBUG (m_keys_file << " is already unlocked." );
6070+ return false ;
6071+ }
6072+ m_keys_file_locker.reset ();
6073+ return true ;
6074+ }
6075+
6076+ bool wallet2::is_keys_file_locked () const
6077+ {
6078+ return m_keys_file_locker->locked ();
6079+ }
6080+
60506081bool wallet2::tx_add_fake_output (std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, uint64_t global_index, const crypto::public_key& output_public_key, const rct::key& mask, uint64_t real_index, bool unlocked) const
60516082{
60526083 if (!unlocked) // don't add locked outs
0 commit comments