diff options
author | Jay Sorg <jay.sorg@gmail.com> | 2013-09-19 01:03:20 -0700 |
---|---|---|
committer | Jay Sorg <jay.sorg@gmail.com> | 2013-09-19 01:03:20 -0700 |
commit | 9263b22cb295ae5eefa3bf25e35873b718966325 (patch) | |
tree | 5a513a8efecee9f7a5dbcce8a335eae0e63a06db /sesman/chansrv/pcsc | |
parent | d926a5becd9814f55025a58fb4bb9263c6a24dbb (diff) | |
download | xrdp-proprietary-9263b22cb295ae5eefa3bf25e35873b718966325.tar.gz xrdp-proprietary-9263b22cb295ae5eefa3bf25e35873b718966325.zip |
chansrv: work on smartcard
Diffstat (limited to 'sesman/chansrv/pcsc')
-rw-r--r-- | sesman/chansrv/pcsc/xrdp_pcsc.c | 107 |
1 files changed, 78 insertions, 29 deletions
diff --git a/sesman/chansrv/pcsc/xrdp_pcsc.c b/sesman/chansrv/pcsc/xrdp_pcsc.c index 251fdd82..520c9971 100644 --- a/sesman/chansrv/pcsc/xrdp_pcsc.c +++ b/sesman/chansrv/pcsc/xrdp_pcsc.c @@ -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,34 +189,31 @@ connect_to_chansrv(void) LLOGLN(0, ("connect_to_chansrv: error, display not > 9 %d", dis)); return 1; } + g_sck = socket(PF_LOCAL, SOCK_STREAM, 0); if (g_sck == -1) { - g_sck = socket(PF_LOCAL, SOCK_STREAM, 0); - if (g_sck == -1) - { - LLOGLN(0, ("connect_to_chansrv: error, socket failed")); - return 1; - } - memset(&saddr, 0, sizeof(struct sockaddr_un)); - saddr.sun_family = AF_UNIX; - bytes = sizeof(saddr.sun_path); - snprintf(saddr.sun_path, bytes, "%s/.pcsc%d/pcscd.comm", home_str, dis); - saddr.sun_path[bytes - 1] = 0; - LLOGLN(0, ("connect_to_chansrv: connecting to %s", saddr.sun_path)); - psaddr = (struct sockaddr *) &saddr; - bytes = sizeof(struct sockaddr_un); - error = connect(g_sck, psaddr, bytes); - if (error == 0) - { - } - else - { - perror("connect_to_chansrv"); - close(g_sck); - g_sck = -1; - LLOGLN(0, ("connect_to_chansrv: error, open %s", saddr.sun_path)); - return 1; - } + LLOGLN(0, ("connect_to_chansrv: error, socket failed")); + return 1; + } + memset(&saddr, 0, sizeof(struct sockaddr_un)); + saddr.sun_family = AF_UNIX; + bytes = sizeof(saddr.sun_path); + snprintf(saddr.sun_path, bytes, "%s/.pcsc%d/pcscd.comm", home_str, dis); + saddr.sun_path[bytes - 1] = 0; + LLOGLN(0, ("connect_to_chansrv: connecting to %s", saddr.sun_path)); + psaddr = (struct sockaddr *) &saddr; + bytes = sizeof(struct sockaddr_un); + error = connect(g_sck, psaddr, bytes); + if (error == 0) + { + } + else + { + perror("connect_to_chansrv"); + close(g_sck); + g_sck = -1; + 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_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); - return SCARD_S_SUCCESS; + *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) |