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.

148 lines
2.6 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <basecsp.h>
  6. #include <pinlib.h>
  7. #include "pindlg.h"
  8. #include "resource.h"
  9. //
  10. // Function: PinStringToBytesA
  11. //
  12. DWORD
  13. WINAPI
  14. PinStringToBytesA(
  15. IN LPSTR szPin,
  16. OUT PDWORD pcbPin,
  17. OUT PBYTE *ppbPin)
  18. {
  19. DWORD dwSts = ERROR_SUCCESS;
  20. DWORD cbPin = 0;
  21. PBYTE pbPin = NULL;
  22. DWORD iChar = 0;
  23. *pcbPin = 0;
  24. *ppbPin = NULL;
  25. cbPin = strlen(szPin);
  26. pbPin = CspAllocH(cbPin);
  27. if (NULL == pbPin)
  28. {
  29. dwSts = ERROR_NOT_ENOUGH_MEMORY;
  30. goto Ret;
  31. }
  32. // Copy the pin bytes directly - no further conversion needed
  33. memcpy(pbPin, szPin, cbPin);
  34. *ppbPin = pbPin;
  35. pbPin = NULL;
  36. *pcbPin = cbPin;
  37. Ret:
  38. if (pbPin)
  39. CspFreeH(pbPin);
  40. return dwSts;
  41. }
  42. //
  43. // Function: PinStringToBytesW
  44. //
  45. DWORD
  46. WINAPI
  47. PinStringToBytesW(
  48. IN LPWSTR wszPin,
  49. OUT PDWORD pcbPin,
  50. OUT PBYTE *ppbPin)
  51. {
  52. DWORD dwSts = ERROR_SUCCESS;
  53. UNICODE_STRING UnicodePin;
  54. ANSI_STRING AnsiPin;
  55. *pcbPin = 0;
  56. *ppbPin = NULL;
  57. memset(&AnsiPin, 0, sizeof(AnsiPin));
  58. RtlInitUnicodeString(&UnicodePin, wszPin);
  59. dwSts = RtlUnicodeStringToAnsiString(
  60. &AnsiPin,
  61. &UnicodePin,
  62. TRUE);
  63. if (STATUS_SUCCESS != dwSts)
  64. {
  65. dwSts = RtlNtStatusToDosError(dwSts);
  66. goto Ret;
  67. }
  68. dwSts = PinStringToBytesA(
  69. AnsiPin.Buffer,
  70. pcbPin,
  71. ppbPin);
  72. Ret:
  73. if (AnsiPin.Buffer)
  74. RtlFreeAnsiString(&AnsiPin);
  75. if (ERROR_SUCCESS != dwSts && NULL != *ppbPin)
  76. {
  77. CspFreeH(*ppbPin);
  78. *ppbPin = NULL;
  79. }
  80. return dwSts;
  81. }
  82. //
  83. // Function: PinShowGetPinUI
  84. //
  85. DWORD
  86. WINAPI
  87. PinShowGetPinUI(
  88. IN OUT PPIN_SHOW_GET_PIN_UI_INFO pInfo)
  89. {
  90. DWORD dwSts = ERROR_SUCCESS;
  91. HWND hWnd = pInfo->hClientWindow;
  92. DWORD cchPin = 0;
  93. INT_PTR dlgResult = 0;
  94. if (0 == hWnd)
  95. {
  96. hWnd = GetDesktopWindow();
  97. if (0 == hWnd || INVALID_HANDLE_VALUE == hWnd)
  98. {
  99. dwSts = GetLastError();
  100. goto Ret;
  101. }
  102. }
  103. //
  104. // Display a dialog to ask the user to enter a pin
  105. //
  106. dlgResult = DialogBoxParamW(
  107. pInfo->hDlgResourceModule,
  108. (LPWSTR) IDD_PINDIALOG,
  109. hWnd,
  110. PinDlgProc,
  111. (LPARAM) pInfo);
  112. if (-1 == dlgResult)
  113. {
  114. dwSts = GetLastError();
  115. goto Ret;
  116. }
  117. dwSts = pInfo->dwError;
  118. Ret:
  119. return dwSts;
  120. }