mirror of
https://github.com/tenrok/Rfid-Credential-Provider.git
synced 2026-06-17 19:30:32 +03:00
Z-2 USB Reader
This commit is contained in:
@@ -15,29 +15,22 @@
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
#define cchOUTPUT 1024
|
||||
#define szOUTPUT_TAG "Sample"
|
||||
#define cchOUTPUT 1024
|
||||
#define szOUTPUT_TAG "Sample"
|
||||
|
||||
//
|
||||
// Copies the field descriptor pointed to by rcpfd into a buffer allocated
|
||||
// using CoTaskMemAlloc. Returns that buffer in ppcpfd.
|
||||
//
|
||||
HRESULT FieldDescriptorCoAllocCopy(
|
||||
const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR& rcpfd,
|
||||
CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd
|
||||
)
|
||||
HRESULT FieldDescriptorCoAllocCopy(const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR& rcpfd, CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd)
|
||||
{
|
||||
HRESULT hr;
|
||||
DWORD cbStruct = sizeof(CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR);
|
||||
|
||||
CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* pcpfd =
|
||||
(CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR*)CoTaskMemAlloc(cbStruct);
|
||||
|
||||
CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* pcpfd = (CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR*)CoTaskMemAlloc(cbStruct);
|
||||
if (pcpfd)
|
||||
{
|
||||
pcpfd->dwFieldID = rcpfd.dwFieldID;
|
||||
pcpfd->cpft = rcpfd.cpft;
|
||||
|
||||
if (rcpfd.pszLabel)
|
||||
{
|
||||
hr = SHStrDupW(rcpfd.pszLabel, &pcpfd->pszLabel);
|
||||
@@ -58,11 +51,9 @@ HRESULT FieldDescriptorCoAllocCopy(
|
||||
}
|
||||
else
|
||||
{
|
||||
CoTaskMemFree(pcpfd);
|
||||
CoTaskMemFree(pcpfd);
|
||||
*ppcpfd = NULL;
|
||||
}
|
||||
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -71,17 +62,12 @@ HRESULT FieldDescriptorCoAllocCopy(
|
||||
// allocating pcpfd. This function uses CoTaskMemAlloc to allocate memory for
|
||||
// pcpfd->pszLabel.
|
||||
//
|
||||
HRESULT FieldDescriptorCopy(
|
||||
const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR& rcpfd,
|
||||
CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* pcpfd
|
||||
)
|
||||
HRESULT FieldDescriptorCopy(const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR& rcpfd, CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* pcpfd)
|
||||
{
|
||||
HRESULT hr;
|
||||
CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR cpfd;
|
||||
|
||||
cpfd.dwFieldID = rcpfd.dwFieldID;
|
||||
cpfd.cpft = rcpfd.cpft;
|
||||
|
||||
if (rcpfd.pszLabel)
|
||||
{
|
||||
hr = SHStrDupW(rcpfd.pszLabel, &cpfd.pszLabel);
|
||||
@@ -91,12 +77,10 @@ HRESULT FieldDescriptorCopy(
|
||||
cpfd.pszLabel = NULL;
|
||||
hr = S_OK;
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
*pcpfd = cpfd;
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -107,10 +91,7 @@ HRESULT FieldDescriptorCopy(
|
||||
// Be very, very sure that this is what you want, because it probably isn't outside of the
|
||||
// exact GetSerialization call where the sample uses it.
|
||||
//
|
||||
HRESULT UnicodeStringInitWithString(
|
||||
PWSTR pwz,
|
||||
UNICODE_STRING* pus
|
||||
)
|
||||
HRESULT UnicodeStringInitWithString(PWSTR pwz, UNICODE_STRING* pus)
|
||||
{
|
||||
HRESULT hr;
|
||||
if (pwz)
|
||||
@@ -151,16 +132,11 @@ HRESULT UnicodeStringInitWithString(
|
||||
// You can read more about the UNICODE_STRING type at:
|
||||
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/unicode_string.asp
|
||||
//
|
||||
static void _UnicodeStringPackedUnicodeStringCopy(
|
||||
const UNICODE_STRING& rus,
|
||||
PWSTR pwzBuffer,
|
||||
UNICODE_STRING* pus
|
||||
)
|
||||
static void _UnicodeStringPackedUnicodeStringCopy(const UNICODE_STRING& rus, PWSTR pwzBuffer, UNICODE_STRING* pus)
|
||||
{
|
||||
pus->Length = rus.Length;
|
||||
pus->MaximumLength = rus.Length;
|
||||
pus->Buffer = pwzBuffer;
|
||||
|
||||
CopyMemory(pus->Buffer, rus.Buffer, pus->Length);
|
||||
}
|
||||
|
||||
@@ -182,11 +158,7 @@ static void _UnicodeStringPackedUnicodeStringCopy(
|
||||
// http://msdn.microsoft.com/msdnmag/issues/05/06/SecurityBriefs/#void
|
||||
//
|
||||
|
||||
HRESULT KerbInteractiveLogonPack(
|
||||
const KERB_INTERACTIVE_LOGON& rkil,
|
||||
BYTE** prgb,
|
||||
DWORD* pcb
|
||||
)
|
||||
HRESULT KerbInteractiveLogonPack(const KERB_INTERACTIVE_LOGON& rkil, BYTE** prgb, DWORD* pcb)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
@@ -197,7 +169,7 @@ HRESULT KerbInteractiveLogonPack(
|
||||
rkil.Password.Length;
|
||||
|
||||
KERB_INTERACTIVE_LOGON* pkil = (KERB_INTERACTIVE_LOGON*)CoTaskMemAlloc(cb);
|
||||
|
||||
|
||||
if (pkil)
|
||||
{
|
||||
pkil->MessageType = rkil.MessageType;
|
||||
@@ -232,7 +204,6 @@ HRESULT KerbInteractiveLogonPack(
|
||||
{
|
||||
hr = E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -248,7 +219,7 @@ HRESULT LsaInitString(PSTRING pszDestinationString, PCSTR pszSourceString)
|
||||
{
|
||||
pszDestinationString->Buffer = (PCHAR)pszSourceString;
|
||||
pszDestinationString->Length = usLength;
|
||||
pszDestinationString->MaximumLength = pszDestinationString->Length+1;
|
||||
pszDestinationString->MaximumLength = pszDestinationString->Length + 1;
|
||||
hr = S_OK;
|
||||
}
|
||||
return hr;
|
||||
@@ -259,15 +230,13 @@ HRESULT LsaInitString(PSTRING pszDestinationString, PCSTR pszSourceString)
|
||||
// For more information on auth packages see this msdn page:
|
||||
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/msv1_0_lm20_logon.asp
|
||||
//
|
||||
HRESULT RetrieveNegotiateAuthPackage(ULONG * pulAuthPackage)
|
||||
HRESULT RetrieveNegotiateAuthPackage(ULONG* pulAuthPackage)
|
||||
{
|
||||
HRESULT hr;
|
||||
HANDLE hLsa;
|
||||
|
||||
NTSTATUS status = LsaConnectUntrusted(&hLsa);
|
||||
if (SUCCEEDED(HRESULT_FROM_NT(status)))
|
||||
{
|
||||
|
||||
ULONG ulAuthPackage;
|
||||
LSA_STRING lsaszKerberosName;
|
||||
LsaInitString(&lsaszKerberosName, NEGOSSP_NAME_A);
|
||||
@@ -286,9 +255,8 @@ HRESULT RetrieveNegotiateAuthPackage(ULONG * pulAuthPackage)
|
||||
}
|
||||
else
|
||||
{
|
||||
hr= HRESULT_FROM_NT(status);
|
||||
hr = HRESULT_FROM_NT(status);
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -296,7 +264,7 @@ std::wstring s2ws(const std::string& s)
|
||||
{
|
||||
int len;
|
||||
int slength = (int)s.length() + 1;
|
||||
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
|
||||
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
|
||||
wchar_t* buf = new wchar_t[len];
|
||||
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
|
||||
std::wstring r(buf);
|
||||
@@ -304,46 +272,44 @@ std::wstring s2ws(const std::string& s)
|
||||
return r;
|
||||
}
|
||||
|
||||
std::string ws2s(const std::wstring& si){
|
||||
std::string ws2s(const std::wstring& si)
|
||||
{
|
||||
std::wstring ws(si);
|
||||
std::string s;
|
||||
s.assign(ws.begin(), ws.end());
|
||||
s.assign(ws.begin(), ws.end());
|
||||
return s;
|
||||
}
|
||||
|
||||
wchar_t* wcs2cs(std::wstring& s){
|
||||
wchar_t* wcs2cs(std::wstring& s)
|
||||
{
|
||||
std::vector<wchar_t> v(s.length() + 1);
|
||||
std::wcscpy(&v[0], s.c_str());
|
||||
wchar_t* w = &v[0];
|
||||
s = w;
|
||||
|
||||
wchar_t* w2 = new wchar_t[wcslen(w) + 1];
|
||||
|
||||
for(int i = 0; i < wcslen(w); i++){
|
||||
for (int i = 0; i < wcslen(w); i++) {
|
||||
w2[i] = w[i];
|
||||
}
|
||||
w2[wcslen(w)] = L'\0';
|
||||
|
||||
return w2;
|
||||
}
|
||||
|
||||
char* s2cs(std::string& s){
|
||||
char* s2cs(std::string& s)
|
||||
{
|
||||
std::vector<char> v(s.length() + 1);
|
||||
std::strcpy(&v[0], s.c_str());
|
||||
char* w = &v[0];
|
||||
s = w;
|
||||
|
||||
char* w2 = new char[strlen(w) + 1];
|
||||
|
||||
for(int i = 0; i < strlen(w); i++){
|
||||
for (int i = 0; i < strlen(w); i++) {
|
||||
w2[i] = w[i];
|
||||
}
|
||||
w2[strlen(w)] = L'\0';
|
||||
|
||||
return w2;
|
||||
}
|
||||
|
||||
unsigned char* s2ucs(std::string& s){
|
||||
unsigned char* s2ucs(std::string& s)
|
||||
{
|
||||
unsigned char* cs = (unsigned char*)s2cs(s);
|
||||
return cs;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user