| 276 | } |
| 277 | |
| 278 | static bool InitRPCAuthentication() { |
| 279 | strRPCUserColonPass = |
| 280 | SysCfg().GetArg("-rpcuser", "") + ":" + SysCfg().GetArg("-rpcpassword", ""); |
| 281 | string rpcuser = SysCfg().GetArg("-rpcuser", ""); |
| 282 | string rpcpassword = SysCfg().GetArg("-rpcpassword", ""); |
| 283 | // RPC user/password required but empty or equal to each other |
| 284 | if (SysCfg().RequireRPCPassword() && (rpcuser == "" || rpcuser == rpcpassword)) { |
| 285 | unsigned char rand_pwd[32]; |
| 286 | RAND_bytes(rand_pwd, 32); |
| 287 | string strWhatAmI = "To use coind"; |
| 288 | |
| 289 | if (SysCfg().IsArgCount("-rpcserver")) { |
| 290 | strWhatAmI = strprintf(_("To use the %s option"), "\"-rpcserver\""); |
| 291 | |
| 292 | } else if (SysCfg().IsArgCount("-daemon")) { |
| 293 | strWhatAmI = strprintf(_("To use the %s option"), "\"-daemon\""); |
| 294 | } |
| 295 | |
| 296 | LogPrint(BCLog::ERROR, "%s, you must set a rpcpassword in the configuration file:\n" |
| 297 | "%s\n" |
| 298 | "It is recommended you use the following random password:\n" |
| 299 | "rpcuser=wiccrpc\n" |
| 300 | "rpcpassword=%s\n" |
| 301 | "(you do not need to remember this password)\n" |
| 302 | "The username and password MUST NOT be the same.\n" |
| 303 | "If the file does not exist, create it with owner-readable-only file " |
| 304 | "permissions.\n" |
| 305 | "It is also recommended to set alertnotify so you are notified of problems;\n" |
| 306 | "for example: alertnotify=echo %%s | mail -s \"Coin Alert\" admin@foo.com\n", |
| 307 | strWhatAmI, GetConfigFile().string(), |
| 308 | EncodeBase58(&rand_pwd[0], &rand_pwd[0] + 32)); |
| 309 | |
| 310 | StartShutdown(); |
| 311 | return false; |
| 312 | } |
| 313 | |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | bool StartRPCServer() { |
| 318 | LogPrint(BCLog::INFO, "Starting HTTP RPC server\n"); |
no test coverage detected