2
2
rdesktop: A Remote Desktop Protocol client.
4
4
Copyright (C) Alexi Volkov <alexi@myrealbox.com> 2006
5
Copyright 2010 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
This program is free software; you can redistribute it and/or modify
7
This program is free software: you can redistribute it and/or modify
7
8
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
the Free Software Foundation, either version 3 of the License, or
9
10
(at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
14
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
969
977
code &= 0x0000FFFF;
970
978
return (code % 2);
974
incStatus(MYPCSC_DWORD code, RD_BOOL mapped)
976
if (mapped || (code & SCARD_STATE_CHANGED))
978
MYPCSC_DWORD count = (code >> 16) & 0x0000FFFF;
980
if (mapped && !(count % 2))
982
return (code & 0x0000FFFF) | (count << 16);
989
983
copyReaderState_MyPCSCToServer(MYPCSC_LPSCARD_READERSTATE_A src, SERVER_LPSCARD_READERSTATE_A dst,
1032
1026
SERVER_DWORD dwTimeout;
1033
1027
SERVER_DWORD dwCount;
1034
1028
SERVER_LPSCARD_READERSTATE_A rsArray, cur;
1035
SERVER_DWORD *stateArray = NULL, *curState;
1036
1029
MYPCSC_LPSCARD_READERSTATE_A myRsArray;
1038
1031
PMEM_HANDLE lcHandle = NULL;
1040
RD_BOOL mapped = False;
1044
1034
in_uint32_le(in, dwTimeout);
1057
1047
return SC_returnNoMemoryError(&lcHandle, in, out);
1058
1048
memset(rsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));
1059
stateArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_DWORD));
1061
return SC_returnNoMemoryError(&lcHandle, in, out);
1062
1049
/* skip two pointers at beginning of struct */
1063
1050
for (i = 0, cur = (SERVER_LPSCARD_READERSTATE_A) ((unsigned char **) rsArray + 2);
1064
1051
i < dwCount; i++, cur++)
1067
1054
in_uint8a(in, cur, SERVER_SCARDSTATESIZE);
1070
for (i = 0, cur = rsArray, curState = stateArray;
1071
i < dwCount; i++, cur++, curState++)
1057
for (i = 0, cur = rsArray; i < dwCount; i++, cur++)
1073
1059
SERVER_DWORD dataLength;
1077
1063
cur->dwEventState = swap32(cur->dwEventState);
1078
1064
cur->cbAtr = swap32(cur->cbAtr);
1080
/* reset Current state hign bytes; */
1081
*curState = cur->dwCurrentState;
1082
cur->dwCurrentState &= 0x0000FFFF;
1083
cur->dwEventState &= 0x0000FFFF;
1086
if (cur->dwCurrentState == (SCARD_STATE_CHANGED | SCARD_STATE_PRESENT))
1088
cur->dwCurrentState = 0x00000000;
1092
if (mappedStatus(*curState))
1094
cur->dwCurrentState &= ~SCARD_STATE_INUSE;
1095
cur->dwEventState &= ~SCARD_STATE_INUSE;
1097
if (cur->dwCurrentState & SCARD_STATE_EMPTY)
1099
cur->dwCurrentState &= ~SCARD_STATE_EMPTY;
1100
cur->dwCurrentState |= SCARD_STATE_UNKNOWN;
1106
1067
in_uint32_le(in, dataLength);
1115
1076
DEBUG_SCARD(("SCARD: user: 0x%08x, state: 0x%08x, event: 0x%08x\n",
1116
1077
(unsigned) cur->pvUserData, (unsigned) cur->dwCurrentState,
1117
1078
(unsigned) cur->dwEventState));
1118
DEBUG_SCARD(("SCARD: current state: 0x%08x\n",
1119
(unsigned) *curState));
1124
1083
rsArray = NULL;
1128
1086
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A));
1149
1107
out_uint32_le(out, 0x00084dd8);
1150
1108
out_uint32_le(out, dwCount);
1152
for (i = 0, cur = rsArray, curState = stateArray; i < dwCount; i++, cur++, curState++)
1110
for (i = 0, cur = rsArray; i < dwCount; i++, cur++)
1155
cur->dwCurrentState = (*curState);
1156
cur->dwEventState |= (*curState) & 0xFFFF0000;
1159
if (mapped && (cur->dwCurrentState & SCARD_STATE_PRESENT)
1160
&& (cur->dwCurrentState & SCARD_STATE_CHANGED)
1161
&& (cur->dwEventState & SCARD_STATE_PRESENT)
1162
&& (cur->dwEventState & SCARD_STATE_CHANGED))
1164
cur->dwEventState |= SCARD_STATE_INUSE;
1166
else if (cur->dwEventState & SCARD_STATE_UNKNOWN)
1168
cur->dwEventState &= ~SCARD_STATE_UNKNOWN;
1169
cur->dwEventState |= SCARD_STATE_EMPTY;
1172
else if ((!mapped) && (cur->dwEventState & SCARD_STATE_INUSE))
1175
cur->dwEventState &= ~SCARD_STATE_INUSE;
1178
cur->dwEventState = incStatus(cur->dwEventState, mapped);
1180
cur->dwEventState = incStatus(cur->dwEventState, False);
1182
1112
DEBUG_SCARD(("SCARD: \"%s\"\n", cur->szReader ? cur->szReader : "NULL"));
1183
1113
DEBUG_SCARD(("SCARD: user: 0x%08x, state: 0x%08x, event: 0x%08x\n",
1184
1114
(unsigned) cur->pvUserData, (unsigned) cur->dwCurrentState,
2107
2043
/* read real input size */
2108
2044
in_uint32_le(in, nInBufferSize);
2109
pInBuffer = SC_xmalloc(&lcHandle, nInBufferSize);
2111
return SC_returnNoMemoryError(&lcHandle, in, out);
2112
in_uint8a(in, pInBuffer, nInBufferSize);
2045
if (nInBufferSize > 0)
2047
pInBuffer = SC_xmalloc(&lcHandle, nInBufferSize);
2049
return SC_returnNoMemoryError(&lcHandle, in, out);
2050
in_uint8a(in, pInBuffer, nInBufferSize);
2054
DEBUG_SCARD(("SCARD: SCardControl(context: 0x%08x, hcard: 0x%08x, code: 0x%08x, in: %d bytes, out: %d bytes)\n", (unsigned) hContext, (unsigned) hCard, (unsigned) dwControlCode, (int) nInBufferSize, (int) nOutBufferSize));
2056
/* Is this a proper Windows smart card ioctl? */
2057
if ((dwControlCode & 0xffff0000) == (49 << 16))
2059
/* Translate to local encoding */
2060
dwControlCode = (dwControlCode & 0x3ffc) >> 2;
2061
dwControlCode = SCARD_CTL_CODE(dwControlCode);
2065
warning("Bogus smart card control code 0x%08x\n", dwControlCode);
2128
2081
if (!pOutBuffer)
2129
2082
return SC_returnNoMemoryError(&lcHandle, in, out);
2131
DEBUG_SCARD(("SCARD: SCardControl(context: 0x%08x, hcard: 0x%08x, code: 0x%08x, in: %d bytes, out: %d bytes)\n", (unsigned) hContext, (unsigned) hCard, (unsigned) dwControlCode, (int) nInBufferSize, (int) nOutBufferSize));
2133
2084
sc_nBytesReturned = nBytesReturned;
2134
2085
myHCard = scHandleToMyPCSC(hCard);
2135
2086
#ifdef WITH_PCSC120
2152
2103
DEBUG_SCARD(("SCARD: -> Success (out: %d bytes)\n", (int) nBytesReturned));
2106
#ifdef PCSCLITE_VERSION_NUMBER
2107
if (dwControlCode == SCARD_CTL_CODE(3400))
2112
for (i = 0; i < nBytesReturned / 6; i++)
2114
memcpy(&cc, pOutBuffer + 2 + i * 6, 4);
2116
cc = cc - 0x42000000;
2117
cc = (49 << 16) | (cc << 2);
2119
memcpy(pOutBuffer + 2 + i * 6, &cc, 4);
2155
2124
out_uint32_le(out, nBytesReturned);
2156
2125
out_uint32_le(out, 0x00000004);
2157
2126
out_uint32_le(out, nBytesReturned);