Browse Source

it compiles again!

Adam Ierymenko 11 years ago
parent
commit
e22fae2397
3 changed files with 36 additions and 3 deletions
  1. 21 0
      control/NodeControlService.cpp
  2. 9 0
      control/NodeControlService.hpp
  3. 6 3
      main.cpp

+ 21 - 0
control/NodeControlService.cpp

@@ -226,4 +226,25 @@ void NodeControlService::_doCommand(IpcConnection *ipcc,const char *commandLine)
 	ipcc->printf("."ZT_EOL_S); // blank line ends response
 	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
 } // namespace ZeroTier

+ 9 - 0
control/NodeControlService.hpp

@@ -69,6 +69,15 @@ public:
 	void threadMain()
 	void threadMain()
 		throw();
 		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:
 private:
 	static void _CBcommandHandler(void *arg,IpcConnection *ipcc,IpcConnection::EventType event,const char *commandLine);
 	static void _CBcommandHandler(void *arg,IpcConnection *ipcc,IpcConnection::EventType event,const char *commandLine);
 	void _doCommand(IpcConnection *ipcc,const char *commandLine);
 	void _doCommand(IpcConnection *ipcc,const char *commandLine);

+ 6 - 3
main.cpp

@@ -72,6 +72,9 @@
 #include "node/EthernetTapFactory.hpp"
 #include "node/EthernetTapFactory.hpp"
 #include "node/RoutingTable.hpp"
 #include "node/RoutingTable.hpp"
 
 
+#include "control/NodeControlClient.hpp"
+#include "control/NodeControlService.hpp"
+
 #ifdef __WINDOWS__
 #ifdef __WINDOWS__
 #include "osnet/WindowsEthernetTapFactory.hpp"
 #include "osnet/WindowsEthernetTapFactory.hpp"
 #include "osnet/WindowsRoutingTable.hpp"
 #include "osnet/WindowsRoutingTable.hpp"
@@ -152,7 +155,7 @@ static int main(const char *homeDir,int argc,char **argv)
 
 
 	try {
 	try {
 		volatile bool done = false;
 		volatile bool done = false;
-		Node::NodeControlClient client(homeDir,&_CBresultHandler,(void *)&done);
+		NodeControlClient client(homeDir,&_CBresultHandler,(void *)&done);
 		const char *err = client.error();
 		const char *err = client.error();
 		if (err) {
 		if (err) {
 			fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],err);
 			fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],err);
@@ -778,7 +781,7 @@ int main(int argc,char **argv)
 			}	break;
 			}	break;
 #else // __UNIX_LIKE__
 #else // __UNIX_LIKE__
 			case Node::NODE_RESTART_FOR_UPGRADE: {
 			case Node::NODE_RESTART_FOR_UPGRADE: {
-				const char *upgPath = node->reasonForTermination();
+				const char *upgPath = node->terminationMessage();
 				// On Unix-type OSes we exec() right into the upgrade. This in turn will
 				// On Unix-type OSes we exec() right into the upgrade. This in turn will
 				// end with us being re-launched either via the upgrade itself or something
 				// end with us being re-launched either via the upgrade itself or something
 				// like OSX's launchd.
 				// like OSX's launchd.
@@ -797,7 +800,7 @@ int main(int argc,char **argv)
 
 
 			case Node::NODE_UNRECOVERABLE_ERROR: {
 			case Node::NODE_UNRECOVERABLE_ERROR: {
 				exitCode = 3;
 				exitCode = 3;
-				const char *termReason = node->reasonForTermination();
+				const char *termReason = node->terminationMessage();
 				fprintf(stderr,"%s: abnormal termination: %s\n",argv[0],(termReason) ? termReason : "(unknown reason)");
 				fprintf(stderr,"%s: abnormal termination: %s\n",argv[0],(termReason) ? termReason : "(unknown reason)");
 			}	break;
 			}	break;