rpc: honor a command-line rpcpassword across restarts; fix dead -rpcusername key

hush_configfile(), on any restart where the auto-generated DRAGONX.conf
already exists, hard-assigned mapArgs["-rpcpassword"] from the conf and
wrote the username to mapArgs["-rpcusername"] -- a key nothing reads
(InitRPCAuthentication in httprpc.cpp and bitcoin-cli.cpp both read
"-rpcuser"). The hard assignment silently overwrote a -rpcpassword passed
on the command line, so after the first run the effective RPC credentials
became {cmdline-user}:{conf-password}, matching neither the command-line
pair the operator passed nor the full conf pair. Automation or external
clients that connect with the known command-line password broke on every
restart.

Use SoftSetArg for both, so a command-line (or explicitly configured)
value wins and the conf-derived credential is only a fallback. Verified on
regtest: after a restart an external client with the command-line password
gets HTTP 200 and the conf's random password gets 401; the conf-only
operator path (no command-line creds) still authenticates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PGhWvdBSgt6UxxHANr7gfN
This commit is contained in:
2026-08-30 16:32:20 -05:00
parent 2d6359ea74
commit 3b2aa866aa

View File

@@ -1383,8 +1383,14 @@ void hush_configfile(char *symbol,uint16_t rpcport)
#endif #endif
} else { } else {
_hush_userpass(myusername,mypassword,fp); _hush_userpass(myusername,mypassword,fp);
mapArgs["-rpcpassword"] = mypassword; // Feed the credentials read by InitRPCAuthentication (httprpc.cpp) and the
mapArgs["-rpcusername"] = myusername; // CLI (bitcoin-cli.cpp) -- both read "-rpcuser"/"-rpcpassword". Use SoftSetArg
// so a value passed on the command line (or an explicit -rpcuser/-rpcpassword)
// still wins: the old direct assignment silently overwrote a command-line
// -rpcpassword on every restart once this conf existed, and the username was
// written to a misspelled "-rpcusername" key that nothing ever reads.
SoftSetArg("-rpcpassword", mypassword);
SoftSetArg("-rpcuser", myusername);
fclose(fp); fclose(fp);
} }
} }