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.

112 lines
2.4 KiB

  1. #include <windows.h>
  2. #include <wincrypt.h>
  3. #include <winscard.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include "pinlib.h"
  8. #define TEST_CASE(X) { if (ERROR_SUCCESS != (dwSts = X)) { printf("%s", #X); goto Ret; } }
  9. #define CAPI_TEST_CASE(X) { if (! X) { dwSts = GetLastError(); printf("%s", #X); goto Ret; } }
  10. //
  11. // Function: CspAllocH
  12. //
  13. LPVOID WINAPI CspAllocH(
  14. IN SIZE_T cBytes)
  15. {
  16. return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cBytes);
  17. }
  18. //
  19. // Function: CspFreeH
  20. //
  21. void WINAPI CspFreeH(
  22. IN LPVOID pMem)
  23. {
  24. HeapFree(GetProcessHeap(), 0, pMem);
  25. }
  26. //
  27. // Function: PrintBytes
  28. //
  29. #define CROW 8
  30. void PrintBytes(LPSTR pszHdr, BYTE *pb, DWORD cbSize)
  31. {
  32. ULONG cb, i;
  33. CHAR rgsz[1024];
  34. printf("\n %s, %d bytes ::\n", pszHdr, cbSize);
  35. while (cbSize > 0)
  36. {
  37. // Start every row with an extra space
  38. printf(" ");
  39. cb = min(CROW, cbSize);
  40. cbSize -= cb;
  41. for (i = 0; i < cb; i++)
  42. printf(" %02x", pb[i]);
  43. for (i = cb; i < CROW; i++)
  44. printf(" ");
  45. printf(" '");
  46. for (i = 0; i < cb; i++)
  47. {
  48. if (pb[i] >= 0x20 && pb[i] <= 0x7f)
  49. printf("%c", pb[i]);
  50. else
  51. printf(".");
  52. }
  53. printf("\n");
  54. pb += cb;
  55. }
  56. }
  57. DWORD WINAPI MyVerifyPin(
  58. IN PPINCACHE_PINS pPins,
  59. IN PVOID pvCallbackCtx)
  60. {
  61. return ERROR_SUCCESS;
  62. }
  63. int _cdecl main(int argc, char * argv[])
  64. {
  65. DWORD dwSts = ERROR_SUCCESS;
  66. PIN_SHOW_GET_PIN_UI_INFO PinUIInfo;
  67. HMODULE hCspMod = 0;
  68. hCspMod = LoadLibrary(L"basecsp.dll");
  69. if (0 == hCspMod || INVALID_HANDLE_VALUE == hCspMod)
  70. {
  71. dwSts = GetLastError();
  72. goto Ret;
  73. }
  74. memset(&PinUIInfo, 0, sizeof(PinUIInfo));
  75. PinUIInfo.wszCardName = L"My Card";
  76. PinUIInfo.wszPrincipal = L"User";
  77. PinUIInfo.pfnVerify = MyVerifyPin;
  78. PinUIInfo.pvCallbackContext = (PVOID) 0xdaad;
  79. PinUIInfo.hDlgResourceModule = hCspMod;
  80. dwSts = PinShowGetPinUI(
  81. &PinUIInfo);
  82. Ret:
  83. if (ERROR_SUCCESS != dwSts)
  84. printf(" failed, 0x%x\n", dwSts);
  85. else
  86. printf("Success.\n");
  87. if (hCspMod)
  88. FreeLibrary(hCspMod);
  89. if (PinUIInfo.pbPin)
  90. CspFreeH(PinUIInfo.pbPin);
  91. return 0;
  92. }