Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

455 lines
9.3 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: srvlist.h
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #ifndef __TLSERVER_LIST__
  13. #define __TLSERVER_LIST__
  14. #include "srvdef.h"
  15. #include "tlsapi.h"
  16. #include "tlsdef.h"
  17. #include "tlsstl.h"
  18. class CTLServerInfo;
  19. class CTLServerMgr;
  20. typedef struct _MapSetupIdToInfo {
  21. //
  22. // Setup ID could never change unless
  23. // system crash
  24. //
  25. LPCTSTR pszSetupId;
  26. } MapSetupIdToInfo;
  27. #define TLSERVER_UNKNOWN 0x00000000
  28. #define TLSERVER_OLDVERSION 0x80000000
  29. #define TLSERVER_SUPPORTREPLICATION 0x00000010
  30. typedef struct _TLServerInfo {
  31. TCHAR m_szDomainName[LSERVER_MAX_STRING_SIZE + 2];
  32. TCHAR m_szServerName[MAX_COMPUTERNAME_LENGTH + 2];
  33. TCHAR m_szSetupId[MAX_JETBLUE_TEXT_LENGTH+2];
  34. DWORD m_dwTLSVersion; // Server version
  35. DWORD m_dwCapability;
  36. DWORD m_dwPushAnnounceTimes;
  37. FILETIME m_dwLastSyncTime; // Last Sync Time.
  38. //------------------------------------------------------------
  39. _TLServerInfo() :
  40. m_dwTLSVersion(0),
  41. m_dwCapability(TLSERVER_UNKNOWN),
  42. m_dwPushAnnounceTimes(0)
  43. {
  44. memset(m_szDomainName, 0, sizeof(m_szDomainName));
  45. memset(m_szServerName, 0, sizeof(m_szServerName));
  46. memset(m_szSetupId, 0, sizeof(m_szSetupId));
  47. memset(&m_dwLastSyncTime, 0, sizeof(FILETIME));
  48. }
  49. //-----------------------------------------------------------
  50. _TLServerInfo(
  51. IN LPCTSTR pszSetupId,
  52. IN LPCTSTR pszDomainName,
  53. IN LPCTSTR pszServerName
  54. ) :
  55. m_dwTLSVersion(0),
  56. m_dwCapability(TLSERVER_UNKNOWN)
  57. /*++
  58. --*/
  59. {
  60. memset(&m_dwLastSyncTime, 0, sizeof(FILETIME));
  61. memset(m_szDomainName, 0, sizeof(m_szDomainName));
  62. memset(m_szServerName, 0, sizeof(m_szServerName));
  63. memset(m_szSetupId, 0, sizeof(m_szSetupId));
  64. lstrcpyn(
  65. m_szSetupId,
  66. pszSetupId,
  67. MAX_JETBLUE_TEXT_LENGTH + 1
  68. );
  69. lstrcpyn(
  70. m_szServerName,
  71. pszServerName,
  72. MAX_COMPUTERNAME_LENGTH + 1
  73. );
  74. lstrcpyn(
  75. m_szDomainName,
  76. pszDomainName,
  77. LSERVER_MAX_STRING_SIZE + 1
  78. );
  79. }
  80. //----------------------------------------------
  81. void
  82. UpdateServerName(
  83. IN LPCTSTR pszServerName
  84. )
  85. /*++
  86. Abstract:
  87. Update Server name.
  88. Parameter:
  89. pszServerName : new server name.
  90. Returns:
  91. None.
  92. Remark:
  93. Server ID can't be changed but server name can,
  94. license server doesn't announce its shutdown so
  95. on next boot, user might have change the machine
  96. name.
  97. --*/
  98. {
  99. memset(m_szServerName, 0, sizeof(m_szServerName));
  100. lstrcpyn(
  101. m_szServerName,
  102. pszServerName,
  103. MAX_COMPUTERNAME_LENGTH + 1
  104. );
  105. }
  106. //----------------------------------------------
  107. BOOL
  108. IsAnnounced()
  109. /*++
  110. detemine if local server already announce
  111. anything to this server.
  112. --*/
  113. {
  114. return m_dwPushAnnounceTimes > 0;
  115. }
  116. //----------------------------------------------
  117. void
  118. UpdateLastSyncTime(
  119. FILETIME* pftTime
  120. )
  121. /*++
  122. Update last push sync. time that is initiate
  123. from local server to this server.
  124. --*/
  125. {
  126. m_dwLastSyncTime = *pftTime;
  127. }
  128. //----------------------------------------------
  129. void
  130. GetLastSyncTime(
  131. FILETIME* pftTime
  132. )
  133. /*++
  134. Retrieve last push sync. time that is initiate
  135. from local server to this server.
  136. --*/
  137. {
  138. *pftTime = m_dwLastSyncTime;
  139. }
  140. //----------------------------------------------
  141. DWORD
  142. GetServerVersion()
  143. /*++
  144. Get this remote server's version information.
  145. --*/
  146. {
  147. return m_dwTLSVersion;
  148. }
  149. //----------------------------------------------
  150. DWORD
  151. GetServerMajorVersion()
  152. /*++
  153. Get this remote server's major version.
  154. --*/
  155. {
  156. return GET_SERVER_MAJOR_VERSION(m_dwTLSVersion);
  157. }
  158. //----------------------------------------------
  159. DWORD
  160. GetServerMinorVersion()
  161. /*++
  162. Get this remote server's minor version.
  163. --*/
  164. {
  165. return GET_SERVER_MINOR_VERSION(m_dwTLSVersion);
  166. }
  167. //----------------------------------------------
  168. BOOL
  169. IsServerEnterpriseServer()
  170. /*++
  171. Check if this remote server is a enterprise server
  172. --*/
  173. {
  174. return IS_ENTERPRISE_SERVER(m_dwTLSVersion);
  175. }
  176. //----------------------------------------------
  177. BOOL
  178. IsEnforceServer()
  179. /*++
  180. Check if this remote server is a enforce license
  181. server.
  182. --*/
  183. {
  184. return IS_ENFORCE_SERVER(m_dwTLSVersion);
  185. }
  186. //----------------------------------------------
  187. LPTSTR
  188. GetServerName()
  189. {
  190. return m_szServerName;
  191. }
  192. //----------------------------------------------
  193. LPTSTR
  194. GetServerDomain()
  195. {
  196. return m_szDomainName;
  197. }
  198. //----------------------------------------------
  199. LPTSTR
  200. GetServerId()
  201. {
  202. return m_szSetupId;
  203. }
  204. //----------------------------------------------
  205. DWORD
  206. GetServerCapability()
  207. /*++
  208. For future version only
  209. --*/
  210. {
  211. DWORD dwCap;
  212. dwCap = m_dwCapability;
  213. return dwCap;
  214. }
  215. //----------------------------------------------
  216. BOOL
  217. IsServerSupportReplication() {
  218. return (BOOL)(m_dwCapability & TLSERVER_SUPPORTREPLICATION);
  219. }
  220. } TLServerInfo, *PTLServerInfo, *LPTLServerInfo;
  221. //---------------------------------------------------------
  222. class CTLServerMgr {
  223. private:
  224. typedef map<MapSetupIdToInfo, PTLServerInfo, less<MapSetupIdToInfo> > MapIdToInfo;
  225. CRWLock m_ReadWriteLock; // reader/writer lock on m_Handles.
  226. MapIdToInfo m_Handles;
  227. MapIdToInfo::iterator enumIterator;
  228. public:
  229. CTLServerMgr();
  230. ~CTLServerMgr();
  231. //
  232. // Add server to list
  233. DWORD
  234. AddServerToList(
  235. IN LPCTSTR pszSetupId,
  236. IN LPCTSTR pszDomainName,
  237. IN LPCTSTR pszServerName
  238. );
  239. DWORD
  240. AddServerToList(
  241. IN PTLServerInfo pServerInfo
  242. );
  243. //
  244. // Lookup function
  245. DWORD
  246. LookupBySetupId(
  247. IN LPCTSTR pszSetupId,
  248. OUT PTLServerInfo pServerInfo
  249. );
  250. DWORD
  251. LookupByServerName(
  252. LPCTSTR pszServerName,
  253. OUT PTLServerInfo pServerInfo
  254. );
  255. void
  256. ServerListEnumBegin();
  257. const PTLServerInfo
  258. ServerListEnumNext();
  259. void
  260. ServerListEnumEnd();
  261. };
  262. //----------------------------------------------------------
  263. inline bool
  264. operator<(
  265. const MapSetupIdToInfo& a,
  266. const MapSetupIdToInfo& b
  267. )
  268. /*++
  269. ++*/
  270. {
  271. int iComp = _tcsicmp(a.pszSetupId, b.pszSetupId);
  272. return iComp < 0;
  273. }
  274. #ifdef __cplusplus
  275. extern "C" {
  276. #endif
  277. void
  278. TLSBeginEnumKnownServerList();
  279. const PTLServerInfo
  280. TLSGetNextKnownServer();
  281. void
  282. TLSEndEnumKnownServerList();
  283. DWORD
  284. TLSAnnounceServerToRemoteServerWithHandle(
  285. IN DWORD dwAnnounceType,
  286. IN TLS_HANDLE hHandle,
  287. IN LPTSTR pszLocalSetupId,
  288. IN LPTSTR pszLocalDomainName,
  289. IN LPTSTR pszLocalServerName,
  290. IN FILETIME* pftLocalLastShutdownTime
  291. );
  292. DWORD
  293. TLSAnnounceServerToRemoteServer(
  294. IN DWORD dwAnnounceType,
  295. IN LPTSTR pszRemoteSetupId,
  296. IN LPTSTR pszRemoteDomainName,
  297. IN LPTSTR pszRemoteServerName,
  298. IN LPTSTR pszLocalSetupId,
  299. IN LPTSTR pszLocalDomainName,
  300. IN LPTSTR pszLocalServerName,
  301. IN FILETIME* pftLocalLastShutdownTime
  302. );
  303. TLS_HANDLE
  304. TLSConnectAndEstablishTrust(
  305. IN LPTSTR pszServerName,
  306. IN HANDLE hHandle
  307. );
  308. DWORD
  309. TLSRetrieveServerInfo(
  310. TLS_HANDLE hHandle,
  311. PTLServerInfo pServerInfo
  312. );
  313. DWORD
  314. TLSLookupServerById(
  315. IN LPTSTR pszServerSetupId,
  316. OUT LPTSTR pszServer
  317. );
  318. DWORD
  319. TLSRegisterServerWithName(
  320. IN LPTSTR pszSetupId,
  321. IN LPTSTR pszDomainName,
  322. IN LPTSTR pszServerName
  323. );
  324. DWORD
  325. TLSRegisterServerWithHandle(
  326. IN TLS_HANDLE hHandle,
  327. OUT PTLServerInfo pServerInfo
  328. );
  329. DWORD
  330. TLSRegisterServerWithServerInfo(
  331. IN PTLServerInfo pServerInfo
  332. );
  333. DWORD
  334. TLSLookupRegisteredServer(
  335. IN LPTSTR pszSetupId,
  336. IN LPTSTR pszDomainName,
  337. IN LPTSTR pszServerName,
  338. OUT PTLServerInfo pServerInfo
  339. );
  340. TLS_HANDLE
  341. TLSConnectToServerWithServerId(
  342. LPTSTR pszServerSetupId
  343. );
  344. DWORD
  345. TLSLookupAnyEnterpriseServer(
  346. OUT PTLServerInfo pServerInfo
  347. );
  348. DWORD
  349. TLSResolveServerIdToServer(
  350. LPTSTR pszServerId,
  351. DWORD cbServerName,
  352. LPTSTR pszServerName
  353. );
  354. #ifdef __cplusplus
  355. }
  356. #endif
  357. #endif