mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 14:53:27 +01:00
simplewallet: check file overwrite when exporting stuff
This commit is contained in:
parent
09d19c9139
commit
ca336c62e3
@ -442,6 +442,21 @@ namespace
|
|||||||
fail_msg_writer() << tr("unexpected error: ") << e.what();
|
fail_msg_writer() << tr("unexpected error: ") << e.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_file_overwrite(const std::string &filename)
|
||||||
|
{
|
||||||
|
boost::system::error_code errcode;
|
||||||
|
if (boost::filesystem::exists(filename, errcode))
|
||||||
|
{
|
||||||
|
if (boost::ends_with(filename, ".keys"))
|
||||||
|
{
|
||||||
|
fail_msg_writer() << boost::format(tr("File %s likely stores wallet private keys! Use a different file name.")) % filename;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return command_line::is_yes(input_line((boost::format(tr("File %s already exists. Are you sure to overwrite it? (Y/Yes/N/No): ")) % filename).str()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse_priority(const std::string& arg, uint32_t& priority)
|
bool parse_priority(const std::string& arg, uint32_t& priority)
|
||||||
@ -874,6 +889,8 @@ bool simple_wallet::export_multisig(const std::vector<std::string> &args)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
const std::string filename = args[0];
|
const std::string filename = args[0];
|
||||||
|
if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename))
|
||||||
|
return true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cryptonote::blobdata ciphertext = m_wallet->export_multisig();
|
cryptonote::blobdata ciphertext = m_wallet->export_multisig();
|
||||||
@ -1122,6 +1139,8 @@ bool simple_wallet::export_raw_multisig(const std::vector<std::string> &args)
|
|||||||
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
|
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
|
||||||
|
|
||||||
std::string filename = args[0];
|
std::string filename = args[0];
|
||||||
|
if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename))
|
||||||
|
return true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tools::wallet2::multisig_tx_set txs;
|
tools::wallet2::multisig_tx_set txs;
|
||||||
@ -1470,6 +1489,19 @@ bool simple_wallet::set_confirm_backlog_threshold(const std::vector<std::string>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool simple_wallet::set_confirm_export_overwrite(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
|
{
|
||||||
|
const auto pwd_container = get_and_verify_password();
|
||||||
|
if (pwd_container)
|
||||||
|
{
|
||||||
|
parse_bool_and_use(args[1], [&](bool r) {
|
||||||
|
m_wallet->confirm_export_overwrite(r);
|
||||||
|
m_wallet->rewrite(m_wallet_file, pwd_container->password());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool simple_wallet::set_refresh_from_block_height(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
bool simple_wallet::set_refresh_from_block_height(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
{
|
{
|
||||||
const auto pwd_container = get_and_verify_password();
|
const auto pwd_container = get_and_verify_password();
|
||||||
@ -1824,6 +1856,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||||||
success_msg_writer() << "merge-destinations = " << m_wallet->merge_destinations();
|
success_msg_writer() << "merge-destinations = " << m_wallet->merge_destinations();
|
||||||
success_msg_writer() << "confirm-backlog = " << m_wallet->confirm_backlog();
|
success_msg_writer() << "confirm-backlog = " << m_wallet->confirm_backlog();
|
||||||
success_msg_writer() << "confirm-backlog-threshold = " << m_wallet->get_confirm_backlog_threshold();
|
success_msg_writer() << "confirm-backlog-threshold = " << m_wallet->get_confirm_backlog_threshold();
|
||||||
|
success_msg_writer() << "confirm-export-overwrite = " << m_wallet->confirm_export_overwrite();
|
||||||
success_msg_writer() << "refresh-from-block-height = " << m_wallet->get_refresh_from_block_height();
|
success_msg_writer() << "refresh-from-block-height = " << m_wallet->get_refresh_from_block_height();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1872,6 +1905,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||||||
CHECK_SIMPLE_VARIABLE("merge-destinations", set_merge_destinations, tr("0 or 1"));
|
CHECK_SIMPLE_VARIABLE("merge-destinations", set_merge_destinations, tr("0 or 1"));
|
||||||
CHECK_SIMPLE_VARIABLE("confirm-backlog", set_confirm_backlog, tr("0 or 1"));
|
CHECK_SIMPLE_VARIABLE("confirm-backlog", set_confirm_backlog, tr("0 or 1"));
|
||||||
CHECK_SIMPLE_VARIABLE("confirm-backlog-threshold", set_confirm_backlog_threshold, tr("unsigned integer"));
|
CHECK_SIMPLE_VARIABLE("confirm-backlog-threshold", set_confirm_backlog_threshold, tr("unsigned integer"));
|
||||||
|
CHECK_SIMPLE_VARIABLE("confirm-export-overwrite", set_confirm_export_overwrite, tr("0 or 1"));
|
||||||
CHECK_SIMPLE_VARIABLE("refresh-from-block-height", set_refresh_from_block_height, tr("block height"));
|
CHECK_SIMPLE_VARIABLE("refresh-from-block-height", set_refresh_from_block_height, tr("block height"));
|
||||||
}
|
}
|
||||||
fail_msg_writer() << tr("set: unrecognized argument(s)");
|
fail_msg_writer() << tr("set: unrecognized argument(s)");
|
||||||
@ -6329,6 +6363,8 @@ bool simple_wallet::export_key_images(const std::vector<std::string> &args)
|
|||||||
}
|
}
|
||||||
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
|
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
|
||||||
std::string filename = args[0];
|
std::string filename = args[0];
|
||||||
|
if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename))
|
||||||
|
return true;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -6396,6 +6432,8 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args)
|
|||||||
}
|
}
|
||||||
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
|
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
|
||||||
std::string filename = args[0];
|
std::string filename = args[0];
|
||||||
|
if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename))
|
||||||
|
return true;
|
||||||
|
|
||||||
LOCK_IDLE_SCOPE();
|
LOCK_IDLE_SCOPE();
|
||||||
try
|
try
|
||||||
|
@ -128,6 +128,7 @@ namespace cryptonote
|
|||||||
bool set_merge_destinations(const std::vector<std::string> &args = std::vector<std::string>());
|
bool set_merge_destinations(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool set_confirm_backlog(const std::vector<std::string> &args = std::vector<std::string>());
|
bool set_confirm_backlog(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool set_confirm_backlog_threshold(const std::vector<std::string> &args = std::vector<std::string>());
|
bool set_confirm_backlog_threshold(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
|
bool set_confirm_export_overwrite(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool set_refresh_from_block_height(const std::vector<std::string> &args = std::vector<std::string>());
|
bool set_refresh_from_block_height(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool help(const std::vector<std::string> &args = std::vector<std::string>());
|
bool help(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool start_mining(const std::vector<std::string> &args);
|
bool start_mining(const std::vector<std::string> &args);
|
||||||
|
@ -611,6 +611,7 @@ wallet2::wallet2(bool testnet, bool restricted):
|
|||||||
m_merge_destinations(false),
|
m_merge_destinations(false),
|
||||||
m_confirm_backlog(true),
|
m_confirm_backlog(true),
|
||||||
m_confirm_backlog_threshold(0),
|
m_confirm_backlog_threshold(0),
|
||||||
|
m_confirm_export_overwrite(true),
|
||||||
m_is_initialized(false),
|
m_is_initialized(false),
|
||||||
m_restricted(restricted),
|
m_restricted(restricted),
|
||||||
is_old_file_format(false),
|
is_old_file_format(false),
|
||||||
@ -2441,6 +2442,9 @@ bool wallet2::store_keys(const std::string& keys_file_name, const epee::wipeable
|
|||||||
value2.SetUint(m_confirm_backlog_threshold);
|
value2.SetUint(m_confirm_backlog_threshold);
|
||||||
json.AddMember("confirm_backlog_threshold", value2, json.GetAllocator());
|
json.AddMember("confirm_backlog_threshold", value2, json.GetAllocator());
|
||||||
|
|
||||||
|
value2.SetInt(m_confirm_export_overwrite ? 1 :0);
|
||||||
|
json.AddMember("confirm_export_overwrite", value2, json.GetAllocator());
|
||||||
|
|
||||||
value2.SetInt(m_testnet ? 1 :0);
|
value2.SetInt(m_testnet ? 1 :0);
|
||||||
json.AddMember("testnet", value2, json.GetAllocator());
|
json.AddMember("testnet", value2, json.GetAllocator());
|
||||||
|
|
||||||
@ -2522,6 +2526,7 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
|
|||||||
m_merge_destinations = false;
|
m_merge_destinations = false;
|
||||||
m_confirm_backlog = true;
|
m_confirm_backlog = true;
|
||||||
m_confirm_backlog_threshold = 0;
|
m_confirm_backlog_threshold = 0;
|
||||||
|
m_confirm_export_overwrite = true;
|
||||||
}
|
}
|
||||||
else if(json.IsObject())
|
else if(json.IsObject())
|
||||||
{
|
{
|
||||||
@ -2621,6 +2626,8 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
|
|||||||
m_confirm_backlog = field_confirm_backlog;
|
m_confirm_backlog = field_confirm_backlog;
|
||||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, confirm_backlog_threshold, uint32_t, Uint, false, 0);
|
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, confirm_backlog_threshold, uint32_t, Uint, false, 0);
|
||||||
m_confirm_backlog_threshold = field_confirm_backlog_threshold;
|
m_confirm_backlog_threshold = field_confirm_backlog_threshold;
|
||||||
|
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, confirm_export_overwrite, int, Int, false, true);
|
||||||
|
m_confirm_export_overwrite = field_confirm_export_overwrite;
|
||||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, testnet, int, Int, false, m_testnet);
|
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, testnet, int, Int, false, m_testnet);
|
||||||
// Wallet is being opened with testnet flag, but is saved as a mainnet wallet
|
// Wallet is being opened with testnet flag, but is saved as a mainnet wallet
|
||||||
THROW_WALLET_EXCEPTION_IF(m_testnet && !field_testnet, error::wallet_internal_error, "Mainnet wallet can not be opened as testnet wallet");
|
THROW_WALLET_EXCEPTION_IF(m_testnet && !field_testnet, error::wallet_internal_error, "Mainnet wallet can not be opened as testnet wallet");
|
||||||
|
@ -837,6 +837,8 @@ namespace tools
|
|||||||
void confirm_backlog(bool always) { m_confirm_backlog = always; }
|
void confirm_backlog(bool always) { m_confirm_backlog = always; }
|
||||||
void set_confirm_backlog_threshold(uint32_t threshold) { m_confirm_backlog_threshold = threshold; };
|
void set_confirm_backlog_threshold(uint32_t threshold) { m_confirm_backlog_threshold = threshold; };
|
||||||
uint32_t get_confirm_backlog_threshold() const { return m_confirm_backlog_threshold; };
|
uint32_t get_confirm_backlog_threshold() const { return m_confirm_backlog_threshold; };
|
||||||
|
bool confirm_export_overwrite() const { return m_confirm_export_overwrite; }
|
||||||
|
void confirm_export_overwrite(bool always) { m_confirm_export_overwrite = always; }
|
||||||
|
|
||||||
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys) const;
|
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys) const;
|
||||||
void check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
|
void check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
|
||||||
@ -1119,6 +1121,7 @@ namespace tools
|
|||||||
bool m_merge_destinations;
|
bool m_merge_destinations;
|
||||||
bool m_confirm_backlog;
|
bool m_confirm_backlog;
|
||||||
uint32_t m_confirm_backlog_threshold;
|
uint32_t m_confirm_backlog_threshold;
|
||||||
|
bool m_confirm_export_overwrite;
|
||||||
bool m_is_initialized;
|
bool m_is_initialized;
|
||||||
NodeRPCProxy m_node_rpc_proxy;
|
NodeRPCProxy m_node_rpc_proxy;
|
||||||
std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
|
std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
|
||||||
|
Loading…
Reference in New Issue
Block a user