Source code of Windows XP (NT5)
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.

293 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. certnotf.hxx
  5. Abstract:
  6. Definitions and data structures needed to deal with cert store change notifications
  7. Author:
  8. Alex Mallet (amallet) 17-Dec-1997
  9. --*/
  10. #ifndef _CERTNOTF_HXX_
  11. #define _CERTNOTF_HXX_
  12. #if !defined( dllexp)
  13. #define dllexp __declspec( dllexport)
  14. #endif // !defined( dllexp)
  15. typedef VOID (*NOTIFFNCPTR) ( LPVOID pvParam ) ;
  16. #define INVALID_FNC_PTR (-1)
  17. //
  18. // Define signatures "backwards" so they read the right way around in debugger
  19. //
  20. #define NOTIFIER_GOOD_SIG (DWORD) 'FTON'
  21. #define NOTIFIER_BAD_SIG (DWORD) 'fton'
  22. #define STORE_ENTRY_GOOD_SIG (DWORD) 'EHCS'
  23. #define STORE_ENTRY_BAD_SIG (DWORD) 'ehcs'
  24. class STORE_CHANGE_NOTIFIER;
  25. //
  26. // Link in linked list containing notification functions to be called
  27. //
  28. typedef struct _NotifFncChainEntry {
  29. NOTIFFNCPTR pNotifFnc; //pointer to function
  30. LPVOID pvParam; //parameter for function
  31. LIST_ENTRY ListEntry;
  32. } NOTIF_FNC_CHAIN_ENTRY, *PNOTIF_FNC_CHAIN_ENTRY;
  33. //
  34. // Class containing data for each store being watched
  35. //
  36. class STORE_CHANGE_ENTRY {
  37. public:
  38. STORE_CHANGE_ENTRY( STORE_CHANGE_NOTIFIER *pNotifier,
  39. LPSTR pszStoreName,
  40. HCERTSTORE hStore,
  41. NOTIFFNCPTR pFncPtr,
  42. PVOID pvParam );
  43. ~STORE_CHANGE_ENTRY();
  44. //
  45. // For functions that return variables that can't be changed after the initial construction
  46. // of the object, there are no calls to Lock()/Unlock() because all callers will
  47. // get the same [valid] value
  48. //
  49. DWORD GetLastError()
  50. {
  51. DWORD dwError = 0;
  52. Lock();
  53. dwError = m_dwError;
  54. Unlock();
  55. return dwError;
  56. }
  57. BOOL CheckSignature()
  58. {
  59. DWORD dwSig = 0;
  60. Lock();
  61. dwSig = m_dwSignature;
  62. Unlock();
  63. return ( dwSig == STORE_ENTRY_GOOD_SIG ? TRUE : FALSE );
  64. }
  65. BOOL ContainsNotifFnc( NOTIFFNCPTR pFncPtr,
  66. LPVOID pvParam );
  67. BOOL AddNotifFnc( NOTIFFNCPTR pFncPtr,
  68. LPVOID pvParam );
  69. BOOL RemoveNotifFnc( NOTIFFNCPTR pFncPtr,
  70. LPVOID pvParam );
  71. BOOL HasNotifFncs()
  72. {
  73. BOOL fEmpty = FALSE;
  74. Lock();
  75. fEmpty = IsListEmpty( &m_NotifFncChain );
  76. Unlock();
  77. return !fEmpty;
  78. }
  79. LPSTR QueryStoreName() { return m_strStoreName.QueryStr() ; }
  80. LIST_ENTRY* QueryNotifFncChain() { return &(m_NotifFncChain) ; }
  81. HCERTSTORE QueryStoreHandle() { return m_hCertStore; }
  82. HANDLE QueryStoreEvent() { return m_hStoreEvent; }
  83. HANDLE* QueryEventHandleAddr() { return &m_hStoreEvent; }
  84. HANDLE QueryWaitHandle()
  85. {
  86. HANDLE hHandle;
  87. Lock();
  88. hHandle = m_hWaitHandle;
  89. Unlock();
  90. return hHandle;
  91. }
  92. STORE_CHANGE_NOTIFIER* QueryNotifier() { return m_pNotifier; }
  93. BOOL Matches( IN LPSTR pszStoreName,
  94. IN NOTIFFNCPTR pFncPtr,
  95. IN PVOID pvParam );
  96. //
  97. // Synchronization functions
  98. //
  99. VOID Lock() { EnterCriticalSection( &m_CS ); }
  100. VOID Unlock() { LeaveCriticalSection( &m_CS ); }
  101. //
  102. // Public Member variable needed so this object can be included in a LIST_ENTRY
  103. // structure
  104. //
  105. LIST_ENTRY m_StoreListEntry;
  106. friend class STORE_CHANGE_NOTIFIER;
  107. static DWORD m_dwNumEntries;
  108. static DWORD QueryStoreEntryCount() { return m_dwNumEntries ; }
  109. private:
  110. VOID MarkInvalid()
  111. {
  112. Lock();
  113. m_fInvalid = TRUE;
  114. Unlock();
  115. }
  116. BOOL IsInvalid()
  117. {
  118. BOOL fInvalid = FALSE;
  119. Lock();
  120. fInvalid = m_fInvalid;
  121. Unlock();
  122. return fInvalid;
  123. }
  124. VOID MarkForDelete()
  125. {
  126. Lock();
  127. m_fDeleteMe = TRUE;
  128. Unlock();
  129. }
  130. BOOL IsMarkedForDelete()
  131. {
  132. BOOL fMarked = FALSE;
  133. Lock();
  134. fMarked = m_fDeleteMe;
  135. Unlock();
  136. return fMarked;
  137. }
  138. DWORD m_dwSignature; //signature, used for debugging
  139. STORE_CHANGE_NOTIFIER *m_pNotifier; //pointer to "parent" object
  140. HCERTSTORE m_hCertStore; //handle to cert store being watched
  141. STR m_strStoreName; //Store name
  142. HANDLE m_hStoreEvent; //event that is signalled when store changes
  143. HANDLE m_hWaitHandle; //handle returned from call to RegisterWaitForSingleObject()
  144. LIST_ENTRY m_NotifFncChain; //Functions to be called for changes to this store
  145. DWORD m_dwRefCount; //ref count for this object
  146. DWORD m_dwError; //internal error state
  147. //
  148. // Variables used to aid cleanup
  149. //
  150. BOOL m_fDeleteMe;
  151. BOOL m_fInvalid;
  152. static VOID IncrementStoreEntryCount()
  153. {
  154. InterlockedIncrement((LPLONG) &(STORE_CHANGE_ENTRY::m_dwNumEntries) );
  155. }
  156. static VOID DecrementStoreEntryCount()
  157. {
  158. InterlockedDecrement((LPLONG) &(STORE_CHANGE_ENTRY::m_dwNumEntries) );
  159. }
  160. CRITICAL_SECTION m_CS;
  161. };
  162. typedef STORE_CHANGE_ENTRY *PSTORE_CHANGE_ENTRY;
  163. class STORE_CHANGE_NOTIFIER
  164. {
  165. public:
  166. dllexp STORE_CHANGE_NOTIFIER();
  167. dllexp ~STORE_CHANGE_NOTIFIER();
  168. dllexp BOOL IsStoreRegisteredForChange( IN LPTSTR pszStoreName,
  169. IN NOTIFFNCPTR pFncPtr,
  170. IN LPVOID pvParam );
  171. dllexp BOOL RegisterStoreForChange( IN LPTSTR pszStoreName,
  172. IN HCERTSTORE hStore,
  173. IN NOTIFFNCPTR pFncPtr,
  174. IN LPVOID pvParam );
  175. dllexp VOID UnregisterStore( IN LPTSTR pszStoreName,
  176. NOTIFFNCPTR pFncPtr,
  177. IN LPVOID pvParam );
  178. #if DBG
  179. dllexp VOID DumpRegisteredStores();
  180. #endif
  181. dllexp VOID ReleaseRegisteredStores();
  182. dllexp static VOID NTAPI NotifFncCaller( LPVOID pv,
  183. BOOLEAN fBoolean );
  184. static VOID Lock() { EnterCriticalSection( STORE_CHANGE_NOTIFIER::m_pStoreListCS ) ; }
  185. static VOID Unlock() { LeaveCriticalSection( STORE_CHANGE_NOTIFIER::m_pStoreListCS ) ; }
  186. private:
  187. PSTORE_CHANGE_ENTRY InternalIsStoreRegisteredForChange( IN LPTSTR pszStoreName,
  188. IN NOTIFFNCPTR pFncPtr,
  189. IN LPVOID pvParam );
  190. BOOL CheckSignature() { return ( m_dwSignature == NOTIFIER_GOOD_SIG ? TRUE : FALSE ); }
  191. VOID StartCleanup( PSTORE_CHANGE_ENTRY pEntry );
  192. DWORD m_dwSignature;
  193. LIST_ENTRY m_StoreList; //list of STORE_CHANGE_ENTRY entries for stores being watched
  194. static CRITICAL_SECTION *m_pStoreListCS;
  195. };
  196. BOOL CopyString( LPTSTR *ppszDest,
  197. LPTSTR pszSrc );
  198. LIST_ENTRY* CopyNotifFncChain( LIST_ENTRY *pNotifFncChain );
  199. VOID DeallocateNotifFncChain( LIST_ENTRY *pNotifFncChain );
  200. #endif // _CERTNOTF_HXX_