diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-09-16 15:47:00 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-09-16 15:47:00 -0700 |
commit | e22fae2397f69302820b7a1af2fe2291bb6865e0 (patch) | |
tree | 9ecb4c23cc4235bd0ce204233402618a03d5a4c5 /control | |
parent | 73dd9d3b74ecee4d7da1368265c780d5464910e4 (diff) | |
download | infinitytier-e22fae2397f69302820b7a1af2fe2291bb6865e0.tar.gz infinitytier-e22fae2397f69302820b7a1af2fe2291bb6865e0.zip |
it compiles again!
Diffstat (limited to 'control')
-rw-r--r-- | control/NodeControlService.cpp | 21 | ||||
-rw-r--r-- | control/NodeControlService.hpp | 9 |
2 files changed, 30 insertions, 0 deletions
diff --git a/control/NodeControlService.cpp b/control/NodeControlService.cpp index a3b1eca6..536752cc 100644 --- a/control/NodeControlService.cpp +++ b/control/NodeControlService.cpp @@ -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 diff --git a/control/NodeControlService.hpp b/control/NodeControlService.hpp index 453e943b..737878e0 100644 --- a/control/NodeControlService.hpp +++ b/control/NodeControlService.hpp @@ -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); |