libwinpr-smartcard: fix compilation on Windows

This commit is contained in:
Marc-André Moreau 2014-04-04 16:45:11 -04:00
parent 91898fb293
commit f9ada64587
7 changed files with 86 additions and 65 deletions

View File

@ -477,7 +477,7 @@ static UINT32 smartcard_output_string(IRP* irp, char* src, BOOL wide)
if (wide)
{
int i;
UINT32 i;
for (i = 0; i < len; i++ )
{
@ -526,7 +526,7 @@ static UINT32 smartcard_output_return(IRP* irp, UINT32 status)
static void smartcard_output_buffer_limit(IRP* irp, char* buffer, unsigned int length, unsigned int highLimit)
{
int header = (length < 0) ? (0) : ((length > highLimit) ? (highLimit) : (length));
UINT32 header = (length < 0) ? (0) : ((length > highLimit) ? (highLimit) : (length));
Stream_Write_UINT32(irp->output, header);
@ -574,7 +574,8 @@ static UINT32 smartcard_input_string(IRP* irp, char** dest, UINT32 dataLength, B
if (wide)
{
int i;
UINT32 i;
for (i = 0; i < dataLength; i++)
{
if ((buffer[2 * i] < 0) || (buffer[2 * i + 1] != 0))
@ -840,13 +841,13 @@ finish:
static UINT32 handle_GetStatusChange(SMARTCARD_DEVICE* smartcard, IRP* irp, BOOL wide)
{
int i;
UINT32 i;
LONG status;
int redirect = 0;
SCARDCONTEXT hContext;
DWORD dwTimeout = 0;
DWORD readerCount = 0;
SCARD_READERSTATE *readerStates = NULL, *cur;
SCARD_READERSTATEA *readerStates = NULL, *cur;
status = handle_CommonTypeHeader(smartcard, irp);
@ -932,9 +933,10 @@ static UINT32 handle_GetStatusChange(SMARTCARD_DEVICE* smartcard, IRP* irp, BOOL
for (i = 0; i < readerCount; i++)
{
cur = &readerStates[i];
UINT32 dataLength;
cur = &readerStates[i];
if (Stream_GetRemainingLength(irp->input) < 12 )
{
DEBUG_WARN("length violation %d [%d]", 12,
@ -1385,7 +1387,7 @@ static UINT32 handle_State(SMARTCARD_DEVICE* smartcard, IRP* irp)
}
readerLen = SCARD_AUTOALLOCATE;
status = SCardStatus(hCard, (LPSTR) &readerName, &readerLen, &state, &protocol, pbAtr, &atrLen);
status = SCardStatusA(hCard, (LPSTR) &readerName, &readerLen, &state, &protocol, pbAtr, &atrLen);
if (status != SCARD_S_SUCCESS)
{
@ -2023,13 +2025,13 @@ static UINT32 handle_LocateCardsByATR(SMARTCARD_DEVICE* smartcard, IRP* irp, BOO
{
int redirect = 0;
LONG status;
int i, j, k;
UINT32 i, j, k;
SCARDCONTEXT hContext;
UINT32 atrMaskCount = 0;
UINT32 readerCount = 0;
SCARD_READERSTATE* cur = NULL;
SCARD_READERSTATE* rsCur = NULL;
SCARD_READERSTATE* readerStates = NULL;
SCARD_READERSTATEA* cur = NULL;
SCARD_READERSTATEA* rsCur = NULL;
SCARD_READERSTATEA* readerStates = NULL;
SCARD_ATRMASK* curAtr = NULL;
SCARD_ATRMASK* pAtrMasks = NULL;
@ -2108,9 +2110,10 @@ static UINT32 handle_LocateCardsByATR(SMARTCARD_DEVICE* smartcard, IRP* irp, BOO
for (i = 0; i < readerCount; i++)
{
cur = &readerStates[i];
UINT32 dataLength;
cur = &readerStates[i];
Stream_Seek(irp->input, 8);
Stream_Read_UINT32(irp->input, dataLength);
smartcard_input_repos(irp, smartcard_input_string(irp, (char **) &cur->szReader, dataLength, wide));
@ -2120,6 +2123,7 @@ static UINT32 handle_LocateCardsByATR(SMARTCARD_DEVICE* smartcard, IRP* irp, BOO
DEBUG_WARN("cur->szReader=%p", cur->szReader);
continue;
}
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0)
cur->dwCurrentState |= SCARD_STATE_IGNORE;
}
@ -2357,7 +2361,7 @@ void smartcard_device_control(SMARTCARD_DEVICE* smartcard, IRP* irp)
/* look for NTSTATUS errors */
if ((result & 0xC0000000) == 0xC0000000)
return scard_error(smartcard, irp, result);
scard_error(smartcard, irp, result);
/* per Ludovic Rousseau, map different usage of this particular
* error code between pcsc-lite & windows */

View File

@ -206,34 +206,36 @@ enum RDPDR_PRINTER_ANNOUNCE_FLAG
#endif
/* [MS-FSCC] FSCTL Structures */
enum FSCTL_STRUCTURE
{
FSCTL_CREATE_OR_GET_OBJECT_ID = 0x900c0,
FSCTL_GET_REPARSE_POINT = 0x900a8,
FSCTL_GET_RETRIEVAL_POINTERS = 0x90073,
FSCTL_IS_PATHNAME_VALID = 0x9002c,
FSCTL_LMR_SET_LINK_TRACKING_INFORMATION = 0x1400ec,
FSCTL_PIPE_PEEK = 0x11400c,
FSCTL_PIPE_TRANSCEIVE = 0x11c017,
FSCTL_PIPE_WAIT = 0x110018,
FSCTL_QUERY_FAT_BPB = 0x90058,
FSCTL_QUERY_ALLOCATED_RANGES = 0x940cf,
FSCTL_QUERY_ON_DISK_VOLUME_INFO = 0x9013c,
FSCTL_QUERY_SPARING_INFO = 0x90138,
FSCTL_READ_FILE_USN_DATA = 0x900eb,
FSCTL_RECALL_FILE = 0x90117,
FSCTL_SET_COMPRESSION = 0x9c040,
FSCTL_SET_DEFECT_MANAGEMENT = 0x98134,
FSCTL_SET_ENCRYPTION = 0x900D7,
FSCTL_SET_OBJECT_ID = 0x90098,
FSCTL_SET_OBJECT_ID_EXTENDED = 0x900bc,
FSCTL_SET_REPARSE_POINT = 0x900a4,
FSCTL_SET_SPARSE = 0x900c4,
FSCTL_SET_ZERO_DATA = 0x980c8,
FSCTL_SET_ZERO_ON_DEALLOCATION = 0x90194,
FSCTL_SIS_COPYFILE = 0x90100,
FSCTL_WRITE_USN_CLOSE_RECORD = 0x900ef
};
#define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION 0x1400ec
#define FSCTL_PIPE_PEEK 0x11400c
#define FSCTL_PIPE_TRANSCEIVE 0x11c017
#define FSCTL_PIPE_WAIT 0x110018
#define FSCTL_QUERY_ON_DISK_VOLUME_INFO 0x9013c
#define FSCTL_QUERY_SPARING_INFO 0x90138
#ifndef _WIN32
#define FSCTL_CREATE_OR_GET_OBJECT_ID 0x900c0
#define FSCTL_GET_REPARSE_POINT 0x900a8
#define FSCTL_GET_RETRIEVAL_POINTERS 0x90073
#define FSCTL_IS_PATHNAME_VALID 0x9002c
#define FSCTL_READ_FILE_USN_DATA 0x900eb
#define FSCTL_RECALL_FILE 0x90117
#define FSCTL_QUERY_FAT_BPB 0x90058
#define FSCTL_QUERY_ALLOCATED_RANGES 0x940cf
#define FSCTL_SET_COMPRESSION 0x9c040
#define FSCTL_SET_ENCRYPTION 0x900D7
#define FSCTL_SET_OBJECT_ID 0x90098
#define FSCTL_SET_OBJECT_ID_EXTENDED 0x900bc
#define FSCTL_SET_REPARSE_POINT 0x900a4
#define FSCTL_SET_SPARSE 0x900c4
#define FSCTL_SET_ZERO_DATA 0x980c8
#define FSCTL_SIS_COPYFILE 0x90100
#define FSCTL_WRITE_USN_CLOSE_RECORD 0x900ef
#endif
#define FSCTL_SET_DEFECT_MANAGEMENT 0x98134
#define FSCTL_SET_ZERO_ON_DEALLOCATION 0x90194
/* [MS-FSCC] FileFsAttributeInformation.FileSystemAttributes */

View File

@ -23,7 +23,11 @@
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#ifndef _WIN32
#ifdef _WIN32
#include <winioctl.h>
#else
#include <winpr/nt.h>

View File

@ -31,8 +31,8 @@
#endif
#ifndef SCARD_S_SUCCESS
#define SCARD_S_SUCCESS NO_ERROR
#endif
#define SCARD_F_INTERNAL_ERROR ((DWORD)0x80100001L)
#define SCARD_E_CANCELLED ((DWORD)0x80100002L)
@ -102,6 +102,8 @@
#define SCARD_W_CACHE_ITEM_STALE ((DWORD)0x80100071L)
#define SCARD_W_CACHE_ITEM_TOO_BIG ((DWORD)0x80100072L)
#endif
#define SCARD_ATR_LENGTH 33
#define SCARD_PROTOCOL_UNDEFINED 0x00000000
@ -280,7 +282,7 @@ typedef SCARD_T1_REQUEST *PSCARD_T1_REQUEST, *LPSCARD_T1_REQUEST;
#define SCARD_READER_TYPE_VENDOR 0xF0
#ifndef WINSCARDAPI
#define WINSCARDAPI
#define WINSCARDAPI WINPR_API
#endif
typedef ULONG_PTR SCARDCONTEXT;

View File

@ -64,7 +64,7 @@ typedef int BOOL;
typedef BOOL *PBOOL, *LPBOOL;
typedef unsigned char BYTE, *PBYTE, *LPBYTE, *LPCBYTE;
typedef unsigned char BYTE, *PBYTE, *LPBYTE;
typedef BYTE BOOLEAN, *PBOOLEAN;
typedef unsigned short WCHAR, *PWCHAR;
typedef WCHAR* BSTR;
@ -146,7 +146,6 @@ typedef unsigned short USHORT;
#define VOID void
typedef void *PVOID, *LPVOID;
typedef void *PVOID64, *LPVOID64;
typedef const void *LPCVOID;
typedef unsigned short WORD, *PWORD, *LPWORD;
#if __x86_64__
@ -316,6 +315,16 @@ typedef LONG NTSTATUS;
typedef NTSTATUS *PNTSTATUS;
#endif
#ifndef _LPCBYTE_DEFINED
#define _LPCBYTE_DEFINED
typedef const BYTE *LPCBYTE;
#endif
#ifndef _LPCVOID_DEFINED
#define _LPCVOID_DEFINED
typedef const VOID *LPCVOID;
#endif
#ifndef _WIN32
typedef struct tagDEC

View File

@ -720,24 +720,24 @@ int PCSC_InitializeSCardApi(void)
if (!g_PCSCModule)
return -1;
g_PCSC.pfnSCardEstablishContext = GetProcAddress(g_PCSCModule, "SCardEstablishContext");
g_PCSC.pfnSCardReleaseContext = GetProcAddress(g_PCSCModule, "SCardReleaseContext");
g_PCSC.pfnSCardIsValidContext = GetProcAddress(g_PCSCModule, "SCardIsValidContext");
g_PCSC.pfnSCardConnect = GetProcAddress(g_PCSCModule, "SCardConnect");
g_PCSC.pfnSCardReconnect = GetProcAddress(g_PCSCModule, "SCardReconnect");
g_PCSC.pfnSCardDisconnect = GetProcAddress(g_PCSCModule, "SCardDisconnect");
g_PCSC.pfnSCardBeginTransaction = GetProcAddress(g_PCSCModule, "SCardBeginTransaction");
g_PCSC.pfnSCardEndTransaction = GetProcAddress(g_PCSCModule, "SCardEndTransaction");
g_PCSC.pfnSCardStatus = GetProcAddress(g_PCSCModule, "SCardStatus");
g_PCSC.pfnSCardGetStatusChange = GetProcAddress(g_PCSCModule, "SCardGetStatusChange");
g_PCSC.pfnSCardControl = GetProcAddress(g_PCSCModule, "SCardControl");
g_PCSC.pfnSCardTransmit = GetProcAddress(g_PCSCModule, "SCardTransmit");
g_PCSC.pfnSCardListReaderGroups = GetProcAddress(g_PCSCModule, "SCardListReaderGroups");
g_PCSC.pfnSCardListReaders = GetProcAddress(g_PCSCModule, "SCardListReaders");
g_PCSC.pfnSCardFreeMemory = GetProcAddress(g_PCSCModule, "SCardFreeMemory");
g_PCSC.pfnSCardCancel = GetProcAddress(g_PCSCModule, "SCardCancel");
g_PCSC.pfnSCardGetAttrib = GetProcAddress(g_PCSCModule, "SCardGetAttrib");
g_PCSC.pfnSCardSetAttrib = GetProcAddress(g_PCSCModule, "SCardSetAttrib");
g_PCSC.pfnSCardEstablishContext = (void*) GetProcAddress(g_PCSCModule, "SCardEstablishContext");
g_PCSC.pfnSCardReleaseContext = (void*) GetProcAddress(g_PCSCModule, "SCardReleaseContext");
g_PCSC.pfnSCardIsValidContext = (void*) GetProcAddress(g_PCSCModule, "SCardIsValidContext");
g_PCSC.pfnSCardConnect = (void*) GetProcAddress(g_PCSCModule, "SCardConnect");
g_PCSC.pfnSCardReconnect = (void*) GetProcAddress(g_PCSCModule, "SCardReconnect");
g_PCSC.pfnSCardDisconnect = (void*) GetProcAddress(g_PCSCModule, "SCardDisconnect");
g_PCSC.pfnSCardBeginTransaction = (void*) GetProcAddress(g_PCSCModule, "SCardBeginTransaction");
g_PCSC.pfnSCardEndTransaction = (void*) GetProcAddress(g_PCSCModule, "SCardEndTransaction");
g_PCSC.pfnSCardStatus = (void*) GetProcAddress(g_PCSCModule, "SCardStatus");
g_PCSC.pfnSCardGetStatusChange = (void*) GetProcAddress(g_PCSCModule, "SCardGetStatusChange");
g_PCSC.pfnSCardControl = (void*) GetProcAddress(g_PCSCModule, "SCardControl");
g_PCSC.pfnSCardTransmit = (void*) GetProcAddress(g_PCSCModule, "SCardTransmit");
g_PCSC.pfnSCardListReaderGroups = (void*) GetProcAddress(g_PCSCModule, "SCardListReaderGroups");
g_PCSC.pfnSCardListReaders = (void*) GetProcAddress(g_PCSCModule, "SCardListReaders");
g_PCSC.pfnSCardFreeMemory = (void*) GetProcAddress(g_PCSCModule, "SCardFreeMemory");
g_PCSC.pfnSCardCancel = (void*) GetProcAddress(g_PCSCModule, "SCardCancel");
g_PCSC.pfnSCardGetAttrib = (void*) GetProcAddress(g_PCSCModule, "SCardGetAttrib");
g_PCSC.pfnSCardSetAttrib = (void*) GetProcAddress(g_PCSCModule, "SCardSetAttrib");
return 1;
}

View File

@ -40,7 +40,7 @@ struct _PCSCFunctionTable
LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState,
LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen);
LONG (* pfnSCardGetStatusChange)(SCARDCONTEXT hContext,
DWORD dwTimeout, LPSCARD_READERSTATE rgReaderStates, DWORD cReaders);
DWORD dwTimeout, LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders);
LONG (* pfnSCardControl)(SCARDHANDLE hCard,
DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength,
LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned);