From 22b52858e04c25709081251300fed6cdc42810be Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 3 Jan 2014 14:03:29 -0800 Subject: Fix -h in zerotier-cli and move code to find auth token into LocalClient, also move auth token for mac into Mac-standard Library/Application Support location. --- node/Node.cpp | 26 ++++++++++++++++++++++++++ node/Node.hpp | 10 ++++++++++ 2 files changed, 36 insertions(+) (limited to 'node') diff --git a/node/Node.cpp b/node/Node.cpp index cd8cfb5e..cbea5694 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -188,6 +188,32 @@ std::vector Node::LocalClient::splitLine(const char *line) return Utils::split(line," ","\\","\""); } +std::string Node::LocalClient::authTokenDefaultUserPath() +{ + const char *home = getenv("HOME"); + if (home) { +#ifdef __APPLE__ + return (std::string(home) + "/Library/Application Support/ZeroTier/One/authtoken.secret"); +#else + return (std::string(home) + "/.zeroTierOneAuthToken"); +#endif + } + return std::string(); +} + +std::string Node::LocalClient::authTokenDefaultSystemPath() +{ +#ifdef __WINDOWS__ + // TODO +#else +#ifdef __APPLE__ + return "/Library/Application Support/ZeroTier/One/authtoken.secret"; +#else + return "/var/lib/zerotier-one/authtoken.secret"; +#endif +#endif +} + struct _NodeImpl { RuntimeEnvironment renv; diff --git a/node/Node.hpp b/node/Node.hpp index 2736713f..a6410992 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -84,6 +84,16 @@ public: static std::vector splitLine(const char *line); static inline std::vector splitLine(const std::string &line) { return splitLine(line.c_str()); } + /** + * @return Default path for user-local authorization token for the current user or empty string if cannot be determined + */ + static std::string authTokenDefaultUserPath(); + + /** + * @return Default system path for auth token on this platform + */ + static std::string authTokenDefaultSystemPath(); + private: // LocalClient is not copyable LocalClient(const LocalClient&); -- cgit v1.2.3