aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/boost_serialization_helper.h33
-rw-r--r--src/common/util.cpp86
-rw-r--r--src/common/util.h27
-rw-r--r--src/cryptonote_core/account.cpp2
-rw-r--r--src/cryptonote_core/blockchain.cpp2
-rw-r--r--src/cryptonote_core/cryptonote_boost_serialization.h9
-rw-r--r--src/p2p/net_node.inl32
-rw-r--r--src/p2p/net_peerlist.h3
-rw-r--r--src/simplewallet/simplewallet.cpp21
-rw-r--r--src/wallet/wallet2.cpp34
-rw-r--r--src/wallet/wallet2.h7
-rw-r--r--src/wallet/wallet_rpc_server.cpp98
-rw-r--r--src/wallet/wallet_rpc_server.h3
13 files changed, 305 insertions, 52 deletions
diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h
index c640a1705..88dccbde7 100644
--- a/src/common/boost_serialization_helper.h
+++ b/src/common/boost_serialization_helper.h
@@ -30,8 +30,9 @@
#pragma once
-#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/portable_binary_oarchive.hpp>
+#include <boost/archive/portable_binary_iarchive.hpp>
namespace tools
@@ -53,8 +54,8 @@ namespace tools
return false;
}
- FILE* data_file_file = _fdopen(data_file_descriptor, "wb");
- if (0 == data_file_file)
+ const std::unique_ptr<FILE, tools::close_file> data_file_file{_fdopen(data_file_descriptor, "wb")};
+ if (nullptr == data_file_file)
{
// Call CloseHandle is not necessary
_close(data_file_descriptor);
@@ -62,11 +63,10 @@ namespace tools
}
// HACK: undocumented constructor, this code may not compile
- std::ofstream data_file(data_file_file);
+ std::ofstream data_file(data_file_file.get());
if (data_file.fail())
{
// Call CloseHandle and _close are not necessary
- fclose(data_file_file);
return false;
}
#else
@@ -76,7 +76,7 @@ namespace tools
return false;
#endif
- boost::archive::binary_oarchive a(data_file);
+ boost::archive::portable_binary_oarchive a(data_file);
a << obj;
if (data_file.fail())
return false;
@@ -85,7 +85,6 @@ namespace tools
#if defined(_MSC_VER)
// To make sure the file is fully stored on disk
::FlushFileBuffers(data_file_handle);
- fclose(data_file_file);
#endif
return true;
@@ -101,9 +100,23 @@ namespace tools
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
if(data_file.fail())
return false;
- boost::archive::binary_iarchive a(data_file);
-
- a >> obj;
+ try
+ {
+ // first try reading in portable mode
+ boost::archive::portable_binary_iarchive a(data_file);
+ a >> obj;
+ }
+ catch(...)
+ {
+ // if failed, try reading in unportable mode
+ boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ data_file.close();
+ data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
+ if(data_file.fail())
+ return false;
+ boost::archive::binary_iarchive a(data_file);
+ a >> obj;
+ }
return !data_file.fail();
CATCH_ENTRY_L0("unserialize_obj_from_file", false);
}
diff --git a/src/common/util.cpp b/src/common/util.cpp
index a53a9be52..6dec6af2a 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -50,6 +50,92 @@ namespace tools
{
std::function<void(int)> signal_handler::m_handler;
+ std::unique_ptr<std::FILE, tools::close_file> create_private_file(const std::string& name)
+ {
+#ifdef WIN32
+ struct close_handle
+ {
+ void operator()(HANDLE handle) const noexcept
+ {
+ CloseHandle(handle);
+ }
+ };
+
+ std::unique_ptr<void, close_handle> process = nullptr;
+ {
+ HANDLE temp{};
+ const bool fail = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, std::addressof(temp)) == 0;
+ process.reset(temp);
+ if (fail)
+ return nullptr;
+ }
+
+ DWORD sid_size = 0;
+ GetTokenInformation(process.get(), TokenOwner, nullptr, 0, std::addressof(sid_size));
+ if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ return nullptr;
+
+ std::unique_ptr<char[]> sid{new char[sid_size]};
+ if (!GetTokenInformation(process.get(), TokenOwner, sid.get(), sid_size, std::addressof(sid_size)))
+ return nullptr;
+
+ const PSID psid = reinterpret_cast<const PTOKEN_OWNER>(sid.get())->Owner;
+ const DWORD daclSize =
+ sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(psid) - sizeof(DWORD);
+
+ const std::unique_ptr<char[]> dacl{new char[daclSize]};
+ if (!InitializeAcl(reinterpret_cast<PACL>(dacl.get()), daclSize, ACL_REVISION))
+ return nullptr;
+
+ if (!AddAccessAllowedAce(reinterpret_cast<PACL>(dacl.get()), ACL_REVISION, (READ_CONTROL | FILE_GENERIC_READ | DELETE), psid))
+ return nullptr;
+
+ SECURITY_DESCRIPTOR descriptor{};
+ if (!InitializeSecurityDescriptor(std::addressof(descriptor), SECURITY_DESCRIPTOR_REVISION))
+ return nullptr;
+
+ if (!SetSecurityDescriptorDacl(std::addressof(descriptor), true, reinterpret_cast<PACL>(dacl.get()), false))
+ return nullptr;
+
+ SECURITY_ATTRIBUTES attributes{sizeof(SECURITY_ATTRIBUTES), std::addressof(descriptor), false};
+ std::unique_ptr<void, close_handle> file{
+ CreateFile(
+ name.c_str(),
+ GENERIC_WRITE, FILE_SHARE_READ,
+ std::addressof(attributes),
+ CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY,
+ nullptr
+ )
+ };
+ if (file)
+ {
+ const int fd = _open_osfhandle(reinterpret_cast<intptr_t>(file.get()), 0);
+ if (0 <= fd)
+ {
+ file.release();
+ std::FILE* real_file = _fdopen(fd, "w");
+ if (!real_file)
+ {
+ _close(fd);
+ }
+ return {real_file, tools::close_file{}};
+ }
+ }
+#else
+ const int fd = open(name.c_str(), (O_RDWR | O_EXCL | O_CREAT), S_IRUSR);
+ if (0 <= fd)
+ {
+ std::FILE* file = fdopen(fd, "w");
+ if (!file)
+ {
+ close(fd);
+ }
+ return {file, tools::close_file{}};
+ }
+#endif
+ return nullptr;
+ }
+
#ifdef WIN32
std::string get_windows_version_display_string()
{
diff --git a/src/common/util.h b/src/common/util.h
index 4fcf66b8f..3bb9a053e 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -30,13 +30,15 @@
#pragma once
-#include <mutex>
-#include <system_error>
-#include <boost/filesystem.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/mutex.hpp>
+#include <csignal>
+#include <cstdio>
+#include <functional>
+#include <memory>
+#include <string>
-#include "crypto/crypto.h"
#include "crypto/hash.h"
-#include "misc_language.h"
#include "p2p/p2p_protocol_defs.h"
/*! \brief Various Tools
@@ -46,6 +48,21 @@
*/
namespace tools
{
+ //! Functional class for closing C file handles.
+ struct close_file
+ {
+ void operator()(std::FILE* handle) const noexcept
+ {
+ if (handle)
+ {
+ std::fclose(handle);
+ }
+ }
+ };
+
+ //! \return File only readable by owner. nullptr if `filename` exists.
+ std::unique_ptr<std::FILE, close_file> create_private_file(const std::string& filename);
+
/*! \brief Returns the default data directory.
*
* \details Windows < Vista: C:\\Documents and Settings\\Username\\Application Data\\CRYPTONOTE_NAME
diff --git a/src/cryptonote_core/account.cpp b/src/cryptonote_core/account.cpp
index c3f2b4446..89ad4184c 100644
--- a/src/cryptonote_core/account.cpp
+++ b/src/cryptonote_core/account.cpp
@@ -28,8 +28,6 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-#include <boost/archive/binary_oarchive.hpp>
-#include <boost/archive/binary_iarchive.hpp>
#include <fstream>
#include "include_base_utils.h"
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 702d98944..a23d51126 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -30,8 +30,6 @@
#include <algorithm>
#include <cstdio>
-#include <boost/archive/binary_oarchive.hpp>
-#include <boost/archive/binary_iarchive.hpp>
#include <boost/filesystem.hpp>
#include "include_base_utils.h"
diff --git a/src/cryptonote_core/cryptonote_boost_serialization.h b/src/cryptonote_core/cryptonote_boost_serialization.h
index 663ef5070..7423b222a 100644
--- a/src/cryptonote_core/cryptonote_boost_serialization.h
+++ b/src/cryptonote_core/cryptonote_boost_serialization.h
@@ -38,7 +38,8 @@
#include <boost/foreach.hpp>
#include <boost/serialization/is_bitwise_serializable.hpp>
#include <boost/archive/binary_iarchive.hpp>
-#include <boost/archive/binary_oarchive.hpp>
+#include <boost/archive/portable_binary_iarchive.hpp>
+#include <boost/archive/portable_binary_oarchive.hpp>
#include "cryptonote_basic.h"
#include "common/unordered_containers_boost_serialization.h"
#include "crypto/crypto.h"
@@ -230,7 +231,8 @@ namespace boost
// a & x.senderPk; // not serialized, as we do not use it in monero currently
}
- inline void serializeOutPk(boost::archive::binary_iarchive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
+ template <class Archive>
+ inline typename std::enable_if<Archive::is_loading::value, void>::type serializeOutPk(Archive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
{
rct::keyV outPk;
a & outPk;
@@ -242,7 +244,8 @@ namespace boost
}
}
- inline void serializeOutPk(boost::archive::binary_oarchive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
+ template <class Archive>
+ inline typename std::enable_if<Archive::is_saving::value, void>::type serializeOutPk(Archive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
{
rct::keyV outPk(outPk_.size());
for (size_t n = 0; n < outPk_.size(); ++n)
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 442c42517..f32e7a435 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -137,14 +137,34 @@ namespace nodetool
{
try
{
- boost::archive::binary_iarchive a(p2p_data);
+ // first try reading in portable mode
+ boost::archive::portable_binary_iarchive a(p2p_data);
a >> *this;
}
- catch (const std::exception &e)
+ catch (...)
{
- LOG_ERROR("Failed to load p2p config file, falling back to default config");
- m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load
- make_default_config();
+ // if failed, try reading in unportable mode
+ boost::filesystem::copy_file(state_file_path, state_file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ p2p_data.close();
+ p2p_data.open( state_file_path , std::ios_base::binary | std::ios_base::in);
+ if(!p2p_data.fail())
+ {
+ try
+ {
+ boost::archive::binary_iarchive a(p2p_data);
+ a >> *this;
+ }
+ catch (const std::exception &e)
+ {
+ LOG_ERROR("Failed to load p2p config file, falling back to default config");
+ m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load
+ make_default_config();
+ }
+ }
+ else
+ {
+ make_default_config();
+ }
}
}else
{
@@ -645,7 +665,7 @@ namespace nodetool
return false;
};
- boost::archive::binary_oarchive a(p2p_data);
+ boost::archive::portable_binary_oarchive a(p2p_data);
a << *this;
return true;
CATCH_ENTRY_L0("blockchain_storage::save", false);
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index c19ecf65f..fa69abd6e 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -36,8 +36,9 @@
#include <boost/foreach.hpp>
//#include <boost/bimap.hpp>
//#include <boost/bimap/multiset_of.hpp>
-#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/portable_binary_oarchive.hpp>
+#include <boost/archive/portable_binary_iarchive.hpp>
#include <boost/serialization/version.hpp>
#include <boost/multi_index_container.hpp>
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index b46447975..dfd4bd561 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -2836,7 +2836,8 @@ bool simple_wallet::donate(const std::vector<std::string> &args_)
return true;
}
std::string mixin_str;
- std::string address_str = "donate.getmonero.org";
+ // Hardcode Monero's donation address (see #1447)
+ const std::string address_str = "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A";
std::string amount_str;
std::string payment_id_str;
// check payment id
@@ -2864,6 +2865,7 @@ bool simple_wallet::donate(const std::vector<std::string> &args_)
if (!payment_id_str.empty())
local_args.push_back(payment_id_str);
transfer_new(local_args);
+ return true;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes, const std::function<const tools::wallet2::tx_construction_data&(size_t)> &get_tx, const std::string &extra_message)
@@ -3882,7 +3884,7 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args)
std::vector<tools::wallet2::transfer_details> outs = m_wallet->export_outputs();
std::stringstream oss;
- boost::archive::binary_oarchive ar(oss);
+ boost::archive::portable_binary_oarchive ar(oss);
ar << outs;
std::string magic(OUTPUT_EXPORT_FILE_MAGIC, strlen(OUTPUT_EXPORT_FILE_MAGIC));
@@ -3962,10 +3964,19 @@ bool simple_wallet::import_outputs(const std::vector<std::string> &args)
std::string body(data, headerlen);
std::stringstream iss;
iss << body;
- boost::archive::binary_iarchive ar(iss);
std::vector<tools::wallet2::transfer_details> outputs;
- ar >> outputs;
-
+ try
+ {
+ boost::archive::portable_binary_iarchive ar(iss);
+ ar >> outputs;
+ }
+ catch (...)
+ {
+ iss.str("");
+ iss << body;
+ boost::archive::binary_iarchive ar(iss);
+ ar >> outputs;
+ }
size_t n_outputs = m_wallet->import_outputs(outputs);
success_msg_writer() << boost::lexical_cast<std::string>(n_outputs) << " outputs imported";
}
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index db4fae557..e58c31156 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -30,8 +30,6 @@
#include <random>
#include <tuple>
-#include <boost/archive/binary_oarchive.hpp>
-#include <boost/archive/binary_iarchive.hpp>
#include <boost/format.hpp>
#include <boost/optional/optional.hpp>
#include <boost/utility/value_init.hpp>
@@ -2313,16 +2311,38 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
std::stringstream iss;
iss << cache_data;
- boost::archive::binary_iarchive ar(iss);
- ar >> *this;
+ try {
+ boost::archive::portable_binary_iarchive ar(iss);
+ ar >> *this;
+ }
+ catch (...)
+ {
+ LOG_PRINT_L0("Failed to open portable binary, trying unportable");
+ boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ iss.str("");
+ iss << cache_data;
+ boost::archive::binary_iarchive ar(iss);
+ ar >> *this;
+ }
}
catch (...)
{
LOG_PRINT_L1("Failed to load encrypted cache, trying unencrypted");
std::stringstream iss;
iss << buf;
- boost::archive::binary_iarchive ar(iss);
- ar >> *this;
+ try {
+ boost::archive::portable_binary_iarchive ar(iss);
+ ar >> *this;
+ }
+ catch (...)
+ {
+ LOG_PRINT_L0("Failed to open portable binary, trying unportable");
+ boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ iss.str("");
+ iss << buf;
+ boost::archive::binary_iarchive ar(iss);
+ ar >> *this;
+ }
}
THROW_WALLET_EXCEPTION_IF(
m_account_public_address.m_spend_public_key != m_account.get_keys().m_account_address.m_spend_public_key ||
@@ -2396,7 +2416,7 @@ void wallet2::store_to(const std::string &path, const std::string &password)
}
// preparing wallet data
std::stringstream oss;
- boost::archive::binary_oarchive ar(oss);
+ boost::archive::portable_binary_oarchive ar(oss);
ar << *this;
wallet2::cache_file_data cache_file_data = boost::value_initialized<wallet2::cache_file_data>();
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index c3381730b..9f4180c0d 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -31,7 +31,6 @@
#pragma once
#include <memory>
-#include <boost/archive/binary_iarchive.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
@@ -676,11 +675,11 @@ namespace boost
namespace serialization
{
template <class Archive>
- inline void initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
+ inline typename std::enable_if<!Archive::is_loading::value, void>::type initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
{
}
- template<>
- inline void initialize_transfer_details(boost::archive::binary_iarchive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
+ template <class Archive>
+ inline typename std::enable_if<Archive::is_loading::value, void>::type initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
{
if (ver < 1)
{
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 7c08bbe4b..c34ce4cf2 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -28,6 +28,7 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include <boost/asio/ip/address.hpp>
+#include <boost/filesystem/operations.hpp>
#include <cstdint>
#include "include_base_utils.h"
using namespace epee;
@@ -36,10 +37,12 @@ using namespace epee;
#include "wallet/wallet_args.h"
#include "common/command_line.h"
#include "common/i18n.h"
+#include "common/util.h"
#include "cryptonote_core/cryptonote_format_utils.h"
#include "cryptonote_core/account.h"
#include "wallet_rpc_server_commands_defs.h"
#include "misc_language.h"
+#include "string_coding.h"
#include "string_tools.h"
#include "crypto/hash.h"
@@ -47,9 +50,11 @@ namespace
{
const command_line::arg_descriptor<std::string, true> arg_rpc_bind_port = {"rpc-bind-port", "Sets bind port for server"};
const command_line::arg_descriptor<std::string> arg_rpc_bind_ip = {"rpc-bind-ip", "Specify ip to bind rpc server", "127.0.0.1"};
- const command_line::arg_descriptor<std::string> arg_user_agent = {"user-agent", "Restrict RPC to clients using this user agent", ""};
-
+ const command_line::arg_descriptor<std::string> arg_rpc_login = {"rpc-login", "Specify username[:password] required for RPC connection"};
+ const command_line::arg_descriptor<bool> arg_disable_rpc_login = {"disable-rpc-login", "Disable HTTP authentication for RPC"};
const command_line::arg_descriptor<bool> arg_confirm_external_bind = {"confirm-external-bind", "Confirm rcp-bind-ip value is NOT a loopback (local) IP"};
+
+ constexpr const char default_rpc_username[] = "monero";
}
namespace tools
@@ -60,9 +65,19 @@ namespace tools
}
//------------------------------------------------------------------------------------------------------------------------------
- wallet_rpc_server::wallet_rpc_server(wallet2& w):m_wallet(w)
+ wallet_rpc_server::wallet_rpc_server(wallet2& w):m_wallet(w), rpc_login_filename(), m_stop(false)
{}
//------------------------------------------------------------------------------------------------------------------------------
+ wallet_rpc_server::~wallet_rpc_server()
+ {
+ try
+ {
+ boost::system::error_code ec{};
+ boost::filesystem::remove(rpc_login_filename, ec);
+ }
+ catch (...) {}
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::run()
{
m_stop = false;
@@ -110,11 +125,79 @@ namespace tools
}
}
+ epee::net_utils::http::http_auth::login login{};
+
+ const bool disable_auth = command_line::get_arg(vm, arg_disable_rpc_login);
+ const std::string user_pass = command_line::get_arg(vm, arg_rpc_login);
+ const std::string bind_port = command_line::get_arg(vm, arg_rpc_bind_port);
+
+ if (disable_auth)
+ {
+ if (!user_pass.empty())
+ {
+ LOG_ERROR(tr("Cannot specify --") << arg_disable_rpc_login.name << tr(" and --") << arg_rpc_login.name);
+ return false;
+ }
+ }
+ else // auth enabled
+ {
+ if (user_pass.empty())
+ {
+ login.username = default_rpc_username;
+
+ std::array<std::uint8_t, 16> rand_128bit{{}};
+ crypto::rand(rand_128bit.size(), rand_128bit.data());
+ login.password = string_encoding::base64_encode(rand_128bit.data(), rand_128bit.size());
+ }
+ else // user password
+ {
+ const auto loc = user_pass.find(':');
+ login.username = user_pass.substr(0, loc);
+ if (loc != std::string::npos)
+ {
+ login.password = user_pass.substr(loc + 1);
+ }
+ else
+ {
+ tools::password_container pwd(true);
+ pwd.read_password("RPC password");
+ login.password = pwd.password();
+ }
+
+ if (login.username.empty() || login.password.empty())
+ {
+ LOG_ERROR(tr("Blank username or password not permitted for RPC authenticaion"));
+ return false;
+ }
+ }
+
+ assert(!login.username.empty());
+ assert(!login.password.empty());
+
+ std::string temp = "monero-wallet-rpc." + bind_port + ".login";
+ const auto cookie = tools::create_private_file(temp);
+ if (!cookie)
+ {
+ LOG_ERROR(tr("Failed to create file ") << temp << tr(". Check permissions or remove file"));
+ return false;
+ }
+ rpc_login_filename.swap(temp); // nothrow guarantee destructor cleanup
+ temp = rpc_login_filename;
+ std::fputs(login.username.c_str(), cookie.get());
+ std::fputc(':', cookie.get());
+ std::fputs(login.password.c_str(), cookie.get());
+ std::fflush(cookie.get());
+ if (std::ferror(cookie.get()))
+ {
+ LOG_ERROR(tr("Error writing to file ") << temp);
+ return false;
+ }
+ LOG_PRINT_L0(tr("RPC username/password is stored in file ") << temp);
+ } // end auth enabled
+
m_net_server.set_threads_prefix("RPC");
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(
- command_line::get_arg(vm, arg_rpc_bind_port),
- std::move(bind_ip),
- command_line::get_arg(vm, arg_user_agent)
+ std::move(bind_port), std::move(bind_ip), std::string{}, boost::make_optional(!disable_auth, std::move(login))
);
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -1132,7 +1215,8 @@ int main(int argc, char** argv) {
tools::wallet2::init_options(desc_params);
command_line::add_arg(desc_params, arg_rpc_bind_ip);
command_line::add_arg(desc_params, arg_rpc_bind_port);
- command_line::add_arg(desc_params, arg_user_agent);
+ command_line::add_arg(desc_params, arg_rpc_login);
+ command_line::add_arg(desc_params, arg_disable_rpc_login);
command_line::add_arg(desc_params, arg_confirm_external_bind);
command_line::add_arg(desc_params, arg_wallet_file);
command_line::add_arg(desc_params, arg_from_json);
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 96ca1af04..8701d38cd 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -32,6 +32,7 @@
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
+#include <string>
#include "net/http_server_impl_base.h"
#include "wallet_rpc_server_commands_defs.h"
#include "wallet2.h"
@@ -48,6 +49,7 @@ namespace tools
static const char* tr(const char* str);
wallet_rpc_server(wallet2& cr);
+ ~wallet_rpc_server();
bool init(const boost::program_options::variables_map& vm);
bool run();
@@ -118,6 +120,7 @@ namespace tools
bool on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er);
wallet2& m_wallet;
+ std::string rpc_login_filename;
std::atomic<bool> m_stop;
};
}