Wire API auth token stuff.

This commit is contained in:
Adam Ierymenko 2015-04-15 19:14:12 -07:00
parent c301d8e438
commit 21a7e774bb
4 changed files with 46 additions and 21 deletions

18
one.cpp
View file

@ -68,7 +68,6 @@
#include "controller/SqliteNetworkController.hpp"
#endif
#define ZT1_AUTHTOKEN_SECRET_PATH "authtoken.secret"
#define ZT1_PID_PATH "zerotier-one.pid"
#define ZT1_CONTROLLER_DB_PATH "controller.db"
@ -643,23 +642,6 @@ int main(int argc,char **argv)
}
}
std::string authToken;
{
std::string authTokenPath(homeDir + ZT_PATH_SEPARATOR_S + ZT1_AUTHTOKEN_SECRET_PATH);
if (!OSUtils::readFile(authTokenPath.c_str(),authToken)) {
unsigned char foo[24];
Utils::getSecureRandom(foo,sizeof(foo));
authToken = "";
for(unsigned int i=0;i<sizeof(foo);++i)
authToken.push_back("abcdefghijklmnopqrstuvwxyz0123456789"[(unsigned long)foo[i] % 36]);
if (!OSUtils::writeFile(authTokenPath.c_str(),authToken)) {
fprintf(stderr,"%s: cannot create authtoken.secret"ZT_EOL_S,argv[0]);
return 1;
} else OSUtils::lockDownFile(authTokenPath.c_str(),false);
}
}
authToken = Utils::trim(authToken);
#ifdef __UNIX_LIKE__
if (getuid() != 0) {
fprintf(stderr,"%s: must be run as root (uid 0)"ZT_EOL_S,argv[0]);