config: allow independent rpccookie config

The bitcoind .cookie contains an autogenerated user (__cookie__) and
password (random string), which can be used instead of the rpc user name
and password. This commit allows for running against bitcoind without
having to access bitcoin.conf like in the case for pure
user/password/zmq configuration.
This commit is contained in:
bitromortac
2022-07-13 13:31:29 +02:00
parent 7e225f6aa5
commit d27c622568
2 changed files with 48 additions and 17 deletions

View File

@ -1794,6 +1794,47 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
}
}
// Get the daemon name for displaying proper errors.
switch net {
case chainreg.BitcoinChain:
daemonName = "bitcoind"
confDir = conf.Dir
confFile = conf.ConfigPath
confFileBase = "bitcoin"
case chainreg.LitecoinChain:
daemonName = "litecoind"
confDir = conf.Dir
confFile = conf.ConfigPath
confFileBase = "litecoin"
}
// Check that cookie and credentials don't contradict each
// other.
if (conf.RPCUser != "" || conf.RPCPass != "") &&
conf.RPCCookie != "" {
return fmt.Errorf("please only provide either "+
"%[1]v.rpccookie or %[1]v.rpcuser and "+
"%[1]v.rpcpass", daemonName)
}
// We convert the cookie into a user name and password.
if conf.RPCCookie != "" {
cookie, err := ioutil.ReadFile(conf.RPCCookie)
if err != nil {
return fmt.Errorf("cannot read cookie file: %w",
err)
}
splitCookie := strings.Split(string(cookie), ":")
if len(splitCookie) != 2 {
return fmt.Errorf("cookie file has a wrong " +
"format")
}
conf.RPCUser = splitCookie[0]
conf.RPCPass = splitCookie[1]
}
if conf.RPCUser != "" && conf.RPCPass != "" {
// If all of RPCUser, RPCPass, ZMQBlockHost, and
// ZMQTxHost are set, we assume those parameters are
@ -1809,28 +1850,14 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
}
}
// Get the daemon name for displaying proper errors.
switch net {
case chainreg.BitcoinChain:
daemonName = "bitcoind"
confDir = conf.Dir
confFile = conf.ConfigPath
confFileBase = "bitcoin"
case chainreg.LitecoinChain:
daemonName = "litecoind"
confDir = conf.Dir
confFile = conf.ConfigPath
confFileBase = "litecoin"
}
// If not all of the parameters are set, we'll assume the user
// did this unintentionally.
if conf.RPCUser != "" || conf.RPCPass != "" ||
conf.ZMQPubRawBlock != "" || conf.ZMQPubRawTx != "" {
return fmt.Errorf("please set all or none of "+
"%[1]v.rpcuser, %[1]v.rpcpass, "+
"%[1]v.zmqpubrawblock, %[1]v.zmqpubrawtx",
return fmt.Errorf("please set %[1]v.rpcuser and "+
"%[1]v.rpcpass (or %[1]v.rpccookie) together "+
"with %[1]v.zmqpubrawblock, %[1]v.zmqpubrawtx",
daemonName)
}
}