Important!

Blog moved to https://blog.apdu.fr/

I moved my blog from https://ludovicrousseau.blogspot.com/ to https://blog.apdu.fr/ . Why? I wanted to move away from Blogger (owne...

Tuesday, October 19, 2010

pcsc-lite upgrade and Ubuntu special configuration

Ubuntu uses a special configuration of pcsc-lite. The libpcsclite.so.1 library is not in /usr/lib but in /lib. See the file list of the libpcsclite1 Ubuntu package for example. This is because libpcsclite.so.1 is used by the wpa_supplicant software and this software should be accessible before /usr is mounted. See Debian bug #531592 "libpcsclite1: move to /lib" and Ubuntu bug #44194 "wpasupplicant doesn't start when the network start"

The problem

By default pcsc-lite install its files in /usr/local but this path can be changed using the --prefix= argument. The standard way to install a software is to use:
./configure --prefix=/usr
make
sudo make install

This will install the daemon pcscd in /usr/sbin/pcscd and the library in /usr/lib.

The daemon provided by the pcscd package is replaced by the new one. But the new library does not replace the old one. So the system will have:

  • /usr/sbin/pcscd: new version
  • /lib/libpcsclite.so.1: old version
  • /lib/libpcsclite.so.1.0.0: old version
  • /usr/lib/libpcsclite.so.1: new version
  • /usr/lib/libpcsclite.so.1.0.0: new version

Of course programs provided by Ubuntu are linked with /lib/libpcsclite.so.1 so they will not use the new version. The old libpcslite will try to communicate with the new pcscd and since I changed the communication protocol that will fail. A typical example can be found in the support request [#312772] RPC Transport error:

$ pcsc_scan
PC/SC device scanner
V 1.4.16 (c) 2001-2009, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC lite version: 1.5.3
SCardEstablishContext: RPC transport error.

The solution

The solution is to install the new version and also replace the old one. It is not possible to remove the /lib/libpcsclite.so.1* files since they are used by Ubuntu compiled programs.

For example pcsc_scan uses /lib/libpcsclite.so.1

$ ldd -r /usr/bin/pcsc_scan 
linux-gate.so.1 =>  (0x00b71000)
libpcsclite.so.1 => /lib/libpcsclite.so.1 (0x003f3000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00836000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00cee000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x001a1000)
/lib/ld-linux.so.2 (0x009e3000)

So it is not a good idea to remove the libpcsclite1 package since that will also remove other packages (because of dependencies) like libccid libpcsc-perl libpcsclite1 network-manager network-manager-gnome pcsc-tools pcscd ubuntu-desktop wpasupplicant. It is not a good idea to install a non packaged software. But many people do this without knowing what they do. So I propose to help them and avoid answer the many bug report I get because of the special Ubuntu configuration.

Install the new pcsc-lite


$ make install

Fix the old pcsc-lite


$ cd /lib
$ ln -sf /usr/lib/libpcsclite.so.1.0.0

This will repace /lib/libpcsclite.so.1.0.0 by a symbolic link to /usr/lib/libpcsclite.so.1.0.0. /lib/libpcsclite.so.1 is already a symbolic link to /lib/libpcsclite.so.1.0.0.

The Ubuntu wrong solution

wpa_supplicant is linked with /lib/libpcsclite.so.1 so can be run even if /usr is not yet mounted. But the daemon pcscd is in /usr/sbin so can't be used yet. So the smart card part of wpa_supplicant can't be used without /usr mounted.

Ubuntu solved the compilation problem. But it does not solve the usability problem.

You can also note that the libpcsclite1 Ubuntu package is in main but the pcscd Ubuntu package is in universe. That is strange since the two packages are generated from the same source archive.

The correct solution

The correct solution would be to load the libpcsclite.so.1 at run time using an explicit dlopen() only if the smart card is used by wpa_supplicant.
The smart card could only be used after /usr is mounted. But I think that is a very reasonable limitation.

Conclusion

Diverting from a standard (library in /usr/lib in the present case) has a cost. The problem is that the cost is not payed by the one diverting from the standard. The cost is payed by other people (me, in the present case) that get support requests.

In economy that is called a externality. In the present case it is a negative externality.

Update, May 2017

Ubuntu (for example version 14.04 and later) installs the libpcsclite.so.1 library in the directory
  • /lib/x86_64-linux-gnu/ on a Intel/AMD 64-bits system
  • /lib/i386-linux-gnu/ on an Intel/AMD 32-bits system

While Debian uses:
  • /usr/lib/x86_64-linux-gnu/
  • /usr/lib/i386-linux-gnu/

So be careful to use the correct ./configure arguments when re-building pcsc-lite.