diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 159a44d8de..2af26af65e 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -24,6 +24,7 @@ #include "txmempool.h" #include "uint256.h" #include "utilstrencodings.h" +#include "util.h" #ifdef ENABLE_WALLET #include "wallet/wallet.h" #endif @@ -1076,6 +1077,8 @@ UniValue signrawtransaction(const JSONRPCRequest& request) result.push_back(Pair("errors", vErrors)); } + AuditLogPrintf("%s : signrawtransaction %s\n", getUser(), EncodeHexTx(mergedTx)); + return result; } @@ -1153,6 +1156,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request) } if(!g_connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); + AuditLogPrintf("%s : sendrawtransaction %s\n", getUser(), hashTx.GetHex()); CInv inv(MSG_TX, hashTx); g_connman->ForEachNode([&inv](CNode* pnode) diff --git a/src/util.cpp b/src/util.cpp index 54d4ebd472..acb490c5b9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -119,7 +119,7 @@ bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS; bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS; bool fLogIPs = DEFAULT_LOGIPS; std::atomic fReopenDebugLog(false); -volatile bool fReopenAuditLog = false; +std::atomic fReopenAuditLog(false); CTranslationInterface translationInterface; /** Init OpenSSL library multithreading support */ @@ -232,12 +232,11 @@ void OpenDebugLog() boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; fileout_debug = fopen(pathDebug.string().c_str(), "a"); if (fileout_debug) setbuf(fileout_debug, NULL); // unbuffered - setbuf(fileout, NULL); // unbuffered + setbuf(fileout_debug, NULL); // unbuffered // dump buffered messages from before we opened the log while (!vMsgsBeforeOpenDebugLog->empty()) { FileWriteStr(vMsgsBeforeOpenDebugLog->front(), fileout_debug); vMsgsBeforeOpenDebugLog->pop_front(); - } } delete vMsgsBeforeOpenDebugLog; @@ -370,7 +369,7 @@ int DebugLogPrintStr(const std::string &str) int AuditLogPrintStr(const std::string &str) { int ret = 0; // Returns total number of characters written - static bool fStartedNewLine = true; + static std::atomic_bool fStartedNewLine(true); string strTimestamped = LogTimestampStr(str, &fStartedNewLine); @@ -929,4 +928,4 @@ std::string CopyrightHolders(const std::string& strPrefix) strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers"; } return strCopyrightHolders; -} \ No newline at end of file +} diff --git a/src/util.h b/src/util.h index 943b7156bf..62fbc4b36d 100644 --- a/src/util.h +++ b/src/util.h @@ -77,25 +77,28 @@ int AuditLogPrintStr(const std::string &str); #define LogPrint(category, ...) do { \ if (LogAcceptCategory((category))) { \ - LogPrintStr(tfm::format(__VA_ARGS__)); \ + DebugLogPrintStr(tfm::format(__VA_ARGS__)); \ } \ } while(0) #define LogPrintf(...) do { \ - LogPrintStr(tfm::format(__VA_ARGS__)); \ + DebugLogPrintStr(tfm::format(__VA_ARGS__)); \ } while(0) -template -static inline int AuditLogPrint(const char* category, const char* fmt, const T1& v1, const Args&... args) -{ - if(!LogAcceptCategory(category)) return 0; \ - return AuditLogPrintStr(tfm::format(fmt, v1, args...)); -} +#define AuditLogPrint(category, ...) do { \ + if (LogAcceptCategory((category))) { \ + AuditLogPrintStr(tfm::format(__VA_ARGS__)); \ + } \ +} while(0) + +#define AuditLogPrintf(...) do { \ + AuditLogPrintStr(tfm::format(__VA_ARGS__)); \ +} while(0) template bool error(const char* fmt, const Args&... args) { - LogPrintStr("ERROR: " + tfm::format(fmt, args...) + "\n"); + DebugLogPrintStr("ERROR: " + tfm::format(fmt, args...) + "\n"); return false; } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 609495169e..8bfc8c0f19 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -152,6 +152,8 @@ UniValue importprivkey(const JSONRPCRequest& request) } } + AuditLogPrintf("%s : importprivkey %s\n", getUser(), pubkey.GetHash().GetHex()); + return NullUniValue; } @@ -252,6 +254,8 @@ UniValue importaddress(const JSONRPCRequest& request) pwalletMain->ReacceptWalletTransactions(); } + AuditLogPrintf("%s : importaddress %s\n", getUser(), request.params[0].get_str()); + return NullUniValue; } @@ -404,6 +408,8 @@ UniValue importpubkey(const JSONRPCRequest& request) pwalletMain->ReacceptWalletTransactions(); } + AuditLogPrintf("%s : importpubkey %s\n", getUser(), request.params[0].get_str()); + return NullUniValue; } @@ -511,6 +517,8 @@ UniValue importwallet(const JSONRPCRequest& request) if (!fGood) throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet"); + AuditLogPrintf("%s : importwallet %s\n", getUser(), request.params[0].get_str()); + return NullUniValue; } @@ -548,6 +556,9 @@ UniValue dumpprivkey(const JSONRPCRequest& request) CKey vchSecret; if (!pwalletMain->GetKey(keyID, vchSecret)) throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known"); + + AuditLogPrintf("%s : dumpprivkey %s\n", getUser(), strAddress); + return CBitcoinSecret(vchSecret).ToString(); } @@ -639,6 +650,9 @@ UniValue dumpwallet(const JSONRPCRequest& request) file << "\n"; file << "# End of dump\n"; file.close(); + + AuditLogPrintf("%s : dumpwallet %s\n", getUser(), request.params[0].get_str()); + return NullUniValue; } @@ -1138,6 +1152,7 @@ UniValue dumpblindingkey(const JSONRPCRequest& request) if (key.IsValid()) { CPubKey pubkey = key.GetPubKey(); if (pubkey == address.GetBlindingKey()) { + AuditLogPrintf("%s : dumpblindingkey %s\n", getUser(), address.ToString()); return HexStr(key.begin(), key.end()); } } @@ -1146,6 +1161,7 @@ UniValue dumpblindingkey(const JSONRPCRequest& request) if (key.IsValid()) { CPubKey pubkey = key.GetPubKey(); if (pubkey == address.GetBlindingKey()) { + AuditLogPrintf("%s : dumpblindingkey %s\n", getUser(), address.ToString()); return HexStr(key.begin(), key.end()); } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7f0aad9124..8e601c7071 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -449,7 +449,7 @@ UniValue sendtoaddress(const JSONRPCRequest& request) SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, confidentiality_pubkey, wtx); - AuditLogPrintf("%s : sendtoaddress %s %d", getUser(), wtx.GetHash().GetHex(), nAmount); + AuditLogPrintf("%s : sendtoaddress %s %s txid:%s\n", getUser(), request.params[0].get_str(), request.params[1].getValStr(), wtx.GetHash().GetHex()); return wtx.GetHash().GetHex(); } @@ -898,6 +898,8 @@ UniValue sendfrom(const JSONRPCRequest& request) SendMoney(address.Get(), nAmount, false, confidentiality_pubkey, wtx); + AuditLogPrintf("%s : sendfrom %s %s %s txid:%s\n", getUser(), request.params[0].get_str(), request.params[1].get_str(), request.params[2].getValStr(), wtx.GetHash().GetHex()); + return wtx.GetHash().GetHex(); } @@ -966,6 +968,9 @@ UniValue sendmany(const JSONRPCRequest& request) set setAddress; vector vecSend; + std::string strAudit(getUser()); + strAudit += " : sendmany \n"; + CAmount totalAmount = 0; vector keys = sendTo.getKeys(); BOOST_FOREACH(const string& name_, keys) @@ -984,6 +989,7 @@ UniValue sendmany(const JSONRPCRequest& request) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); totalAmount += nAmount; + strAudit += name_ + " " + sendTo[name_].getValStr() + "\n"; CPubKey confidentiality_pubkey; if (address.IsBlinded()) @@ -998,6 +1004,7 @@ UniValue sendmany(const JSONRPCRequest& request) CRecipient recipient = {scriptPubKey, nAmount, confidentiality_pubkey, fSubtractFeeFromAmount}; vecSend.push_back(recipient); + } EnsureWalletIsUnlocked(); @@ -1021,6 +1028,8 @@ UniValue sendmany(const JSONRPCRequest& request) throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); } + AuditLogPrintf("%s", strAudit); + return wtx.GetHash().GetHex(); } @@ -1072,6 +1081,9 @@ UniValue addmultisigaddress(const JSONRPCRequest& request) pwalletMain->AddCScript(inner); pwalletMain->SetAddressBook(innerID, strAccount, "send"); + + AuditLogPrintf("%s : addmultisigaddress %s\n", getUser(), CBitcoinAddress(innerID).ToString()); + return CBitcoinAddress(innerID).ToString(); } @@ -1161,6 +1173,8 @@ UniValue addwitnessaddress(const JSONRPCRequest& request) pwalletMain->SetAddressBook(w.result, "", "receive"); + AuditLogPrintf("%s : addwitnessaddress %s\n", getUser(), CBitcoinAddress(w.result).ToString()); + return CBitcoinAddress(w.result).ToString(); } @@ -1944,6 +1958,8 @@ UniValue backupwallet(const JSONRPCRequest& request) if (!pwalletMain->BackupWallet(strDest)) throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); + AuditLogPrintf("%s : backupwallet %s\n", getUser(), strDest); + return NullUniValue; } @@ -2048,6 +2064,8 @@ UniValue walletpassphrase(const JSONRPCRequest& request) nWalletUnlockTime = GetTime() + nSleepTime; RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime); + AuditLogPrintf("%s : walletpassphrase\n", getUser()); + return NullUniValue; } @@ -2094,6 +2112,8 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request) if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); + AuditLogPrintf("%s : walletpassphrasechange\n", getUser()); + return NullUniValue; } @@ -2187,6 +2207,8 @@ UniValue encryptwallet(const JSONRPCRequest& request) if (!pwalletMain->EncryptWallet(strWalletPass)) throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet."); + AuditLogPrintf("%s : encryptwallet\n", getUser()); + // BDB seems to have a bad habit of writing old data into // slack space in .dat files; that is bad if the old data is // unencrypted private keys. So: @@ -2356,6 +2378,9 @@ UniValue settxfee(const JSONRPCRequest& request) CAmount nAmount = AmountFromValue(request.params[0]); payTxFee = CFeeRate(nAmount, 1000); + + AuditLogPrintf("%s : settxfee %s\n", getUser(), request.params[0].getValStr()); + return true; } @@ -3183,6 +3208,8 @@ UniValue getpeginaddress(const JSONRPCRequest& request) UniValue fundinginfo(UniValue::VOBJ); + AuditLogPrintf("%s : getpeginaddress mainaddress: %s address: %s\n", getUser(), destAddr.ToString(), address.ToString()); + fundinginfo.pushKV("mainaddress", destAddr.ToString()); fundinginfo.pushKV("address", address.ToString()); return fundinginfo; @@ -3256,6 +3283,8 @@ UniValue sendtomainchain(const JSONRPCRequest& request) CWalletTx wtxNew; SendMoney(scriptPubKey, nAmount, false, CPubKey(), wtxNew); + AuditLogPrintf("%s : sendtomainchain %s\n", getUser(), wtxNew.tx->GetHash().GetHex()); + return wtxNew.GetHash().GetHex(); } @@ -3400,6 +3429,8 @@ UniValue claimpegin(const JSONRPCRequest& request) { pnode->PushInventory(inv); }); + + AuditLogPrintf("%s : claimpegin %s\n", getUser(), finalTxn.ToString()); return finalTxn.GetHash().GetHex(); }