|
|
|
@ -55,6 +55,7 @@ typedef struct _SCARD_IO_REQUEST
|
|
|
|
|
#define SCARD_ESTABLISH_CONTEXT 0x01
|
|
|
|
|
#define SCARD_RELEASE_CONTEXT 0x02
|
|
|
|
|
#define SCARD_LIST_READERS 0x03
|
|
|
|
|
#define SCARD_CONNECT 0x04
|
|
|
|
|
#define SCARD_GET_STATUS_CHANGE 0x0C
|
|
|
|
|
|
|
|
|
|
#define SCARD_S_SUCCESS 0x00000000
|
|
|
|
@ -79,6 +80,9 @@ static int g_sck = -1; /* unix domain socket */
|
|
|
|
|
|
|
|
|
|
static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
|
|
/* for pcsc_stringify_error */
|
|
|
|
|
static char g_error_str[512];
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static int
|
|
|
|
|
get_display_num_from_display(const char *display_text)
|
|
|
|
@ -152,6 +156,11 @@ connect_to_chansrv(void)
|
|
|
|
|
struct sockaddr_un saddr;
|
|
|
|
|
struct sockaddr *psaddr;
|
|
|
|
|
|
|
|
|
|
if (g_sck != -1)
|
|
|
|
|
{
|
|
|
|
|
/* already connected */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
xrdp_session = getenv("XRDP_SESSION");
|
|
|
|
|
if (xrdp_session == NULL)
|
|
|
|
|
{
|
|
|
|
@ -180,8 +189,6 @@ connect_to_chansrv(void)
|
|
|
|
|
LLOGLN(0, ("connect_to_chansrv: error, display not > 9 %d", dis));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (g_sck == -1)
|
|
|
|
|
{
|
|
|
|
|
g_sck = socket(PF_LOCAL, SOCK_STREAM, 0);
|
|
|
|
|
if (g_sck == -1)
|
|
|
|
|
{
|
|
|
|
@ -208,7 +215,6 @@ connect_to_chansrv(void)
|
|
|
|
|
LLOGLN(0, ("connect_to_chansrv: error, open %s", saddr.sun_path));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -369,6 +375,12 @@ SCardConnect(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,
|
|
|
|
|
DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,
|
|
|
|
|
LPDWORD pdwActiveProtocol)
|
|
|
|
|
{
|
|
|
|
|
char msg[256];
|
|
|
|
|
int code;
|
|
|
|
|
int bytes;
|
|
|
|
|
int status;
|
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
|
|
LLOGLN(0, ("SCardConnect:"));
|
|
|
|
|
if (g_sck == -1)
|
|
|
|
|
{
|
|
|
|
@ -376,8 +388,47 @@ SCardConnect(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,
|
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
pthread_mutex_lock(&g_mutex);
|
|
|
|
|
offset = 0;
|
|
|
|
|
SET_UINT32(msg, offset, hContext);
|
|
|
|
|
offset += 4;
|
|
|
|
|
bytes = strlen(szReader);
|
|
|
|
|
if (bytes > 99)
|
|
|
|
|
{
|
|
|
|
|
LLOGLN(0, ("SCardConnect: error, name too long"));
|
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
memcpy(msg + offset, szReader, bytes);
|
|
|
|
|
memset(msg + bytes, 0, 100 - bytes);
|
|
|
|
|
offset += 100;
|
|
|
|
|
SET_UINT32(msg, offset, dwShareMode);
|
|
|
|
|
offset += 4;
|
|
|
|
|
SET_UINT32(msg, offset, dwPreferredProtocols);
|
|
|
|
|
offset += 4;
|
|
|
|
|
if (send_message(SCARD_CONNECT, msg, offset) != 0)
|
|
|
|
|
{
|
|
|
|
|
LLOGLN(0, ("SCardConnect: error, send_message"));
|
|
|
|
|
pthread_mutex_unlock(&g_mutex);
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
bytes = 256;
|
|
|
|
|
if (get_message(&code, msg, &bytes) != 0)
|
|
|
|
|
{
|
|
|
|
|
LLOGLN(0, ("SCardConnect: error, get_message"));
|
|
|
|
|
pthread_mutex_unlock(&g_mutex);
|
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (code != SCARD_RELEASE_CONTEXT)
|
|
|
|
|
{
|
|
|
|
|
LLOGLN(0, ("SCardConnect: error, bad code"));
|
|
|
|
|
pthread_mutex_unlock(&g_mutex);
|
|
|
|
|
return SCARD_F_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
pthread_mutex_unlock(&g_mutex);
|
|
|
|
|
*phCard = GET_UINT32(msg, 0);
|
|
|
|
|
*pdwActiveProtocol = GET_UINT32(msg, 4);
|
|
|
|
|
status = GET_UINT32(msg, 8);
|
|
|
|
|
LLOGLN(10, ("SCardReleaseContext: got status 0x%8.8x", status));
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
@ -746,8 +797,6 @@ SCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr,
|
|
|
|
|
return SCARD_S_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char g_error_str[512];
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
char *
|
|
|
|
|
pcsc_stringify_error(const long code)
|
|
|
|
|