- from PLD
authorMarcin Krol <hawk@tld-linux.org>
Wed, 8 Jul 2015 15:36:48 +0000 (15:36 +0000)
committerMarcin Krol <hawk@tld-linux.org>
Wed, 8 Jul 2015 15:36:48 +0000 (15:36 +0000)
configure-expand.patch [new file with mode: 0644]
debuglog-pid.patch [new file with mode: 0644]
noautostart.patch [new file with mode: 0644]
pcsc-lite-any.patch [new file with mode: 0644]
pcsc-lite-fhs.patch [new file with mode: 0644]
pcsc-lite-pcscd.init [new file with mode: 0644]
pcsc-lite-pcscd.sysconfig [new file with mode: 0644]
pcsc-lite.spec [new file with mode: 0644]
pcsc-lite.tmpfiles [new file with mode: 0644]
pcscd.upstart [new file with mode: 0644]

diff --git a/configure-expand.patch b/configure-expand.patch
new file mode 100644 (file)
index 0000000..3b7af9a
--- /dev/null
@@ -0,0 +1,10 @@
+--- pcsc-lite-1.8.8/configure.ac~      2010-12-12 12:03:57.000000000 +0200
++++ pcsc-lite-1.8.8/configure.ac       2011-01-12 02:44:22.154890564 +0200
+@@ -338,6 +338,7 @@
+ AC_SUBST(host_to_ccid_16)
+ AC_SUBST(host_to_ccid_32)
+ AS_AC_EXPAND(confdir_exp,$confdir)
++AS_AC_EXPAND(sysconfdir_exp,$sysconfdir)
+ AS_AC_EXPAND(sbindir_exp,$sbindir)
+ AS_AC_EXPAND(localstatedir_exp,$localstatedir)
diff --git a/debuglog-pid.patch b/debuglog-pid.patch
new file mode 100644 (file)
index 0000000..f681d95
--- /dev/null
@@ -0,0 +1,31 @@
+--- pcsc-lite-1.6.6/src/debuglog.c~    2010-06-30 15:40:58.000000000 +0300
++++ pcsc-lite-1.6.6/src/debuglog.c     2011-01-12 01:58:18.693291099 +0200
+@@ -104,6 +104,8 @@
+ {
+       char DebugBuffer[DEBUG_BUF_SIZE];
+       va_list argptr;
++      // boolean not to do openlog several times
++      static int syslog_opened = 0;
+       if ((LogSuppress != DEBUGLOG_LOG_ENTRIES)
+               || (priority < LogLevel) /* log priority lower than threshold? */
+@@ -114,13 +116,18 @@
+       vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
+       va_end(argptr);
++      if (DEBUGLOG_SYSLOG_DEBUG == LogMsgType && !syslog_opened) {
++              openlog(NULL, LOG_PID, LOG_DAEMON);
++              syslog_opened = 1;
++      }
++
+       log_line(priority, DebugBuffer);
+ } /* log_msg */
+ static void log_line(const int priority, const char *DebugBuffer)
+ {
+       if (DEBUGLOG_SYSLOG_DEBUG == LogMsgType)
+-              syslog(LOG_INFO, "%s", DebugBuffer);
++              syslog(LOG_DEBUG, "%s", DebugBuffer);
+       else
+       {
+               if (LogDoColor)
diff --git a/noautostart.patch b/noautostart.patch
new file mode 100644 (file)
index 0000000..f99ebaa
--- /dev/null
@@ -0,0 +1,102 @@
+# Disable pcscd on-demand startup (#653903)
+https://bugzilla.redhat.com/show_bug.cgi?id=653903
+
+--- pcsc-lite-1.7.0/src/winscard_clnt.c.orig   2011-02-22 23:20:25.000000000 +0100
++++ pcsc-lite-1.7.0/src/winscard_clnt.c        2011-03-18 16:44:57.275416294 +0100
+@@ -444,80 +444,16 @@
+       LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
+ {
+       LONG rv;
+-      int daemon_launched = FALSE;
+-      int retries = 0;
+       API_TRACE_IN("%ld, %p, %p", dwScope, pvReserved1, pvReserved2)
+       PROFILE_START
+-again:
+       /* Check if the server is running */
+       rv = SCardCheckDaemonAvailability();
+       if (SCARD_E_INVALID_HANDLE == rv)
+               /* we reconnected to a daemon or we got called from a forked child */
+               rv = SCardCheckDaemonAvailability();
+-      if (SCARD_E_NO_SERVICE == rv)
+-      {
+-launch:
+-              if (daemon_launched)
+-              {
+-                      retries++;
+-                      if (retries < 50)       /* 50 x 100ms = 5 seconds */
+-                      {
+-                              /* give some more time to the server to start */
+-                              SYS_USleep(100*1000);   /* 100 ms */
+-                              goto again;
+-                      }
+-
+-                      /* the server failed to start (in time) */
+-                      goto end;
+-              }
+-              else
+-              {
+-                      int pid;
+-
+-                      pid = fork();
+-
+-                      if (pid < 0)
+-                      {
+-                              Log2(PCSC_LOG_CRITICAL, "fork failed: %s", strerror(errno));
+-                              rv = SCARD_F_INTERNAL_ERROR;
+-                              goto end;
+-                      }
+-
+-                      if (0 == pid)
+-                      {
+-                              int i, max;
+-                              char *param = getenv("PCSCLITE_PCSCD_ARGS");
+-
+-                              /* close all file handles except stdin, stdout and
+-                               * stderr so that pcscd does not confiscate ressources
+-                               * allocated by the application */
+-                              max = sysconf(_SC_OPEN_MAX);
+-                              if (-1 == max)
+-                                      max = 1024;
+-                              for (i=3; i<max; i++)
+-                                      (void)close(i);
+-
+-                              /* son process */
+-                              execl(PCSCD_BINARY, "pcscd", "--auto-exit", param,
+-                                      (char *)NULL);
+-                              Log2(PCSC_LOG_CRITICAL, "exec " PCSCD_BINARY " failed: %s",
+-                                      strerror(errno));
+-                              exit(1);
+-                      }
+-
+-                      /* father process */
+-                      daemon_launched = TRUE;
+-
+-                      if (waitpid(pid, NULL, 0) < 0)
+-                              Log2(PCSC_LOG_CRITICAL, "waitpid failed: %s", strerror(errno));
+-
+-                      goto again;
+-              }
+-      }
+-
+       if (rv != SCARD_S_SUCCESS)
+               goto end;
+@@ -526,15 +462,6 @@
+               pvReserved2, phContext);
+       (void)SCardUnlockThread();
+-      /* SCardEstablishContextTH may fail if the previous pcscd crashed
+-       * without cleaning /var/run/pcscd/pcscd.comm */
+-      if (SCARD_E_NO_SERVICE == rv)
+-      {
+-              retries++;
+-              if (retries <= 1)
+-                      goto launch;
+-      }
+-
+ end:
+       PROFILE_END(rv)
+       API_TRACE_OUT("%ld", *phContext)
diff --git a/pcsc-lite-any.patch b/pcsc-lite-any.patch
new file mode 100644 (file)
index 0000000..58eaab6
--- /dev/null
@@ -0,0 +1,28 @@
+--- pcsc-lite-1.5.2/src/winscard.c.orig        2009-02-06 09:46:20.000000000 +0100
++++ pcsc-lite-1.5.2/src/winscard.c     2009-04-02 22:54:43.137718835 +0200
+@@ -430,6 +430,12 @@
+                       {
+                               (void)SYS_MutexUnLock(rContext->mMutex);
++                              /*
++                               * If it is set to ANY let it do any of the protocols
++                               */
++                              if (dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD)
++                                      dwPreferredProtocols = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1;
++
+                               if (! (dwPreferredProtocols & rContext->readerState->cardProtocol))
+                                       return SCARD_E_PROTO_MISMATCH;
+                       }
+@@ -758,6 +764,12 @@
+                       {
+                               (void)SYS_MutexUnLock(rContext->mMutex);
++                              /*
++                               * If it is set to ANY let it do any of the protocols
++                               */
++                              if (dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD)
++                                      dwPreferredProtocols = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1;
++
+                               if (! (dwPreferredProtocols & rContext->readerState->cardProtocol))
+                                       return SCARD_E_PROTO_MISMATCH;
+                       }
diff --git a/pcsc-lite-fhs.patch b/pcsc-lite-fhs.patch
new file mode 100644 (file)
index 0000000..8550382
--- /dev/null
@@ -0,0 +1,24 @@
+--- pcsc-lite-1.8.11/DRIVERS.orig      2014-03-07 21:54:54.054804707 +0100
++++ pcsc-lite-1.8.11/DRIVERS   2014-03-07 21:59:19.138126916 +0100
+@@ -3,17 +3,17 @@
+ To install USB drivers, download the driver from
+ http://musclecard.com/software.html and copy it to a temporary location.
+ After you have unarchived the files copy the directory to
+-/usr/local/pcsc/drivers/.  If the directory /usr/local/pcsc/drivers/
++/usr/lib*/pcsc/drivers/.  If the directory /usr/lib*/pcsc/drivers/
+ does not exist create it before copying the driver directory to it.
+ Example Mac OS X, Linux 2.4:
+ tar -xzvf driver.bundle-0.1.0.tar.gz
+-cp -r driver.bundle /usr/local/pcsc/drivers/
+-cd /usr/local/pcsc/drivers/driver.bundle
++cp -r driver.bundle /usr/lib*/pcsc/drivers/
++cd /usr/lib*/pcsc/drivers/driver.bundle
+ build or use Project Builder to build
+-The /usr/local/pcsc/drivers/ directory should contain bundle directories only.
++The /usr/lib*/pcsc/drivers/ directory should contain bundle directories only.
+ You must restart pcscd to use the new driver.
diff --git a/pcsc-lite-pcscd.init b/pcsc-lite-pcscd.init
new file mode 100644 (file)
index 0000000..8d7e7be
--- /dev/null
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# pcscd                PC/SC Smartcard daemon
+#
+# chkconfig:   2345 12 88
+#
+# description: The PC/SC smart card daemon is a resource manager for the \
+#              PC/SC lite and Musclecard frameworks.  It coordinates \
+#              communications with smart card readers, smart cards, and \
+#              cryptographic tokens that are connected to the system.
+#
+# processname: pcscd
+# config:      /etc/reader.conf.d
+#
+# Note!  pcscd should be started after pcmcia, and shut down before it
+# for smooth experience with PCMCIA readers.
+#
+# $Id$
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+upstart_controlled
+
+umask 077
+
+# Set defaults
+LOGLEVEL=""
+PCSCD_OPTIONS=""
+
+# Get service config - may override defaults
+[ -f /etc/sysconfig/pcscd ] && . /etc/sysconfig/pcscd
+
+pidfile=/var/run/pcscd/pcscd.pid
+
+start() {
+       if [ -f /var/lock/subsys/pcscd ]; then
+               msg_already_running "PC/SC smart card daemon"
+               return
+       fi
+
+       local logopt
+       case "$LOGLEVEL" in
+       debug|info|error|critical)
+               logopt=--$LOGLEVEL
+       ;;
+       esac
+
+       msg_starting "PC/SC smart card daemon"
+       daemon /usr/sbin/pcscd $logopt $PCSCD_OPTIONS
+       RETVAL=$?
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pcscd
+}
+
+stop() {
+       if [ ! -f /var/lock/subsys/pcscd ]; then
+               msg_not_running "PC/SC smart card daemon"
+               return
+       fi
+
+       msg_stopping "PC/SC smart card daemon"
+       killproc --pidfile $pidfile pcscd
+       rm -f /var/lock/subsys/pcscd
+}
+
+condrestart() {
+       if [ ! -f /var/lock/subsys/pcscd ]; then
+               msg_not_running "PC/SC smart card daemon"
+               RETVAL=$1
+               return
+       fi
+
+       stop
+       start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop
+       ;;
+  restart)
+       stop
+       start
+       ;;
+  try-restart)
+       condrestart 0
+       ;;
+  force-reload)
+       # pcscd doesn't support reloading on HUP
+       condrestart 7
+       ;;
+  status)
+       status --pidfile $pidfile pcscd
+       RETVAL=$?
+       ;;
+  *)
+       msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+       exit 3
+esac
+
+exit $RETVAL
diff --git a/pcsc-lite-pcscd.sysconfig b/pcsc-lite-pcscd.sysconfig
new file mode 100644 (file)
index 0000000..4ad20eb
--- /dev/null
@@ -0,0 +1,10 @@
+# Customized settings for pcscd
+
+# set loglevel. valid values: debug, info, error, critical
+#LOGLEVEL="debug"
+
+# options for pcscd daemon
+#PCSCD_OPTIONS=""
+
+# Define nice level for pcscd
+SERVICE_RUN_NICE_LEVEL="+0"
diff --git a/pcsc-lite.spec b/pcsc-lite.spec
new file mode 100644 (file)
index 0000000..68a5026
--- /dev/null
@@ -0,0 +1,240 @@
+# TODO
+# - pcscd & pcscd-lite-libs need to be exactly same version installed otherwise
+#   client will flood daemon so much that daemon is not usable (max 200
+#   connections reached, etc)
+#
+# Conditional build:
+%bcond_without polkit  # polkit support
+%bcond_without udev    # udev support (plain libusb if disabled)
+
+Summary:       PCSC Framework for Linux
+Summary(pl.UTF-8):     Środowisko PCSC dla Linuksa
+Name:          pcsc-lite
+Version:       1.8.11
+Release:       2
+License:       BSD
+Group:         Daemons
+# Source0Download: https://alioth.debian.org/frs/?group_id=30105
+Source0:       https://alioth.debian.org/frs/download.php/file/3991/%{name}-%{version}.tar.bz2
+# Source0-md5: 73502ca4ba6526727f9f49c63d805408
+Source1:       %{name}-pcscd.init
+Source2:       %{name}-pcscd.sysconfig
+Source3:       pcscd.upstart
+Source4:       %{name}.tmpfiles
+Patch0:                %{name}-fhs.patch
+Patch1:                %{name}-any.patch
+Patch2:                debuglog-pid.patch
+Patch3:                configure-expand.patch
+URL:           https://alioth.debian.org/projects/pcsclite/
+BuildRequires: autoconf >= 2.69
+BuildRequires: automake >= 1:1.8
+BuildRequires: flex
+%{?with_apidocs:BuildRequires: graphviz}
+BuildRequires: libtool >= 2:2.0
+%{!?with_udev:BuildRequires:   libusb-devel >= 1.0}
+BuildRequires: pkgconfig
+%{?with_polkit:BuildRequires:  polkit-devel >= 0.111}
+BuildRequires: rpmbuild(macros) >= 1.647
+%{?with_udev:BuildRequires:    udev-devel}
+Requires(post,preun):  /sbin/chkconfig
+Requires(pretrans):    fileutils
+%{?with_polkit:Requires:       polkit >= 0.111}
+Requires:      rc-scripts >= 0.4.3.0
+Requires:      systemd-units >= 38
+BuildRoot:     %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%define                usbdropdir      /usr/%{_lib}/pcsc/drivers
+
+%description
+pcscd is the daemon program for PC/SC Lite. It is a resource manager
+that coorinates communications with Smart Card readers and Smart Cards
+that are connected to the system. The purpose of PCSC Lite is to
+provide a Windows(R) SCard interface in a very small form factor for
+communicating to smartcards and readers. PCSC Lite uses the same
+winscard api as used under Windows(R).
+
+%description -l pl.UTF-8
+pcscd jest demonem dla PC/SC Lite. Jest to zarządca zasobów,
+koordynujący komunikację z czytnikami kart procesorowych podłączonymi
+do systemu. Celem PCSC Lite jest udostępnienie interfejsu zgodnego z
+Windows(R) SCard służącego do komunikacji z czytnikami kart chipowych.
+Używa tego samego API winscard, które jest używane pod Microsoft(TM)
+Windows(R).
+
+%package libs
+Summary:       PC/SC Lite libraries
+Summary(pl.UTF-8):     Biblioteki PC/SC Lite
+Group:         Libraries
+
+%description libs
+PC/SC Lite libraries.
+
+%description libs -l pl.UTF-8
+Biblioteki PC/SC Lite.
+
+%package devel
+Summary:       PC/SC Lite development files
+Summary(pl.UTF-8):     Pliki dla programistów używających PC/SC Lite
+Group:         Development/Libraries
+Requires:      %{name}-libs = %{version}-%{release}
+
+%description devel
+PC/SC Lite development files.
+
+%description devel -l pl.UTF-8
+Pliki dla programistów używających PC/SC Lite.
+
+%package static
+Summary:       Static PC/SC Lite libraries
+Summary(pl.UTF-8):     Biblioteki statyczne PC/SC Lite
+Group:         Development/Libraries
+Requires:      %{name}-devel = %{version}-%{release}
+
+%description static
+Static PC/SC Lite libraries.
+
+%description static -l pl.UTF-8
+Statyczne biblioteki PC/SC Lite.
+
+%package apidocs
+Summary:       PC/SC Lite API documentation
+Summary(pl.UTF-8):     Dokumentacja API biblioteki PC/SC Lite
+Group:         Documentation
+
+%description apidocs
+API and internal documentation for PC/SC Lite library.
+
+%description apidocs -l pl.UTF-8
+Dokumentacja API biblioteki PC/SC Lite.
+
+%prep
+%setup -q
+%patch0 -p1
+%patch1 -p1
+%patch2 -p1
+%patch3 -p1
+
+%build
+%{__libtoolize}
+%{__aclocal} -I m4
+%{__autoconf}
+%{__autoheader}
+%{__automake}
+# auto power down unreliable yet
+CPPFLAGS="%{rpmcppflags} -DDISABLE_ON_DEMAND_POWER_ON"
+%configure \
+       %{!?with_udev:--disable-libudev} \
+       --disable-silent-rules \
+       --enable-ipcdir=/var/run/pcscd \
+       %{?with_polkit:--enable-polkit} \
+       --enable-static \
+       --enable-usbdropdir=%{usbdropdir}
+
+%{__make}
+
+%if %{with apidocs}
+doxygen doc/doxygen.conf
+rm -f doc/api/*.{map,md5}
+%endif
+
+%install
+rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT%{usbdropdir} \
+       $RPM_BUILD_ROOT/etc/{rc.d/init.d,sysconfig,init} \
+       $RPM_BUILD_ROOT%{_sysconfdir}/reader.conf.d \
+       $RPM_BUILD_ROOT/var/run/pcscd \
+       $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version} \
+       $RPM_BUILD_ROOT/usr/lib/tmpfiles.d
+
+%{__make} install \
+       DESTDIR=$RPM_BUILD_ROOT
+
+%{__rm} -r $RPM_BUILD_ROOT%{_docdir}/%{name}
+
+install -p %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/pcscd
+cp -p %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/pcscd
+cp -p %{SOURCE3} $RPM_BUILD_ROOT/etc/init/pcscd.conf
+install %{SOURCE4} $RPM_BUILD_ROOT/usr/lib/tmpfiles.d/%{name}.conf
+
+cp -p doc/example/*.c $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%pretrans
+# upgrade from pcsc-lite < 1.2.9-0.beta7
+if [ -f /etc/reader.conf -a ! -f %{_sysconfdir}/reader.conf.d/reader.conf ]; then
+       install -d -m755 %{_sysconfdir}/reader.conf.d
+       cp -af /etc/reader.conf %{_sysconfdir}/reader.conf.d/reader.conf
+fi
+
+%post
+/sbin/chkconfig --add pcscd
+%service pcscd restart "PC/SC smart card daemon"
+%systemd_post pcscd.service pcscd.socket
+
+%preun
+if [ "$1" = "0" ]; then
+       %service pcscd stop
+       /sbin/chkconfig --del pcscd
+fi
+%systemd_preun pcscd.service pcscd.socket
+
+%postun
+%systemd_reload
+
+%triggerpostun -- pcsc-lite < 1.8.3-1
+%systemd_trigger pcscd.service pcscd.socket
+
+%post  libs -p /sbin/ldconfig
+%postun        libs -p /sbin/ldconfig
+
+%files
+%defattr(644,root,root,755)
+%doc AUTHORS COPYING ChangeLog* DRIVERS HELP NEWS README SECURITY TODO doc/README.{DAEMON,polkit}
+%attr(755,root,root) %{_bindir}/pcsc-spy
+%attr(755,root,root) %{_sbindir}/pcscd
+%dir %{_libdir}/pcsc
+%dir %{_libdir}/pcsc/drivers
+%dir %{_sysconfdir}/reader.conf.d
+%attr(754,root,root) /etc/rc.d/init.d/pcscd
+%config(noreplace) %verify(not md5 mtime size) /etc/init/pcscd.conf
+%attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/pcscd
+%{_mandir}/man1/pcsc-spy.1*
+%{_mandir}/man5/reader.conf.5*
+%{_mandir}/man8/pcscd.8*
+%dir /var/run/pcscd
+%{systemdunitdir}/pcscd.service
+%{systemdunitdir}/pcscd.socket
+/usr/lib/tmpfiles.d/%{name}.conf
+%if %{with polkit}
+%{_datadir}/polkit-1/actions/org.debian.pcsc-lite.policy
+%endif
+
+%files libs
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_libdir}/libpcsclite.so.*.*.*
+%attr(755,root,root) %ghost %{_libdir}/libpcsclite.so.1
+%attr(755,root,root) %{_libdir}/libpcscspy.so.*.*.*
+%attr(755,root,root) %ghost %{_libdir}/libpcscspy.so.0
+
+%files devel
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_libdir}/libpcsclite.so
+%attr(755,root,root) %{_libdir}/libpcscspy.so
+%{_libdir}/libpcsclite.la
+%{_libdir}/libpcscspy.la
+%{_includedir}/PCSC
+%{_pkgconfigdir}/libpcsclite.pc
+%{_examplesdir}/%{name}-%{version}
+
+%files static
+%defattr(644,root,root,755)
+%{_libdir}/libpcsclite.a
+%{_libdir}/libpcscspy.a
+
+%if %{with apidocs}
+%files apidocs
+%defattr(644,root,root,755)
+%doc doc/api/*
+%endif
diff --git a/pcsc-lite.tmpfiles b/pcsc-lite.tmpfiles
new file mode 100644 (file)
index 0000000..57db013
--- /dev/null
@@ -0,0 +1 @@
+d /var/run/pcscd 0755 root root -
diff --git a/pcscd.upstart b/pcscd.upstart
new file mode 100644 (file)
index 0000000..2852802
--- /dev/null
@@ -0,0 +1,24 @@
+description "PC/SC Smartcard daemon"
+
+# Note!  pcscd should be started after pcmcia, and shut down before it
+# for smooth experience with PCMCIA readers.
+
+# Set defaults
+env LOGLEVEL=""
+env PCSCD_OPTIONS=""
+
+respawn
+expect fork
+
+script
+       [ -f /etc/sysconfig/pcscd ] && . /etc/sysconfig/pcscd
+
+       local logopt
+       case "$LOGLEVEL" in
+       debug|info|error|critical)
+               logopt=--$LOGLEVEL
+       ;;
+       esac
+
+       exec /usr/sbin/pcscd $logopt $PCSCD_OPTIONS
+end script