Commit Graph

346 Commits

Author SHA1 Message Date
Ondrej Holy
7554154a04 smartcard: Fix usage of uninitialized values
This fixes the following defect reported by covscan tool:
 - channels/smartcard/client/smartcard_pack.c:942: uninit_use_in_call: Using uninitialized value "tmp" when calling "ConvertFromUnicode".
 - channels/smartcard/client/smartcard_pack.c:894: uninit_use_in_call: Using uninitialized value "tmp" when calling "ConvertFromUnicode".
 - channels/smartcard/client/smartcard_pack.c:475: uninit_use_in_call: Using uninitialized value "tmp" when calling "ConvertFromUnicode".
2020-06-04 07:55:12 +02:00
akallabeth
feb7d4f362 Changed smartcard no reader log message level to info 2020-05-08 11:21:51 +02:00
akallabeth
af79aafbba Fixed int overflow in smartcard_ndr_read
Thanks to hac425
2020-05-08 11:04:03 +02:00
Armin Novak
e80316cf9a Silence SCARD_E_TIMEOUT warnings
These occur quite often for status calls, so reduce log verbosity.
2020-05-04 17:32:55 +02:00
Alex Wilson
40f23e2728 SCardReadCache/SCardWriteCache should actually cache data
Currently since the hash/keyCompare/keyClone members on the
context->cache were never being set, we were using the
HashTable_Pointer* variants, meaning that lookup always
failed (since we never ask for the same *pointer* twice).

This also revealed that the logic for autoallocate on these ops
was a bit backwards, and some error codes and support for the
"freshness" counter were missing.

In Win10 (at least with some card minidrivers) the freshness
counter is load-bearing and smartcard login won't work without
implementing a very basic version of it.
2020-04-21 08:11:54 +02:00
akallabeth
6b66aa71fb Fixi #6086: smartcard filter early abort.
Do not abort before incrementing read position.
2020-04-14 19:04:11 +02:00
Alex Wilson
c6e675bfb7 Always copy null terminator when filtering smartcard list 2020-04-09 10:44:25 +02:00
akallabeth
2749de506c Added missing context and handle read. 2020-03-30 11:07:47 +02:00
Armin Novak
f360d445e2 Pack smartcard channel structs to 1 byte alignment 2020-03-27 18:24:25 +01:00
akallabeth
ac4ec690c9 Removed a few magic numbers. 2020-03-27 15:03:59 +01:00
akallabeth
80177efe69 Fixed typos, make status comparisons explicit. 2020-03-27 14:49:09 +01:00
Armin Novak
2968e41409 Fixed missing boundary checks in smartcard_array_dump 2020-03-02 09:01:39 +01:00
Armin Novak
bef8dda5e1 Fixed data length for list reader group return. 2020-02-20 15:35:11 +01:00
Armin Novak
5ab0716d7b SCardListReadersW return length is in bytes, not char. 2020-02-20 15:24:03 +01:00
Armin Novak
fd89ff6913 Fixed some conversion warnings. 2020-02-20 14:40:19 +01:00
Armin Novak
9b5f1ab384 Beautify smartcard log. 2020-02-20 13:59:28 +01:00
Armin Novak
893d08d653 Decreased smartcard log verbosity. 2020-02-20 13:59:28 +01:00
Armin Novak
a8e8351c1d Removed duplicated copyright claim 2020-02-20 13:59:28 +01:00
Armin Novak
f885476423 Fixed 8bit and 16bit return string sizes. 2020-02-20 13:59:28 +01:00
Armin Novak
ef93109f42 Fixes for GetAttrib and some refactroing
* Fix accidental buffer free before transfer
* Refactored code to eliminate a bunch of warnings
* Updated copyright headers
2020-02-20 13:59:28 +01:00
Armin Novak
fe61eab88c Fixed SCardReadCache autoallocate handling. 2020-02-20 13:59:28 +01:00
Armin Novak
04f0e679f7 Fixed NDR pointer handling for smartcard data. 2020-02-20 13:59:28 +01:00
Armin Novak
11d3ea3b43 Fix #5847: Missing length check to trace smartcard buffers. 2020-02-10 14:28:38 +01:00
Armin Novak
11f2532242 Added unified NDR pointer reading. 2020-01-24 13:52:43 +01:00
Armin Novak
7b50ed887e Fixed missing length checks for smartcard IRP read. 2020-01-24 13:23:40 +01:00
Armin Novak
f4ee8d92a7 Fixed smartcard type mismatches. 2020-01-23 10:39:43 +01:00
Armin Novak
f0db6f2ead Unified smartcart multistring conversion. 2020-01-23 10:07:54 +01:00
Armin Novak
ee7950c95c Fixed type mismatches on allocation. 2020-01-23 09:48:20 +01:00
Armin Novak
ec5881e3f2 Fixed smartcard_SetAttrib_Decode call type 2020-01-23 09:32:34 +01:00
Armin Novak
dfe7b8c8da Implement missing functions for new smartcard
Newer smartcard channel behaviour expects a lot more callbacks
being implemented. This change provides them.
2020-01-13 11:27:37 +01:00
Armin Novak
7c243da6e1 Remove symbols exported by accident. 2019-12-02 10:57:31 +01:00
Armin Novak
72ca88f49c Reformatted to new style 2019-11-07 10:53:54 +01:00
Armin Novak
59b4988f56 Fixed compilation warnings. 2019-10-16 14:54:05 +02:00
Bernhard Miklautz
a311075202 fix [channels/smartcard]: fix StatusW_Call
According to 2.2.2.18 Status_Call cbAtrLen is unused an must be ignored
upon receipt.
2019-07-30 09:48:47 +02:00
Armin Novak
60a82854c1 For smartcard trace functions use const arguments 2019-05-08 15:13:03 +02:00
Armin Novak
4b72a85e91 Fixed possible memory leak. 2019-05-08 15:12:40 +02:00
Armin Novak
8f7e1579fd Silenced unused parameter warnings in smartcard trace 2019-05-08 12:27:51 +02:00
r-barnett
40ef08ddc5 Fix smartcard segfault when no devices are present (#5364)
* Don't assume smartcard reader list is not empty.

* Check status of retrieval of smartcard device list before trying to filter it

* style fixes
2019-05-02 06:11:57 +02:00
Pascal J. Bourguignon
431c37f3a9 5360 segfault using smartcard without any readers (#5361)
* Fix: corrected test for astyle.

* Fix: added test for NULL readers returned by ConvertFromUnicode.
2019-04-26 09:10:41 +02:00
Armin Novak
b9b3f3eda7 Fixed sign-compare warnings 2019-04-05 09:13:24 +02:00
Armin Novak
ef1728faf5 Fixed NULL dereferences and uninitialized values 2019-01-30 16:11:10 +01:00
Armin Novak
a8a6accc15 Fixed compiler warnings. 2018-10-03 15:16:59 +02:00
Armin Novak
f63286dbea Fixed smartcard filter for empty arguments. 2018-09-19 11:13:02 +02:00
Armin Novak
4596588e0f Set freed pointer to NULL avoiding double free. 2018-09-04 15:22:06 +02:00
Armin Novak
b2ce309b28 Added multi filter for smartcard. (based on #4837 by @informatimago) 2018-09-04 14:34:32 +02:00
Ondrej Holy
97f25e8ab4 channels/smartcard: Fix leak found by covscan
leaked_storage: Variable "operation" going out of scope leaks the storage it points to.
2018-08-22 13:35:43 +02:00
Ondrej Holy
3baa716706 channels/smartcard: Format code by astyle
Run ./scripts/format_code.sh before the following changes.
2018-08-22 13:35:43 +02:00
Ruben De Visscher
1835a39aaf Fix inconsistent cBytes value between WinScard and pcsc-lite. 2018-04-24 10:33:44 +02:00
Armin Novak
2517755d25 Fixed thread function return and parameters. 2018-03-07 14:36:55 +01:00
Jukka-Pekka Virtanen
2e8f2c693d [MS-RDPESC] 2.2.2.18 Status_Call.cbAtrLen: Unused. MUST be ignored upon receipt.
The [MS-RDPESC] clearly states in section 2.2.2.18 that Status_Call's
cbAtrLen must not be used when generating Status_Return response. This
is also how FreeRDP 1.1 behaves.
2018-01-11 16:23:15 +02:00
Armin Novak
bb7ba6ff26 Fixed smartcard related scanbuild warnings. 2017-12-21 10:53:36 +01:00
Armin Novak
6a21bdae3d Fixed various scanbuild warnings. 2017-12-21 09:34:35 +01:00
Bernhard Miklautz
36c6478627 fix client/smartcard: indentation and return value
Integrate feedback from pull request review.
2017-12-14 16:21:19 +01:00
Bernhard Miklautz
5a1c0081c5 fix smartcard: SCardStatus unicode handling
* fix StatusW_Call to rely and use SCardStatusW
* fix trace call in  StatusW_Call - needs to be called after the sizes
  are set
* unify SCardStatus functions for pcsc - let the internal function handle unicode directly

This fixes an issue with size calculations of SCardStatusW.
2017-12-14 15:46:14 +01:00
Bernhard Miklautz
94b35cb4f7 fix channel/smartcard: leak in Connect[AW]
smartcard_Connect[AW] leaked the reader buffer in error case.
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
9fc754170b fix channel/smartcard: SCardStatus
Add support for fmszReaderNamesIsNULL. Formating of the touched files
was also updated.
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
bc8bdc3e54 fix channel/smartcard: compiler warnings
* remove unused variables
* remove unused jump label
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
e3d45c4580 fix channel/smartcard: remove SCardAddReaderName
SCardAddReaderName isn't part of the SCard API.

Note: removing this also removes the possibility to redirect single
smartcard readers with /smartcard:READERNAME. However this features
wasn't implemented in a general way and will be re-added as part of
the smart card channel directly.
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
1e6fea7fa7 fix channel/smartcard: simplify channel variables
Path was not really used and name was duplicated. Use the device->Name
directly.
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
f8a3e7acd4 fix channel/smartcard: GetStatusChange return code
In case SCardGetStatusChange returned an error the call didn't return
any data but STATUS_NO_MEMORY as the calloc failed. This caused problems
with multiple applications server side (hangs and incorrect behavior).

Now the case when no readers are returned is handed correctly and the
data is also filled and send if the call fails.
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
46a7538322 fix channel/smartcard: async request handling
The smart card channel tried to mimic mstsc's behavior on if an IRP was
processed synchronously or asynchronously. As the channel uses one thread per
context it could happen, especially with PCSC, that the main
channel thread was blocked waiting for an smart card operation to
complete. To prevent that behavior only call known safe functions in the
main thread (like CreateContext) and call the rest asynchronously.

For example the channel would block if a ListReaders is invoked on
the same context where a GetStatusChange (infinite timeout)
was already pending. Only when a status change happened the channel
would continue.

Note: Due to the one context per thread design it's important that
cancel isn't queued an alway run synchronously. Otherwise a specific
context might lock.
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
3dc4e283db fix channel/smartcard: return value handling
Device control calls always returned SCARD_S_SUCCESS even if an error
occurred. This caused server side software (including the card manager)
to behave incorrectly.
2017-12-13 17:04:06 +01:00
Bernhard Miklautz
99c69cde27 fix channel/smartcard: error handling
According to MS-RDPESC the smart card channel must set the IoStatus to
an NTSTATUS in case a encoding or decoding error happens. The smart card
channel did this correctly but the output stream was modified
incorrectly causing the smart card remote manager to stop in error
cases.
2017-12-13 17:04:06 +01:00
Armin Novak
0490aeb018 Fixed clang malloc integer overflow warnings. 2017-07-20 09:29:48 +02:00
dodo040
03723c2738 fix wrong declaration 2017-07-19 13:16:08 +02:00
dodo040
722e927c64 redirect specific smartcard readers 2017-07-19 13:16:08 +02:00
Armin Novak
b2c29158be Scanbuild warning, argument checks and leak fixes.
* Added Stream_GetRemainingCapacity to check remaining stream size
  before writes.
* Fixed shadow server memory leak.
* Fixed lots of scanbuild warnings
* Added missing argument checks in many functions
* Added missing static function declarations
2017-03-02 18:13:43 +01:00
Armin Novak
ff56f75893 Fixed format specifier and unused variables. 2017-02-17 14:25:59 +01:00
Andreas Schultz
d2f98261f7 smartcard: implement ListReaderGroups
Conflicts:
	channels/smartcard/client/smartcard_operations.c
	channels/smartcard/client/smartcard_pack.c
	channels/smartcard/client/smartcard_pack.h

smartcard_operations: move handling of call argument into functions

The call argument was only use by static functions and was always equal
to operation->call. Remove the argument and use operation-call directly.

Also put the memory allocation and check into the same place.

Conflicts:
	channels/smartcard/client/smartcard_operations.c

Updated formatting and API
2017-02-16 16:59:03 +01:00
Norbert Federa
f71b6b46e8 fix string format specifiers
- fixed invalid, missing or additional arguments
- removed all type casts from arguments
- added missing (void*) typecasts for %p arguments
- use inttypes defines where appropriate
2016-12-16 13:48:43 +01:00
Norbert Federa
c6e6b44143 countless WLog/printf format specifier fixes 2016-11-25 17:06:25 +01:00
Marc-André Moreau
dee76617d9 channels: remove thread-local storage usage 2016-11-15 11:41:01 -05:00
Armin Novak
b0b32734ad Reformatted file. 2016-10-06 13:43:13 +02:00
Armin Novak
9f5da483dc Reformatted files touched in last 2 commits. 2016-10-06 13:43:12 +02:00
Armin Novak
88a3b8dd76 Initializing channel context in each thread. 2016-10-06 13:43:12 +02:00
David PHAM-VAN
d5dc5b4a3f Fix smartcard channel disconnect 2016-09-19 11:27:25 -07:00
Norbert Federa
ef4b29e5b3 ConvertFromUnicode fixes and misc hardening
- Added missing ConvertFromUnicode checks
- If ConvertToUnicode allocates memory, guarantee the null termination
  similar to ConvertFromUnicode's implementation
- Fixed some TestUnicodeConversion.c CTest return values
- Added some CTests for ConvertFromUnicode and ConvertToUnicode
- Misc code and protocol hardening fixes in the surrounding code regions
  that have been touched
2016-03-03 16:56:19 +01:00
Bernhard Miklautz
6fa3608111 cleanup cmake exports and pkg-config files
With this commit the "exported" components (usable with pkg-config and
cmake find module package)
* winpr - winpr library and headers
* freerdp - core library and headers
* freerdp-client - client specific library
* freerdp-server - server specific library
* rdtk - rdtk headers and library

To allow the installation of multiple different version (different major
number) the include files were moved into the respective sub folder:
freerdp -> freerdp{MAJOR}/freerdp (currently freerdp2/freerdp/)
winpr -> winpr{MAJOR}/winpr (currently winrp1/winpr/)
rdtk -> rdpk{MAJOR}/rdtk (currently rdtk0/rdtk/

The generated pkg-config and cmake find modules now also include the major
version number. Currently the following pkg-config are generated and
installed.
* winpr1
* freerdp2
* freerdp-server2
* freerdp-client2
* rdtk0

As cmake is able to handle multiple versions out of the box the
following can be used to find a specific module:

find_package(WinPR)
find_package(FreeRDP)
find_package(FreeRDP-Server)
find_package(FreeRDP-Client)
find_package(RdTk)

As cmake doesn't automatically resolve dependencies for packages it is
necessary to manually include the requirements. For example if
FreeRDP-Client is required WinPR and FreeRDP need to be included
(find_package) as well.

This commit also fixes the installation when STATIC_CHANNELS are built.
WITH STATIC_CHANNELS all channels are linked into libfreerdp-client, for
this all channels are generated as linker archive and linked together in
the final step. Before the intermediate linker archives were, although
not required and useful, installed. Same applies for server side
channels.
2016-01-12 17:32:33 +01:00
Armin Novak
cb958ba9c6 Added pdb files to package target.
Fixed name collision with freerdp-shadow targets.
2015-12-15 12:07:21 +01:00
bjcollins
456416a871 Dont use invalid/bogus input value for cbAtrLen for Smartcard Status Calls, instead just always use the max value here to indicate we have max
buffer space available.
2015-09-18 16:55:06 -05:00
Armin Novak
911750f0f6 Checking for allocation value > 0 2015-09-07 11:10:27 +02:00
Armin Novak
97f7aa8f42 Fixed uninitialized values. 2015-09-01 12:27:54 +02:00
Armin Novak
aa43f3b5df Fixed zero lenght allocation. 2015-09-01 12:25:44 +02:00
Marc-André Moreau
90b7d42429 Merge pull request #2838 from akallabeth/smartcard_no_readers
Added return value checks for smartcard functions.
2015-08-27 10:05:23 -04:00
Martin Haimberger
52405a3e79 Remove WIN32ERROR type
All return values are UINT now.
2015-08-27 05:38:20 -07:00
Armin Novak
c40f3198a4 Added return value checks. 2015-08-19 12:50:48 +02:00
Martin Haimberger
2862109337 Merge remote-tracking branch 'upstream/master' into mh-channel-fix
Conflicts:
	channels/smartcard/client/smartcard_main.c
	channels/smartcard/client/smartcard_operations.c
2015-07-30 07:29:12 -07:00
Martin Haimberger
65fd259610 misc fixes:
fixed all bugs from the review
checking all WaitFor*Object/s calls
2015-07-30 06:49:21 -07:00
Marc-André Moreau
dfa29804ad Merge pull request #2799 from kaliway/scardlistreaders-fix
Smartcard Reader Connection Handling
2015-07-28 08:51:03 -04:00
Kirill Kotyagin
ef37487a44 channels/smartcard: fix possible mszReaders leak in smartcard_ListReaders(A/W)_Call 2015-07-22 17:25:17 +03:00
Kirill Kotyagin
76916d614b channels/smartcard: make smartcard_ListReaders(A/W)_Call return PCSC error statuses to the server 2015-07-22 16:56:24 +03:00
Rostislav Kondratenko
7248ea98d0 Fixing condition on SCardIsValidContext to be true when context is valid 2015-07-17 18:13:02 +03:00
Rostislav Kondratenko
f2863fabf5 Re-enabled PCSC-Lite transactions and fixed smartcard deinitialization so it will release all contexts to unblock calls waiting for transactions 2015-07-17 16:37:44 +03:00
Martin Haimberger
b8c110d19b introduced channel error reporting system
The rdpContext gets an event which will
get set if an error occoured in a channel.

If a thread or a void callback has to report an
error it will get signaled by this system.
2015-07-15 00:50:35 -07:00
Martin Haimberger
d9e2834a70 channel smartcard hardend 2015-07-09 03:00:19 -07:00
Martin Haimberger
6e4e1c2773 Merge remote-tracking branch 'upstream/master' into mh-stream-fix
Conflicts:
	client/Windows/wf_cliprdr.c
2015-06-18 03:06:40 -07:00
Martin Haimberger
76305a716c just satisfied compiler 2015-06-18 03:04:33 -07:00
David FORT
12f873f1f9 Fixed MessageQueue and callers 2015-05-29 14:24:14 +02:00
Bernhard Miklautz
d922afc24a smartcard: fix compiler warnings
gcc 4.7.2:
warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from
pointer target type
2015-05-18 11:36:31 +02:00
Hardening
f8120919af Add checks for some XXX_New and XXX_Add functions
Based on PR #2616
2015-05-18 11:28:00 +02:00