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.

227 lines
5.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: dumpcat.cpp
  8. //
  9. // Contents: Microsoft Internet Security Catalog Utilities
  10. //
  11. // Functions: wmain
  12. //
  13. // History: 21-Nov-1997 pberkman created
  14. //
  15. //--------------------------------------------------------------------------
  16. #include "global.hxx"
  17. void _DisplayStore(CRYPTCATSTORE *pStore);
  18. void _DisplayMember(CRYPTCATMEMBER *pMember);
  19. void _DisplayAttribute(CRYPTCATATTRIBUTE *pAttr, BOOL fCatalogLevel);
  20. BOOL fVerbose = FALSE;
  21. BOOL fTesting = FALSE;
  22. DWORD dwExpectedError = 0;
  23. DWORD dwTotal = 0;
  24. WCHAR *pwszFile = NULL;
  25. int iRet = 0;
  26. extern "C" int __cdecl wmain(int argc, WCHAR **wargv)
  27. {
  28. cWArgv_ *pArgs;
  29. BOOL fFailed;
  30. HANDLE hCatStore;
  31. COleDateTime tStart;
  32. COleDateTime tEnd;
  33. COleDateTimeSpan tsTotal;
  34. hCatStore = NULL;
  35. if (!(pArgs = new cWArgv_((HINSTANCE)GetModuleHandle(NULL), &fFailed)))
  36. {
  37. goto MemoryError;
  38. }
  39. if (fFailed)
  40. {
  41. goto MemoryError;
  42. }
  43. pArgs->AddUsageText(IDS_USAGETEXT_USAGE, IDS_USAGETEXT_OPTIONS,
  44. IDS_USAGETEXT_CMDFILE, IDS_USAGETEXT_ADD,
  45. IDS_USAGETEXT_OPTPARAM);
  46. pArgs->Add2List(IDS_PARAM_HELP, IDS_PARAMTEXT_HELP, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  47. pArgs->Add2List(IDS_PARAM_VERBOSE, IDS_PARAMTEXT_VERBOSE, WARGV_VALUETYPE_BOOL, (void *)FALSE);
  48. pArgs->Add2List(IDS_PARAM_EXPERROR, IDS_PARAMTEXT_EXPERROR, WARGV_VALUETYPE_DWORDH, NULL, TRUE);
  49. if (!(pArgs->Fill(argc, wargv)) ||
  50. (pArgs->GetValue(IDS_PARAM_HELP)))
  51. {
  52. wprintf(L"%s", pArgs->GetUsageString());
  53. goto NeededHelp;
  54. }
  55. fVerbose = (BOOL)((DWORD_PTR)pArgs->GetValue(IDS_PARAM_VERBOSE));
  56. if (pArgs->IsSet(IDS_PARAM_EXPERROR))
  57. {
  58. dwExpectedError = (DWORD)((DWORD_PTR)pArgs->GetValue(IDS_PARAM_EXPERROR));
  59. fTesting = TRUE;
  60. }
  61. if (!(pwszFile = pArgs->GetFileName()))
  62. {
  63. wprintf(L"%s", pArgs->GetUsageString());
  64. goto ParamError;
  65. }
  66. SetLastError(0);
  67. //
  68. // start our timer
  69. //
  70. tStart = COleDateTime::GetCurrentTime();
  71. if ((hCatStore = CryptCATOpen(pwszFile, 0, NULL, 0, 0)) == INVALID_HANDLE_VALUE)
  72. {
  73. goto CatOpenError;
  74. }
  75. CRYPTCATSTORE *pStore;
  76. CRYPTCATMEMBER *pMember;
  77. CRYPTCATATTRIBUTE *pAttr;
  78. printf("\n");
  79. wprintf(L"\nCatalog File: %s", pwszFile);
  80. if (pStore = CryptCATStoreFromHandle(hCatStore))
  81. {
  82. if (fVerbose)
  83. {
  84. _DisplayStore(pStore);
  85. }
  86. }
  87. pAttr = NULL;
  88. while (pAttr = CryptCATEnumerateCatAttr(hCatStore, pAttr))
  89. {
  90. if (fVerbose)
  91. {
  92. _DisplayAttribute(pAttr, TRUE);
  93. }
  94. }
  95. pMember = NULL;
  96. while (pMember = CryptCATEnumerateMember(hCatStore, pMember))
  97. {
  98. dwTotal++;
  99. if (fVerbose)
  100. {
  101. _DisplayMember(pMember);
  102. }
  103. pAttr = NULL;
  104. while (pAttr = CryptCATEnumerateAttr(hCatStore, pMember, pAttr))
  105. {
  106. if (fVerbose)
  107. {
  108. _DisplayAttribute(pAttr, FALSE);
  109. }
  110. }
  111. }
  112. //
  113. // end timer
  114. //
  115. tEnd = COleDateTime::GetCurrentTime();
  116. tsTotal = tEnd - tStart;
  117. printf("\n");
  118. printf("\nTiming:");
  119. printf("\n Processing time: %s", (LPCSTR)tsTotal.Format("%D:%H:%M:%S"));
  120. printf("\n Total members: %lu", dwTotal);
  121. printf("\n Average per member: %f", (double)tsTotal.GetTotalSeconds() / (double)dwTotal);
  122. printf("\n");
  123. iRet = 0;
  124. CommonReturn:
  125. DELETE_OBJECT(pArgs);
  126. if (hCatStore)
  127. {
  128. CryptCATClose(hCatStore);
  129. }
  130. return(iRet);
  131. ErrorReturn:
  132. iRet = 1;
  133. goto CommonReturn;
  134. TRACE_ERROR_EX(DBG_SS_APP, MemoryError);
  135. TRACE_ERROR_EX(DBG_SS_APP, ParamError);
  136. TRACE_ERROR_EX(DBG_SS_APP, NeededHelp);
  137. TRACE_ERROR_EX(DBG_SS_APP, CatOpenError);
  138. }
  139. void _DisplayStore(CRYPTCATSTORE *pStore)
  140. {
  141. wprintf(L"\n Catalog Store Info:");
  142. wprintf(L"\n dwPublicVersion: 0x%08.8lX", pStore->dwPublicVersion);
  143. wprintf(L"\n dwEncodingType: 0x%08.8lX", pStore->dwEncodingType);
  144. }
  145. void _DisplayMember(CRYPTCATMEMBER *pMember)
  146. {
  147. wprintf(L"\n member: ");
  148. if ((pMember->pIndirectData) &&
  149. (pMember->pIndirectData->Digest.pbData))
  150. {
  151. DWORD i;
  152. for (i = 0; i < pMember->pIndirectData->Digest.cbData; i++)
  153. {
  154. printf("%02.2X", pMember->pIndirectData->Digest.pbData[i]);
  155. }
  156. }
  157. else
  158. {
  159. BYTE bEmpty[21];
  160. memset(&bEmpty[0], ' ', 20);
  161. bEmpty[20] = 0x00;
  162. printf("%s", &bEmpty[0]);
  163. }
  164. wprintf(L" %s", pMember->pwszReferenceTag);
  165. }
  166. void _DisplayAttribute(CRYPTCATATTRIBUTE *pAttr, BOOL fCatalogLevel)
  167. {
  168. if (fCatalogLevel)
  169. {
  170. wprintf(L"\n attribute: ");
  171. }
  172. else
  173. {
  174. wprintf(L"\n attribute: ");
  175. }
  176. wprintf(L"%s ", pAttr->pwszReferenceTag);
  177. DWORD i;
  178. for (i = 0; i < pAttr->cbValue; i++)
  179. {
  180. printf("%c", pAttr->pbValue[i]);
  181. }
  182. }