|
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,18 +413,47 @@ 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 | }
|
| 424 | + if (StdinTerminal()) { |
| 425 | + fputc('\n', stdout); |
| 426 | + } |
417 | 427 | gArgs.ForceSetArg("-rpcpassword", rpcPass);
|
418 | 428 | }
|
419 | 429 | std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
|
| 430 | + if (gArgs.GetBoolArg("-stdinwalletpassphrase", false)) { |
| 431 | + NO_STDIN_ECHO(); |
| 432 | + std::string walletPass; |
| 433 | + if (args.size() < 1 || args[0].substr(0, 16) != "walletpassphrase") { |
| 434 | + throw std::runtime_error("-stdinwalletpassphrase is only applicable for walletpassphrase(change)"); |
| 435 | + } |
| 436 | + if (!StdinReady()) { |
| 437 | + fputs("Wallet passphrase> ", stderr); |
| 438 | + fflush(stderr); |
| 439 | + } |
| 440 | + if (!std::getline(std::cin, walletPass)) { |
| 441 | + throw std::runtime_error("-stdinwalletpassphrase specified but failed to read from standard input"); |
| 442 | + } |
| 443 | + if (StdinTerminal()) { |
| 444 | + fputc('\n', stdout); |
| 445 | + } |
| 446 | + args.insert(args.begin() + 1, walletPass); |
| 447 | + } |
420 | 448 | if (gArgs.GetBoolArg("-stdin", false)) {
|
421 | 449 | // Read one arg per line from stdin and append
|
422 | 450 | std::string line;
|
423 | 451 | while (std::getline(std::cin, line)) {
|
424 | 452 | args.push_back(line);
|
425 | 453 | }
|
| 454 | + if (StdinTerminal()) { |
| 455 | + fputc('\n', stdout); |
| 456 | + } |
426 | 457 | }
|
427 | 458 | std::unique_ptr<BaseRequestHandler> rh;
|
428 | 459 | std::string method;
|
|
0 commit comments