Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/protocol.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | bool GenerateAuthCookie(std::string *cookie_out) { | ||||
/** the umask determines what permissions are used to create this file - | /** the umask determines what permissions are used to create this file - | ||||
* these are set to 077 in init.cpp unless overridden with -sysperms. | * these are set to 077 in init.cpp unless overridden with -sysperms. | ||||
*/ | */ | ||||
std::ofstream file; | std::ofstream file; | ||||
fs::path filepath = GetAuthCookieFile(); | fs::path filepath = GetAuthCookieFile(); | ||||
file.open(filepath.string().c_str()); | file.open(filepath.string().c_str()); | ||||
if (!file.is_open()) { | if (!file.is_open()) { | ||||
LogPrintf("Unable to open cookie authentication file %s for writing\n", | LogPrint(BCLog::RPC, | ||||
"Unable to open cookie authentication file %s for writing\n", | |||||
filepath.string()); | filepath.string()); | ||||
return false; | return false; | ||||
} | } | ||||
file << cookie; | file << cookie; | ||||
file.close(); | file.close(); | ||||
LogPrintf("Generated RPC authentication cookie %s\n", filepath.string()); | LogPrint(BCLog::RPC, "Generated RPC authentication cookie %s\n", | ||||
filepath.string()); | |||||
if (cookie_out) { | if (cookie_out) { | ||||
*cookie_out = cookie; | *cookie_out = cookie; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool GetAuthCookie(std::string *cookie_out) { | bool GetAuthCookie(std::string *cookie_out) { | ||||
Show All 12 Lines | bool GetAuthCookie(std::string *cookie_out) { | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void DeleteAuthCookie() { | void DeleteAuthCookie() { | ||||
try { | try { | ||||
fs::remove(GetAuthCookieFile()); | fs::remove(GetAuthCookieFile()); | ||||
} catch (const fs::filesystem_error &e) { | } catch (const fs::filesystem_error &e) { | ||||
LogPrintf("%s: Unable to remove random auth cookie file: %s\n", | LogPrint(BCLog::RPC, | ||||
__func__, e.what()); | "%s: Unable to remove random auth cookie file: %s\n", __func__, | ||||
e.what()); | |||||
} | } | ||||
} | } |