sc_lock(3)

NAME
sc_lock, sc_unlock - lock or unlock smart card

SYNOPSIS
#include <opensc.h>

int sc_lock(sc_card_t *card);
int sc_unlock(sc_card_t *card);

DESCRIPTION
These functions handle locking of smart cards, in order to prevent concurrent access to the same card by different users.

Locking is important to prevent unauthorized access to the card after presenting the PIN, for instance.

After a call to sc_lock, concurrent access by other application to the same smart card reader is disallowed, provided the reader middleware supports this (see below). A lock must later be released by calling sc_unlock. When disconnecting from the card using sc_disconnect_card, there must not be anymore locks on the card.

Calls to sc_lock may be nested, i.e. if sc_lock is called five times in a row, the lock will not be released until the fifth call to sc_unlock.

Note that these functions do not offer mutual exclusion for different threads within the same application process. Multithread locking is the application's job (Note that the OpenSC PKCS11 module provides MT locking facilities, as that's part of the standard).

NOTES
Whether locking is effective depends a lot on the middleware used to talk to the card reader. CT-API based drivers for instance perform no interprocess locking at all.

The only middleware implementations currently supported by OpenSC that do perform this type of locking are PC/SC and OpenCT.

RETURN VALUE
If an error occurred, a negative error code is returned, as described in sc_error(3). Otherwise, the function will return 0.

SEE ALSO
sc_connect_card(3).

AUTHOR
This manual page was written by Olaf Kirch <okir@suse.de>