diff options
author | Riccardo Spagni <ric@spagni.net> | 2018-01-27 17:24:34 -0800 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2018-01-27 17:24:34 -0800 |
commit | e1ba5b95c180410118e28587986f5a61eb460900 (patch) | |
tree | 73032f09c93038a3a0a5434422b472ce80af0739 /src/simplewallet | |
parent | Merge pull request #3114 (diff) | |
parent | simplewallet: check file overwrite when exporting stuff (diff) | |
download | monero-e1ba5b95c180410118e28587986f5a61eb460900.tar.xz |
Merge pull request #3118
ca336c62 simplewallet: check file overwrite when exporting stuff (stoffu)
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 38 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8d95773a3..8f31bbc1c 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -442,6 +442,21 @@ namespace 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) @@ -874,6 +889,8 @@ bool simple_wallet::export_multisig(const std::vector<std::string> &args) return true; const std::string filename = args[0]; + if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename)) + return true; try { 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; } std::string filename = args[0]; + if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename)) + return true; try { tools::wallet2::multisig_tx_set txs; @@ -1470,6 +1489,19 @@ bool simple_wallet::set_confirm_backlog_threshold(const std::vector<std::string> 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>()*/) { 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() << "confirm-backlog = " << m_wallet->confirm_backlog(); 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(); 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("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-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")); } 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; } std::string filename = args[0]; + if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename)) + return true; 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; } std::string filename = args[0]; + if (m_wallet->confirm_export_overwrite() && !check_file_overwrite(filename)) + return true; LOCK_IDLE_SCOPE(); try diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index a67e20add..f51b27e0e 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -128,6 +128,7 @@ namespace cryptonote 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_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 help(const std::vector<std::string> &args = std::vector<std::string>()); bool start_mining(const std::vector<std::string> &args); |