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.

419 lines
7.8 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1999
  3. Module Name:
  4. scEvents
  5. Abstract:
  6. This module provides access to the Calais subsystem internal events.
  7. Currently two events are defined:
  8. Microsoft Smart Card Resource Manager Started - This event is set when the
  9. resource manager starts up.
  10. Microsoft Smart Card Resource Manager New Reader - This event is set when
  11. the resource manager adds a new reader via Plug 'n Play.
  12. Author:
  13. Doug Barlow (dbarlow) 7/1/1998
  14. Notes:
  15. ?Notes?
  16. --*/
  17. #define __SUBROUTINE__
  18. #ifndef WIN32_LEAN_AND_MEAN
  19. #define WIN32_LEAN_AND_MEAN
  20. #endif
  21. #include <windows.h>
  22. #include <winscard.h>
  23. #include <CalMsgs.h>
  24. #include <calcom.h>
  25. static HANDLE
  26. l_hStartedEvent = NULL,
  27. l_hNewReaderEvent = NULL,
  28. l_hStoppedEvent = NULL;
  29. /*++
  30. AccessStartedEvent:
  31. This function obtains a local handle to the Calais Resource Manager Start
  32. event. The handle must be released via the ReleaseStartedEvent
  33. service.
  34. Arguments:
  35. None
  36. Return Value:
  37. The Handle, or NULL if an error occurs.
  38. Throws:
  39. None
  40. Remarks:
  41. Programs other than the resource manager should only wait on these flags.
  42. Author:
  43. Doug Barlow (dbarlow) 7/1/1998
  44. --*/
  45. #undef __SUBROUTINE__
  46. #define __SUBROUTINE__ DBGT("AccessStartedEvent")
  47. HANDLE
  48. AccessStartedEvent(
  49. void)
  50. {
  51. if (NULL == l_hStartedEvent)
  52. {
  53. try
  54. {
  55. CSecurityDescriptor acl;
  56. acl.Initialize();
  57. acl.Allow(
  58. &acl.SID_LocalService,
  59. EVENT_ALL_ACCESS);
  60. acl.Allow(
  61. &acl.SID_Interactive,
  62. SYNCHRONIZE);
  63. acl.Allow(
  64. &acl.SID_System,
  65. SYNCHRONIZE);
  66. l_hStartedEvent =
  67. CreateEvent(
  68. acl, // pointer to security attributes
  69. TRUE, // flag for manual-reset event
  70. FALSE, // flag for initial state
  71. CalaisString(CALSTR_STARTEDEVENTNAME)); // event-object name
  72. if (NULL == l_hStartedEvent)
  73. {
  74. l_hStartedEvent = OpenEvent(SYNCHRONIZE, FALSE, CalaisString(CALSTR_STARTEDEVENTNAME));
  75. }
  76. }
  77. catch (...)
  78. {
  79. ASSERT(NULL == l_hStartedEvent);
  80. }
  81. }
  82. return l_hStartedEvent;
  83. }
  84. /*++
  85. AccessStoppedEvent:
  86. This function obtains a local handle to the Calais Resource Manager Stopped
  87. event.
  88. Arguments:
  89. None
  90. Return Value:
  91. The Handle, or NULL if an error occurs.
  92. Throws:
  93. None
  94. Remarks:
  95. Programs other than the resource manager should only wait on these flags.
  96. Author:
  97. --*/
  98. #undef __SUBROUTINE__
  99. #define __SUBROUTINE__ DBGT("AccessStoppedEvent")
  100. HANDLE
  101. AccessStoppedEvent(
  102. void)
  103. {
  104. if (NULL == l_hStoppedEvent)
  105. {
  106. try
  107. {
  108. CSecurityDescriptor acl;
  109. acl.Initialize();
  110. acl.Allow(
  111. &acl.SID_LocalService,
  112. EVENT_ALL_ACCESS);
  113. acl.Allow(
  114. &acl.SID_Interactive,
  115. SYNCHRONIZE);
  116. acl.Allow(
  117. &acl.SID_System,
  118. SYNCHRONIZE);
  119. l_hStoppedEvent =
  120. CreateEvent(
  121. acl, // pointer to security attributes
  122. TRUE, // flag for manual-reset event
  123. FALSE, // flag for initial state
  124. CalaisString(CALSTR_STOPPEDEVENTNAME)); // event-object name
  125. if (NULL == l_hStoppedEvent)
  126. {
  127. l_hStoppedEvent = OpenEvent(SYNCHRONIZE, FALSE, CalaisString(CALSTR_STOPPEDEVENTNAME));
  128. }
  129. }
  130. catch (...)
  131. {
  132. ASSERT(NULL == l_hStoppedEvent);
  133. }
  134. }
  135. return l_hStoppedEvent;
  136. }
  137. /*++
  138. AccessNewReaderEvent:
  139. This function obtains a local handle to the Calais Resource Manager's New
  140. Reader event. The handle must be released via the
  141. ReleaseNewReaderEvent service.
  142. Arguments:
  143. None
  144. Return Value:
  145. The Handle, or NULL if an error occurs.
  146. Throws:
  147. None
  148. Remarks:
  149. Programs other than the resource manager should only wait on these flags.
  150. Author:
  151. Doug Barlow (dbarlow) 7/1/1998
  152. --*/
  153. #undef __SUBROUTINE__
  154. #define __SUBROUTINE__ DBGT("AccessNewReaderEvent")
  155. HANDLE
  156. AccessNewReaderEvent(
  157. void)
  158. {
  159. if (NULL == l_hNewReaderEvent)
  160. {
  161. try
  162. {
  163. CSecurityDescriptor acl;
  164. acl.Initialize();
  165. acl.Allow(
  166. &acl.SID_LocalService,
  167. EVENT_ALL_ACCESS);
  168. acl.Allow(
  169. &acl.SID_Interactive,
  170. SYNCHRONIZE);
  171. acl.Allow(
  172. &acl.SID_System,
  173. SYNCHRONIZE);
  174. l_hNewReaderEvent
  175. = CreateEvent(
  176. acl, // pointer to security attributes
  177. TRUE, // flag for manual-reset event
  178. FALSE, // flag for initial state
  179. CalaisString(CALSTR_NEWREADEREVENTNAME)); // pointer to event-object name
  180. }
  181. catch (...)
  182. {
  183. ASSERT(NULL == l_hNewReaderEvent);
  184. }
  185. }
  186. return l_hNewReaderEvent;
  187. }
  188. /*++
  189. ReleaseStartedEvent:
  190. This function releases a previously accessed handle to the Calais
  191. Resource Manager Start event. The handle must be obtained via the
  192. AccessStartedEvent service.
  193. Arguments:
  194. None
  195. Return Value:
  196. None.
  197. Throws:
  198. None
  199. Remarks:
  200. Programs other than the resource manager should only wait on these flags.
  201. Author:
  202. Doug Barlow (dbarlow) 7/1/1998
  203. --*/
  204. #undef __SUBROUTINE__
  205. #define __SUBROUTINE__ DBGT("ReleaseStartedEvent")
  206. void
  207. ReleaseStartedEvent(
  208. void)
  209. {
  210. if (NULL != l_hStartedEvent)
  211. {
  212. CloseHandle(l_hStartedEvent);
  213. l_hStartedEvent = NULL;
  214. }
  215. }
  216. /*++
  217. ReleaseStoppedEvent:
  218. This function releases a previously accessed handle to the Calais
  219. Resource Manager Stopped event. The handle must be obtained via the
  220. AccessStoppedEvent service.
  221. Arguments:
  222. None
  223. Return Value:
  224. None.
  225. Throws:
  226. None
  227. Remarks:
  228. Programs other than the resource manager should only wait on these flags.
  229. --*/
  230. #undef __SUBROUTINE__
  231. #define __SUBROUTINE__ DBGT("ReleaseStoppedEvent")
  232. void
  233. ReleaseStoppedEvent(
  234. void)
  235. {
  236. if (NULL != l_hStoppedEvent)
  237. {
  238. CloseHandle(l_hStoppedEvent);
  239. l_hStoppedEvent = NULL;
  240. }
  241. }
  242. /*++
  243. ReleaseNewReaderEvent:
  244. This function releases a previously accessed handle to the Calais
  245. Resource Manager New Reader event. The handle must be obtained via the
  246. AccessNewReaderEvent service.
  247. Arguments:
  248. None
  249. Return Value:
  250. None.
  251. Throws:
  252. None
  253. Remarks:
  254. Programs other than the resource manager should only wait on these flags.
  255. Author:
  256. Doug Barlow (dbarlow) 7/1/1998
  257. --*/
  258. #undef __SUBROUTINE__
  259. #define __SUBROUTINE__ DBGT("ReleaseNewReaderEvent")
  260. void
  261. ReleaseNewReaderEvent(
  262. void)
  263. {
  264. if (NULL != l_hNewReaderEvent)
  265. {
  266. CloseHandle(l_hNewReaderEvent);
  267. l_hNewReaderEvent = NULL;
  268. }
  269. }
  270. /*++
  271. ReleaseAllEvents:
  272. This is a catch-all routine that releases all known special event handles.
  273. Arguments:
  274. None
  275. Return Value:
  276. None
  277. Throws:
  278. None
  279. Remarks:
  280. Author:
  281. Doug Barlow (dbarlow) 7/6/1998
  282. --*/
  283. #undef __SUBROUTINE__
  284. #define __SUBROUTINE__ DBGT("ReleaseAllEvents")
  285. void
  286. ReleaseAllEvents(
  287. void)
  288. {
  289. ReleaseNewReaderEvent();
  290. }