|
27 | 27 | #include <support/events.h>
|
28 | 28 |
|
29 | 29 | #include <univalue.h>
|
| 30 | +#include <compat/stdin.h> |
30 | 31 |
|
31 | 32 | const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
32 | 33 |
|
@@ -58,7 +59,8 @@ static void SetupCliArgs()
|
58 | 59 | gArgs.AddArg("-rpcwait", "Wait for RPC server to start", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
59 | 60 | gArgs.AddArg("-rpcwallet=<walletname>", "Send RPC for non-default wallet on RPC server (needs to exactly match corresponding -wallet option passed to bitcoind). This changes the RPC endpoint used, e.g. http://127.0.0.1:8332/wallet/<walletname>", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
60 | 61 | gArgs.AddArg("-stdin", "Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases). When combined with -stdinrpcpass, the first line from standard input is used for the RPC password.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
61 |
| - gArgs.AddArg("-stdinrpcpass", "Read RPC password from standard input as a single line. When combined with -stdin, the first line from standard input is used for the RPC password.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); |
| 62 | + gArgs.AddArg("-stdinrpcpass", "Read RPC password from standard input as a single line. When combined with -stdin, the first line from standard input is used for the RPC password. When combined with -stdinwalletpassphrase, -stdinrpcpass consumes the first line, and -stdinwalletpassphrase consumes the second.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); |
| 63 | + gArgs.AddArg("-stdinwalletpassphrase", "Read wallet passphrase from standard input as a single line. When combined with -stdin, the first line from standard input is used for the wallet passphrase.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); |
62 | 64 | }
|
63 | 65 |
|
64 | 66 | /** libevent event log callback */
|
@@ -411,12 +413,32 @@ static int CommandLineRPC(int argc, char *argv[])
|
411 | 413 | }
|
412 | 414 | std::string rpcPass;
|
413 | 415 | if (gArgs.GetBoolArg("-stdinrpcpass", false)) {
|
| 416 | + NO_STDIN_ECHO(); |
| 417 | + if (!StdinReady()) { |
| 418 | + fputs("RPC password> ", stderr); |
| 419 | + fflush(stderr); |
| 420 | + } |
414 | 421 | if (!std::getline(std::cin, rpcPass)) {
|
415 | 422 | throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input");
|
416 | 423 | }
|
417 | 424 | gArgs.ForceSetArg("-rpcpassword", rpcPass);
|
418 | 425 | }
|
419 | 426 | std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
|
| 427 | + if (gArgs.GetBoolArg("-stdinwalletpassphrase", false)) { |
| 428 | + NO_STDIN_ECHO(); |
| 429 | + std::string walletPass; |
| 430 | + if (args.size() < 1 || args[0].substr(0, 16) != "walletpassphrase") { |
| 431 | + throw std::runtime_error("-stdinwalletpassphrase is only applicable for walletpassphrase(change)"); |
| 432 | + } |
| 433 | + if (!StdinReady()) { |
| 434 | + fputs("Wallet passphrase> ", stderr); |
| 435 | + fflush(stderr); |
| 436 | + } |
| 437 | + if (!std::getline(std::cin, walletPass)) { |
| 438 | + throw std::runtime_error("-stdinwalletpassphrase specified but failed to read from standard input"); |
| 439 | + } |
| 440 | + args.insert(args.begin() + 1, walletPass); |
| 441 | + } |
420 | 442 | if (gArgs.GetBoolArg("-stdin", false)) {
|
421 | 443 | // Read one arg per line from stdin and append
|
422 | 444 | std::string line;
|
|
0 commit comments