20 |
#include <cardmod.h> |
#include <cardmod.h> |
21 |
#include "global.h" |
#include "global.h" |
22 |
|
|
23 |
DWORD Authenticate(PWSTR wszPin, PWSTR wszUserId, PDWORD pcAttemptsRemaining) |
DWORD Authenticate(PSTR szPin, PWSTR wszUserId, PDWORD pcAttemptsRemaining) |
24 |
{ |
{ |
25 |
LPSTR szPin = NULL; |
DWORD cbPin = strlen(szPin); |
|
DWORD cbPin = 0; |
|
26 |
DWORD dwReturn; |
DWORD dwReturn; |
27 |
__try |
__try |
28 |
{ |
{ |
31 |
dwReturn = SCARD_E_COMM_DATA_LOST; |
dwReturn = SCARD_E_COMM_DATA_LOST; |
32 |
__leave; |
__leave; |
33 |
} |
} |
|
// |
|
|
// Convert the PIN to ANSI |
|
|
// |
|
|
if (0 == (cbPin = WideCharToMultiByte(CP_ACP,0,wszPin,-1,NULL,0,NULL,NULL))) |
|
|
{ |
|
|
dwReturn = GetLastError(); |
|
|
__leave; |
|
|
} |
|
34 |
|
|
35 |
szPin = (LPSTR) LocalAlloc(0,cbPin); |
dwReturn = pCardData->pfnCardAuthenticatePin( |
36 |
if (szPin == NULL) |
pCardData, |
37 |
|
wszUserId, |
38 |
|
(PBYTE) szPin, |
39 |
|
cbPin - 1, |
40 |
|
pcAttemptsRemaining); |
41 |
|
} |
42 |
|
__finally |
43 |
|
{ |
44 |
|
} |
45 |
|
|
46 |
|
return dwReturn; |
47 |
|
} |
48 |
|
|
49 |
|
DWORD ChangePin(PSTR szPin, PSTR szPin2, PWSTR wszUserId, PDWORD pcAttemptsRemaining) |
50 |
|
{ |
51 |
|
WORD cbPin = strlen(szPin); |
52 |
|
DWORD cbPin2 = strlen(szPin2); |
53 |
|
DWORD dwReturn; |
54 |
|
__try |
55 |
|
{ |
56 |
|
if (!pCardData) |
57 |
{ |
{ |
58 |
dwReturn = GetLastError(); |
dwReturn = SCARD_E_COMM_DATA_LOST; |
59 |
__leave; |
__leave; |
60 |
} |
} |
61 |
|
|
62 |
if (0 == (cbPin = WideCharToMultiByte(CP_ACP,0,wszPin,-1,szPin,cbPin,NULL,NULL))) |
dwReturn = pCardData->pfnCardChangeAuthenticator( |
|
{ |
|
|
dwReturn = GetLastError(); |
|
|
__leave; |
|
|
} |
|
|
|
|
|
// |
|
|
// Call the card module |
|
|
// |
|
|
|
|
|
dwReturn = pCardData->pfnCardAuthenticatePin( |
|
63 |
pCardData, |
pCardData, |
64 |
wszUserId, |
wszUserId, |
65 |
(PBYTE) szPin, |
(PBYTE) szPin, |
66 |
cbPin - 1, |
cbPin, |
67 |
|
(PBYTE) szPin2, |
68 |
|
cbPin2, |
69 |
|
0,CARD_AUTHENTICATE_PIN_PIN, |
70 |
pcAttemptsRemaining); |
pcAttemptsRemaining); |
71 |
} |
} |
72 |
__finally |
__finally |
73 |
{ |
{ |
74 |
if (NULL != szPin) |
} |
75 |
LocalFree(szPin); |
|
76 |
|
return dwReturn; |
77 |
|
} |
78 |
|
DWORD ResetPin(PSTR szPin, PSTR szPin2, BOOL fIsPUK, PDWORD pcAttemptsRemaining) |
79 |
|
{ |
80 |
|
DWORD cbPin = strlen(szPin); |
81 |
|
DWORD cbPin2 = strlen(szPin2); |
82 |
|
DWORD dwReturn; |
83 |
|
__try |
84 |
|
{ |
85 |
|
if (!pCardData) |
86 |
|
{ |
87 |
|
dwReturn = SCARD_E_COMM_DATA_LOST; |
88 |
|
__leave; |
89 |
|
} |
90 |
|
if (fIsPUK) |
91 |
|
{ |
92 |
|
dwReturn = pCardData->pfnCardChangeAuthenticatorEx( |
93 |
|
pCardData, |
94 |
|
PIN_CHANGE_FLAG_UNBLOCK, 5, |
95 |
|
(PBYTE) szPin,cbPin, |
96 |
|
ROLE_USER, (PBYTE)szPin2, cbPin2, 0, |
97 |
|
pcAttemptsRemaining); |
98 |
|
} |
99 |
|
else |
100 |
|
{ |
101 |
|
dwReturn = pCardData->pfnCardChangeAuthenticatorEx( |
102 |
|
pCardData, |
103 |
|
PIN_CHANGE_FLAG_UNBLOCK, ROLE_ADMIN, |
104 |
|
(PBYTE) szPin,cbPin, |
105 |
|
ROLE_USER, (PBYTE)szPin2, cbPin2, 0, |
106 |
|
pcAttemptsRemaining); |
107 |
|
} |
108 |
|
} |
109 |
|
__finally |
110 |
|
{ |
111 |
} |
} |
112 |
|
|
113 |
return dwReturn; |
return dwReturn; |