From f0223490becc9bba82297cd6316c87d2f89f2052 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 2 Apr 2014 17:12:04 -0700 Subject: Make GUI work with new control client API, make control client look for user authtoken.secret if system unreadable. --- node/Node.cpp | 43 +++++++++++++++++++++++-------------------- node/Node.hpp | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) (limited to 'node') diff --git a/node/Node.cpp b/node/Node.cpp index 051cb317..f9a0a614 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -109,27 +109,30 @@ Node::NodeControlClient::NodeControlClient(const char *hp,void (*resultHandler)( std::string at; if (authToken) at = authToken; - else if (!Utils::readFile((std::string(hp) + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),at)) - impl->err = "no authentication token specified and authtoken.secret not readable"; - else { - std::string myid; - if (Utils::readFile((std::string(hp) + ZT_PATH_SEPARATOR_S + "identity.public").c_str(),myid)) { - std::string myaddr(myid.substr(0,myid.find(':'))); - if (myaddr.length() != 10) - impl->err = "invalid address extracted from identity.public"; - else { - try { - impl->resultHandler = resultHandler; - impl->arg = arg; - impl->ipcc = new IpcConnection((std::string(ZT_IPC_ENDPOINT_BASE) + myaddr).c_str(),&_CBipcResultHandler,_impl); - impl->ipcc->printf("auth %s"ZT_EOL_S,at.c_str()); - } catch ( ... ) { - impl->ipcc = (IpcConnection *)0; - impl->err = "failure connecting to running ZeroTier One service"; - } - } - } else impl->err = "unable to read identity.public"; + else if (!Utils::readFile(authTokenDefaultSystemPath(),at)) { + if (!Utils::readFile(authTokenDefaultUserPath(),at)) { + impl->err = "no authentication token specified and authtoken.secret not readable"; + return; + } } + + std::string myid; + if (Utils::readFile((std::string(hp) + ZT_PATH_SEPARATOR_S + "identity.public").c_str(),myid)) { + std::string myaddr(myid.substr(0,myid.find(':'))); + if (myaddr.length() != 10) + impl->err = "invalid address extracted from identity.public"; + else { + try { + impl->resultHandler = resultHandler; + impl->arg = arg; + impl->ipcc = new IpcConnection((std::string(ZT_IPC_ENDPOINT_BASE) + myaddr).c_str(),&_CBipcResultHandler,_impl); + impl->ipcc->printf("auth %s"ZT_EOL_S,at.c_str()); + } catch ( ... ) { + impl->ipcc = (IpcConnection *)0; + impl->err = "failure connecting to running ZeroTier One service"; + } + } + } else impl->err = "unable to read identity.public"; } Node::NodeControlClient::~NodeControlClient() diff --git a/node/Node.hpp b/node/Node.hpp index ceb4e745..cc2886e7 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -58,7 +58,7 @@ public: * * Initialization may fail. Call error() to check. * - * @param hp Home path of ZeroTier One instance + * @param hp Home path of ZeroTier One instance or NULL for default system home path * @param resultHandler Function to call when commands provide results * @param arg First argument to result handler * @param authToken Authentication token or NULL (default) to read from authtoken.secret in home path -- cgit v1.2.3