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.

220 lines
5.4 KiB

  1. #include <pch.cpp>
  2. #pragma hdrstop
  3. #include "crtem.h"
  4. //////////////////////////
  5. // OpenItem list
  6. COpenItemList::COpenItemList()
  7. {
  8. m_pfnIsMatch = OpenItemIsMatch;
  9. m_pfnFreeElt = OpenItemFreeElt;
  10. }
  11. void CreateOpenListItem(OPENITEM_LIST_ITEM* pli,
  12. PST_PROVIDER_HANDLE* phPSTProv,
  13. PST_KEY Key,
  14. const GUID* pguidType,
  15. const GUID* pguidSubtype,
  16. LPCWSTR szItemName)
  17. {
  18. pli->pNext = NULL;
  19. CopyMemory(&pli->hPSTProv, phPSTProv, sizeof(PST_PROVIDER_HANDLE));
  20. pli->Key = Key;
  21. CopyMemory(&pli->guidType, pguidType, sizeof(GUID));
  22. CopyMemory(&pli->guidSubtype, pguidSubtype, sizeof(GUID));
  23. pli->szItemName = (LPWSTR)szItemName;
  24. }
  25. BOOL OpenItemIsMatch(
  26. ELT* pCandidate,
  27. ELT* pTemplate)
  28. {
  29. POPENITEM_LIST_ITEM pliCandidate = (POPENITEM_LIST_ITEM) pCandidate;
  30. POPENITEM_LIST_ITEM pliTemplate = (POPENITEM_LIST_ITEM) pTemplate;
  31. if (
  32. (0 == memcmp(&pliCandidate->hPSTProv, &pliTemplate->hPSTProv, sizeof(PST_PROVIDER_HANDLE))) &&
  33. (pliCandidate->Key == pliTemplate->Key) &&
  34. (0 == memcmp(&pliCandidate->guidType, &pliTemplate->guidType, sizeof(GUID))) &&
  35. (0 == memcmp(&pliCandidate->guidSubtype, &pliTemplate->guidSubtype, sizeof(GUID))) &&
  36. (0 == wcscmp(pliCandidate->szItemName, pliTemplate->szItemName))
  37. )
  38. return TRUE;
  39. return FALSE;
  40. }
  41. void OpenItemFreeElt(
  42. ELT* p)
  43. {
  44. if (NULL == p)
  45. return;
  46. POPENITEM_LIST_ITEM pli = (POPENITEM_LIST_ITEM) p;
  47. // do all necessary freeing
  48. if (pli->szItemName != NULL)
  49. SSFree(pli->szItemName);
  50. if (pli->szMasterKey != NULL)
  51. SSFree(pli->szMasterKey);
  52. RtlSecureZeroMemory(pli, sizeof(OPENITEM_LIST_ITEM)); // make sure contents invalid
  53. SSFree(pli);
  54. }
  55. //////////////////////////
  56. // UACache list
  57. CUAList::CUAList()
  58. {
  59. m_pfnIsMatch = UACacheIsMatch;
  60. m_pfnFreeElt = UACacheFreeElt;
  61. }
  62. void CreateUACacheListItem(UACACHE_LIST_ITEM* pli,
  63. LPCWSTR szUserName,
  64. LPCWSTR szMKName,
  65. LUID *pluidAuthID)
  66. {
  67. pli->pNext = NULL;
  68. pli->szUserName = (LPWSTR)szUserName;
  69. pli->szMKName = (LPWSTR)szMKName;
  70. CopyMemory( &(pli->luidAuthID), pluidAuthID, sizeof(LUID) );
  71. }
  72. BOOL UACacheIsMatch(
  73. ELT* pCandidate,
  74. ELT* pTemplate)
  75. {
  76. PUACACHE_LIST_ITEM pliCandidate = (PUACACHE_LIST_ITEM) pCandidate;
  77. PUACACHE_LIST_ITEM pliTemplate = (PUACACHE_LIST_ITEM) pTemplate;
  78. if (
  79. (0 == wcscmp(pliCandidate->szUserName, pliTemplate->szUserName)) &&
  80. (0 == wcscmp(pliCandidate->szMKName, pliTemplate->szMKName))
  81. ) {
  82. //
  83. // sfield:
  84. // on WinNT, expand cache matching based on authentication ID.
  85. //
  86. if(FIsWinNT()) {
  87. if(memcmp(&(pliCandidate->luidAuthID), &(pliTemplate->luidAuthID), sizeof(LUID)) != 0)
  88. return FALSE;
  89. }
  90. return TRUE;
  91. }
  92. return FALSE;
  93. }
  94. void UACacheFreeElt(
  95. ELT* p)
  96. {
  97. if (NULL == p)
  98. return;
  99. PUACACHE_LIST_ITEM pli = (PUACACHE_LIST_ITEM) p;
  100. // do all necessary freeing
  101. if (pli->szUserName != NULL)
  102. SSFree(pli->szUserName);
  103. if (pli->szMKName != NULL)
  104. SSFree(pli->szMKName);
  105. RtlSecureZeroMemory(pli, sizeof(UACACHE_LIST_ITEM)); // make sure contents invalid
  106. SSFree(pli);
  107. }
  108. ////////////////////////
  109. // Cryptographic Provider handle list
  110. CCryptProvList::CCryptProvList()
  111. {
  112. m_pfnIsMatch = CryptProvIsMatch;
  113. m_pfnFreeElt = CryptProvFreeElt;
  114. }
  115. void CreateCryptProvListItem(CRYPTPROV_LIST_ITEM* pli,
  116. DWORD dwAlgId1,
  117. DWORD dwKeySize1,
  118. DWORD dwAlgId2,
  119. DWORD dwKeySize2,
  120. HCRYPTPROV hProvider)
  121. {
  122. pli->pNext = NULL;
  123. pli->dwAlgId1 = dwAlgId1;
  124. pli->dwKeySize1 = dwKeySize1;
  125. pli->dwAlgId2 = dwAlgId2;
  126. pli->dwKeySize2 = dwKeySize2;
  127. pli->hProv = hProvider;
  128. }
  129. BOOL CryptProvIsMatch(
  130. ELT* pCandidate,
  131. ELT* pTemplate)
  132. {
  133. PCRYPTPROV_LIST_ITEM pliCandidate = (PCRYPTPROV_LIST_ITEM) pCandidate;
  134. PCRYPTPROV_LIST_ITEM pliTemplate = (PCRYPTPROV_LIST_ITEM) pTemplate;
  135. // if both algids match
  136. if ((pliCandidate->dwAlgId1 == pliTemplate->dwAlgId1) &&
  137. (pliCandidate->dwAlgId2 == pliTemplate->dwAlgId2))
  138. {
  139. // if both sizes match
  140. if ((pliCandidate->dwKeySize1 == -1) ||
  141. (pliTemplate->dwKeySize1 == -1) ||
  142. (pliCandidate->dwKeySize1 == pliTemplate->dwKeySize1))
  143. {
  144. if ((pliCandidate->dwKeySize2 == -1) ||
  145. (pliTemplate->dwKeySize2 == -1) ||
  146. (pliCandidate->dwKeySize2 == pliTemplate->dwKeySize2))
  147. return TRUE;
  148. }
  149. }
  150. return FALSE;
  151. }
  152. void CryptProvFreeElt(
  153. ELT* p)
  154. {
  155. if (NULL == p)
  156. return;
  157. PCRYPTPROV_LIST_ITEM pli = (PCRYPTPROV_LIST_ITEM) p;
  158. // do all necessary freeing
  159. if (pli->hProv != 0)
  160. CryptReleaseContext((HCRYPTPROV)pli->hProv, 0);
  161. RtlSecureZeroMemory(pli, sizeof(CRYPTPROV_LIST_ITEM)); // make sure contents invalid
  162. SSFree(pli);
  163. }