1 /* 2 * Copyright (c)2019 ZeroTier, Inc. 3 * 4 * Use of this software is governed by the Business Source License included 5 * in the LICENSE.TXT file in the project's root directory. 6 * 7 * Change Date: 2025-01-01 8 * 9 * On the date above, in accordance with the Business Source License, use 10 * of this software will be governed by version 2.0 of the Apache License. 11 */ 12 /****/ 13 14 #pragma once 15 16 #if defined(_WIN32) || defined(_WIN64) 17 18 #include <stdio.h> 19 20 #include "ServiceBase.h" 21 22 #include <string> 23 24 #include "../../node/Mutex.hpp" 25 #include "../../osdep/Thread.hpp" 26 #include "../../service/OneService.hpp" 27 28 // Uncomment to make debugging Windows services suck slightly less hard. 29 //#define ZT_DEBUG_SERVICE "C:\\ZeroTierOneServiceDebugLog.txt" 30 31 #ifdef ZT_DEBUG_SERVICE 32 extern FILE *SVCDBGfile; 33 extern ZeroTier::Mutex SVCDBGfile_m; 34 #define ZT_SVCDBG(f,...) { SVCDBGfile_m.lock(); fprintf(SVCDBGfile,f,##__VA_ARGS__); fflush(SVCDBGfile); SVCDBGfile_m.unlock(); } 35 #else 36 #define ZT_SVCDBG(f,...) {} 37 #endif 38 39 #define ZT_SERVICE_NAME "ZeroTierOneService" 40 #define ZT_SERVICE_DISPLAY_NAME "ZeroTier One" 41 #define ZT_SERVICE_START_TYPE SERVICE_AUTO_START 42 #define ZT_SERVICE_DEPENDENCIES "" 43 //#define ZT_SERVICE_ACCOUNT "NT AUTHORITY\\LocalService" 44 #define ZT_SERVICE_ACCOUNT NULL 45 #define ZT_SERVICE_PASSWORD NULL 46 47 class ZeroTierOneService : public CServiceBase 48 { 49 public: 50 ZeroTierOneService(); 51 virtual ~ZeroTierOneService(void); 52 53 /** 54 * Thread main method; do not call elsewhere 55 */ 56 void threadMain() 57 throw(); 58 59 protected: 60 virtual void OnStart(DWORD dwArgc, PSTR *pszArgv); 61 virtual void OnStop(); 62 virtual void OnShutdown(); 63 64 private: 65 std::string _path; 66 ZeroTier::OneService *volatile _service; 67 ZeroTier::Mutex _lock; 68 ZeroTier::Thread _thread; 69 }; 70 71 #endif 72