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.

390 lines
9.6 KiB

  1. //*************************************************************
  2. //
  3. // File name: TSrvInfo.c
  4. //
  5. // Description: Contains routines to support TShareSRV
  6. // TSrvInfo object manipulation
  7. //
  8. // Microsoft Confidential
  9. // Copyright (c) Microsoft Corporation 1991-1997
  10. // All rights reserved
  11. //
  12. //*************************************************************
  13. #include <TSrv.h>
  14. #include <TSrvInfo.h>
  15. #include <_TSrvInfo.h>
  16. #include <TSrvCom.h>
  17. #include <TSrvTerm.h>
  18. #include "license.h"
  19. #include <tssec.h>
  20. //
  21. // Data declarations
  22. //
  23. CRITICAL_SECTION g_TSrvCritSect;
  24. //*************************************************************
  25. //
  26. // TSrvReferenceInfo()
  27. //
  28. // Purpose: Increments the refCount on a TSrvInfo object
  29. //
  30. // Parameters: IN [pTSrvInfo] -- TSrv instance object
  31. //
  32. // Return: void
  33. //
  34. // History: 07-17-97 BrianTa Created
  35. //
  36. //*************************************************************
  37. VOID
  38. TSrvReferenceInfo(IN PTSRVINFO pTSrvInfo)
  39. {
  40. TRACE((DEBUG_TSHRSRV_FLOW,
  41. "TShrSRV: TSrvReferenceInfo entry\n"));
  42. TSrvInfoValidate(pTSrvInfo);
  43. TS_ASSERT(pTSrvInfo->RefCount >= 0);
  44. // Increment the reference count
  45. if (InterlockedIncrement(&pTSrvInfo->RefCount) <= 0 )
  46. TS_ASSERT(0);
  47. TRACE((DEBUG_TSHRSRV_FLOW,
  48. "TShrSRV: TSrvReferenceInfo exit\n"));
  49. }
  50. //*************************************************************
  51. //
  52. // TSrvDereferenceInfo()
  53. //
  54. // Purpose: Decrements the refCount on a TSrvInfo object
  55. //
  56. // Parameters: IN [pTSrvInfo] -- TSrv instance object
  57. //
  58. // Return: void
  59. //
  60. // History: 07-17-97 BrianTa Created
  61. //
  62. //*************************************************************
  63. VOID
  64. TSrvDereferenceInfo(IN PTSRVINFO pTSrvInfo)
  65. {
  66. TRACE((DEBUG_TSHRSRV_FLOW,
  67. "TShrSRV: TSrvDereferenceInfo entry\n"));
  68. TSrvInfoValidate(pTSrvInfo);
  69. TS_ASSERT(pTSrvInfo->RefCount > 0);
  70. // Decrement the reference count
  71. if (InterlockedDecrement(&pTSrvInfo->RefCount) == 0)
  72. {
  73. // If no one holds an outstanding refcount on this object,
  74. // then its time to release it
  75. TSrvDestroyInfo(pTSrvInfo);
  76. }
  77. TRACE((DEBUG_TSHRSRV_FLOW,
  78. "TShrSRV: TSrvDereferenceInfo exit\n"));
  79. }
  80. //*************************************************************
  81. //
  82. // TSrvInitGlobalData()
  83. //
  84. // Purpose: Performs TSrvInfoList object initialization
  85. //
  86. // Parameters: void
  87. //
  88. // Return: TRUE Success
  89. // FALSE Failure
  90. //
  91. // History: 07-17-97 BrianTa Created
  92. //
  93. //*************************************************************
  94. BOOL
  95. TSrvInitGlobalData(void)
  96. {
  97. TRACE((DEBUG_TSHRSRV_FLOW,
  98. "TShrSRV: TSrvInitGlobalData entry\n"));
  99. // Initialize the global crit sec
  100. if (RtlInitializeCriticalSection(&g_TSrvCritSect) == STATUS_SUCCESS) {
  101. //
  102. // Nothing to do
  103. //
  104. }
  105. else {
  106. TRACE((DEBUG_TSHRSRV_ERROR, "TShrSRV: cannot initialize g_TSrvCritSect\n"));
  107. return FALSE;
  108. }
  109. // For now, always successful
  110. TRACE((DEBUG_TSHRSRV_FLOW,
  111. "TShrSRV: TSrvInitGlobalData exit - 0x%x\n", TRUE));
  112. return (TRUE);
  113. }
  114. //*************************************************************
  115. //
  116. // TSrvAllocInfoNew()
  117. //
  118. // Purpose: Allocates a new TSRVINFO object
  119. //
  120. // Parameters: void
  121. //
  122. // Return: Ptr to TSRVINFO obj Success
  123. // NULL Failure
  124. //
  125. // History: 07-17-97 BrianTa Created
  126. //
  127. //*************************************************************
  128. PTSRVINFO
  129. TSrvAllocInfoNew(void)
  130. {
  131. PTSRVINFO pTSrvInfo;
  132. TRACE((DEBUG_TSHRSRV_FLOW,
  133. "TShrSRV: TSrvAllocInfoNew entry\n"));
  134. // Allocate the object - zero filled
  135. pTSrvInfo = TSHeapAlloc(HEAP_ZERO_MEMORY,
  136. sizeof(TSRVINFO),
  137. TS_HTAG_TSS_TSRVINFO);
  138. if (pTSrvInfo)
  139. {
  140. // Create a worker event to be used for inter and intra
  141. // thread syncronization
  142. pTSrvInfo->hWorkEvent = CreateEvent(NULL, // security attributes
  143. FALSE, // manual-reset event
  144. FALSE, // initial state
  145. NULL); // event-object name
  146. // If we are able to allocate the event, then perform base
  147. // initialization on it
  148. if (pTSrvInfo->hWorkEvent)
  149. {
  150. if (RtlInitializeCriticalSection(&pTSrvInfo->cs) == STATUS_SUCCESS) {
  151. #if DBG
  152. pTSrvInfo->CheckMark = TSRVINFO_CHECKMARK;
  153. #endif
  154. TSrvReferenceInfo(pTSrvInfo);
  155. TRACE((DEBUG_TSHRSRV_DEBUG,
  156. "TShrSRV: New info object allocated %p, workEvent %p\n",
  157. pTSrvInfo, pTSrvInfo->hWorkEvent));
  158. }
  159. else {
  160. TRACE((DEBUG_TSHRSRV_ERROR,
  161. "TShrSRV: can't initialize pTSrvInfo->cs\n"));
  162. CloseHandle(pTSrvInfo->hWorkEvent);
  163. TSHeapFree(pTSrvInfo);
  164. pTSrvInfo = NULL;
  165. }
  166. }
  167. else
  168. {
  169. // We could not allocate the event. Free the TSRVINFO object
  170. // and report the condition back to the caller
  171. TRACE((DEBUG_TSHRSRV_ERROR,
  172. "TShrSRV: Can't allocate hWorkEvent - 0x%x\n",
  173. GetLastError()));
  174. TSHeapFree(pTSrvInfo);
  175. pTSrvInfo = NULL;
  176. }
  177. }
  178. TRACE((DEBUG_TSHRSRV_FLOW,
  179. "TShrSRV: TSrvAllocInfoNew exit - %p\n", pTSrvInfo));
  180. return (pTSrvInfo);
  181. }
  182. //*************************************************************
  183. //
  184. // TSrvAllocInfo()
  185. //
  186. // Purpose: Performs the conf disconnect process
  187. //
  188. // Parameters: OUT [ppTSrvInfo] -- Ptr to ptr to receive
  189. // TSrv instance object
  190. //
  191. // Return: STATUS_SUCCESS Success
  192. // STATUS_NO_MEMORY Failure
  193. //
  194. // History: 07-17-97 BrianTa Created
  195. //
  196. //*************************************************************
  197. NTSTATUS
  198. TSrvAllocInfo(OUT PTSRVINFO *ppTSrvInfo,
  199. IN HANDLE hIca,
  200. IN HANDLE hStack)
  201. {
  202. NTSTATUS ntStatus;
  203. PTSRVINFO pTSrvInfo;
  204. TRACE((DEBUG_TSHRSRV_FLOW,
  205. "TShrSRV: TSrvAllocInfo entry\n"));
  206. ntStatus = STATUS_NO_MEMORY;
  207. // Try allocating a TSRVINFO object
  208. pTSrvInfo = TSrvAllocInfoNew();
  209. // If we managed to get a TSRVINFO object, perform
  210. // default base initialization
  211. if (pTSrvInfo)
  212. {
  213. pTSrvInfo->hDomain = NULL;
  214. pTSrvInfo->hIca = hIca;
  215. pTSrvInfo->hStack = hStack;
  216. pTSrvInfo->fDisconnect = FALSE;
  217. pTSrvInfo->fuConfState = TSRV_CONF_PENDING;
  218. pTSrvInfo->ulReason = 0;
  219. pTSrvInfo->ntStatus = STATUS_SUCCESS;
  220. pTSrvInfo->bSecurityEnabled = FALSE;
  221. pTSrvInfo->SecurityInfo.CertType = CERT_TYPE_INVALID;
  222. // Base init complete - now bind the Ica stack
  223. ntStatus = TSrvBindStack(pTSrvInfo);
  224. if (!NT_SUCCESS(ntStatus))
  225. {
  226. TSrvDereferenceInfo(pTSrvInfo);
  227. pTSrvInfo = NULL;
  228. }
  229. }
  230. *ppTSrvInfo = pTSrvInfo;
  231. TRACE((DEBUG_TSHRSRV_FLOW,
  232. "TShrSRV: TSrvAllocInfo exit - 0x%x\n", ntStatus));
  233. return (ntStatus);
  234. }
  235. //*************************************************************
  236. //
  237. // TSrvDestroyInfo()
  238. //
  239. // Purpose: Disposes of the given TSRVINFO object
  240. //
  241. // Parameters: IN [pTSrvInfo] -- TSrv instance object
  242. //
  243. // Return: void
  244. //
  245. // History: 07-17-97 BrianTa Created
  246. //
  247. //*************************************************************
  248. void
  249. TSrvDestroyInfo(IN PTSRVINFO pTSrvInfo)
  250. {
  251. NTSTATUS ntStatus;
  252. TRACE((DEBUG_TSHRSRV_FLOW,
  253. "TShrSRV: TSrvDestroyInfo entry\n"));
  254. TS_ASSERT(pTSrvInfo->RefCount == 0);
  255. TRACE((DEBUG_TSHRSRV_DEBUG,
  256. "TShrSRV: Destroying info object %p, workEvent %p\n",
  257. pTSrvInfo, pTSrvInfo->hWorkEvent));
  258. // Destroy the allocated worker event
  259. if (pTSrvInfo->hWorkEvent)
  260. {
  261. CloseHandle(pTSrvInfo->hWorkEvent);
  262. pTSrvInfo->hWorkEvent = NULL;
  263. }
  264. // Release any prev allocated UserData structures
  265. if (pTSrvInfo->pUserDataInfo)
  266. {
  267. TSHeapFree(pTSrvInfo->pUserDataInfo);
  268. pTSrvInfo->pUserDataInfo = NULL;
  269. }
  270. // And free the actual TSRVINFO object
  271. RtlDeleteCriticalSection(&pTSrvInfo->cs);
  272. TSHeapFree(pTSrvInfo);
  273. TRACE((DEBUG_TSHRSRV_FLOW,
  274. "TShrSRV: TSrvDestroyInfo exit\n"));
  275. }
  276. #if DBG
  277. //*************************************************************
  278. //
  279. // TSrvDoDisconnect()
  280. //
  281. // Purpose: Performs the conf disconnect process
  282. //
  283. // Parameters: IN [pTSrvInfo] -- TSrv instance object
  284. //
  285. // Return: STATUS_SUCCESS Success
  286. // Other Failure
  287. //
  288. // History: 07-17-97 BrianTa Created
  289. //
  290. //*************************************************************
  291. void
  292. TSrvInfoValidate(PTSRVINFO pTSrvInfo)
  293. {
  294. TS_ASSERT(pTSrvInfo);
  295. if (pTSrvInfo)
  296. {
  297. TSHeapValidate(0, pTSrvInfo, TS_HTAG_TSS_TSRVINFO);
  298. TS_ASSERT(pTSrvInfo->CheckMark == TSRVINFO_CHECKMARK);
  299. TS_ASSERT(pTSrvInfo->hWorkEvent);
  300. }
  301. }
  302. #endif // DBG