mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-21 13:54:15 -07:00
it compiles again!
This commit is contained in:
parent
73dd9d3b74
commit
e22fae2397
3 changed files with 36 additions and 3 deletions
|
@ -226,4 +226,25 @@ void NodeControlService::_doCommand(IpcConnection *ipcc,const char *commandLine)
|
|||
ipcc->printf("."ZT_EOL_S); // blank line ends response
|
||||
}
|
||||
|
||||
std::string NodeControlService::readOrCreateAuthtoken(const char *path,bool generateIfNotFound)
|
||||
{
|
||||
unsigned char randbuf[24];
|
||||
std::string token;
|
||||
|
||||
if (Utils::readFile(path,token))
|
||||
return token;
|
||||
else token = "";
|
||||
|
||||
if (generateIfNotFound) {
|
||||
Utils::getSecureRandom(randbuf,sizeof(randbuf));
|
||||
for(unsigned int i=0;i<sizeof(randbuf);++i)
|
||||
token.push_back(("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")[(unsigned int)randbuf[i] % 62]);
|
||||
if (!Utils::writeFile(path,token))
|
||||
return std::string();
|
||||
Utils::lockDownFile(path,false);
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -69,6 +69,15 @@ public:
|
|||
void threadMain()
|
||||
throw();
|
||||
|
||||
/**
|
||||
* Load (or generate) the authentication token
|
||||
*
|
||||
* @param path Full path to authtoken.secret
|
||||
* @param generateIfNotFound If true, generate and save if not found or readable
|
||||
* @return Authentication token or empty string on failure
|
||||
*/
|
||||
static std::string readOrCreateAuthtoken(const char *path,bool generateIfNotFound);
|
||||
|
||||
private:
|
||||
static void _CBcommandHandler(void *arg,IpcConnection *ipcc,IpcConnection::EventType event,const char *commandLine);
|
||||
void _doCommand(IpcConnection *ipcc,const char *commandLine);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue