summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2021-09-02 11:32:09 +0200
committerSlávek Banko <slavek.banko@axis.cz>2021-09-05 12:35:21 +0200
commitb62ce69302c6b8dad04cab0f9ced879853b08be9 (patch)
tree0461bbbfd4a3bdccc774d518c7951313f8c39cd6
parentb70630a2278865b0d7a42d165cf308da6d063c0e (diff)
downloadsmartcardauth-b62ce693.tar.gz
smartcardauth-b62ce693.zip
Improve processing of multiarch libraries location in scripts.
Initramfs hook instead of a fixed list of libraries, it processes dependent libraries by using copy_exec function. This also ensure the copy of the symlinks and maintaining the original paths by multiarch location. Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit 3eb77b4fcaf2284e9711d6fbe757b4f882cd7c4d)
-rwxr-xr-xusr/share/initramfs-tools/hooks/cryptlukssc108
1 files changed, 68 insertions, 40 deletions
diff --git a/usr/share/initramfs-tools/hooks/cryptlukssc b/usr/share/initramfs-tools/hooks/cryptlukssc
index 577fc96..d92c81e 100755
--- a/usr/share/initramfs-tools/hooks/cryptlukssc
+++ b/usr/share/initramfs-tools/hooks/cryptlukssc
@@ -18,49 +18,84 @@ esac
. /usr/share/initramfs-tools/hook-functions
+# Additional function for copying plugin (library) from multiarch directory.
+# Based on copy_exec.
+copy_plugin() {
+ local src target x
+
+ src="${1}"
+ if [ ${src} = "${src#/}" ]; then
+ for x in /${ARCHDIR} /lib /usr/${ARCHDIR} /usr/lib; do
+ if [ -e $x/$src ]; then
+ src=$(echo $x/$src)
+ break
+ fi
+ done
+ fi
+ target="${2:-$src}"
+
+ copy_exec "${src}" "${target}" || return $(($? - 1))
+}
+
+# Determine multiarch directory
+ARCHDIR=$(ldd $SHELL | grep libc\.so |\
+ sed -e "s|^.*=> \(.*\)/[^/]*$|\1|" -e "s|^/usr||" -e "s|^/||")
+if [ -z "$ARCHDIR" ] && [ -n "$HOSTTYPE" ] && [ -n "$OSTYPE" ]; then
+ ARCHDIR=$HOSTTYPE-$OSTYPE
+fi
+if [ -z "$ARCHDIR" ]; then
+ ARCHDIR=$(uname -i)
+ if [ "$ARCHDIR" = "unknown" ]; then
+ ARCHDIR=$(uname -m)
+ fi
+ if [ "$ARCHDIR" = "ppc64le" ]; then
+ ARCHDIR="powerpc64"
+ fi
+ if [ "$ARCHDIR" = "ppc64el" ]; then
+ ARCHDIR="powerpc64"
+ fi
+ ARCHDIR="*${ARCHDIR}*"
+fi
+
# Hooks for loading smartcard reading software into the initramfs
# Install directories needed by smartcard reading daemon, command, and
# key-script
-for dir in etc/opensc usr/lib/pcsc var/run tmp ; do
- if [ ! -d ${DESTDIR}/${dir} ] ; then mkdir -p ${DESTDIR}/${dir} ; fi
+for dir in etc/opensc lib usr/lib var/run tmp ; do
+ if [ ! -d ${DESTDIR}/${dir} ] ;
+ then
+ mkdir -p ${DESTDIR}/${dir}
+ fi
done
-# Install pcscd daemon, drivers, conf file, and include libgcc as well since
-# pcscd utilizes pthread_cancel
-mkdir -p ${DESTDIR}/lib
+# Install pcscd daemon, drivers, conf file
copy_exec /usr/sbin/pcscd /sbin
-if [ -e /lib/*`uname -i`*/libgcc_s.so.1 ]
-then
- copy_exec /lib/*`uname -i`*/libgcc_s.so.1 /lib
-else
- copy_exec /lib/libgcc_s.so.1 /lib
-fi
-if [ -e /lib/*`uname -i`*/libpcsclite.so.1 ]
-then
- copy_exec /lib/*`uname -i`*/libpcsclite.so.1 /lib
-else
- copy_exec /lib/libpcsclite.so.1 /lib
-fi
-if [ -e /usr/lib/*`uname -i`*/libusb-1.0.so.0 ]
-then
- copy_exec /usr/lib/*`uname -i`*/libusb-1.0.so.0 /usr/lib
-else if [ -e /usr/lib/libusb-1.0.so.0 ]
-then
- copy_exec /usr/lib/libusb-1.0.so.0 /usr/lib
+
+copy_plugin libpcsclite.so.1
+
+find /usr/lib/pcsc ! -type d |
+while read PSCS_FILE; do
+ if [ ! -x ${PSCS_FILE} ] && [ ${PSCS_FILE} = ${PSCS_FILE%.so} ]; then
+ [ -d ${DESTDIR}${PSCS_FILE%/*} ] || \
+ mkdir -p ${DESTDIR}${PSCS_FILE%/*}
+ cp -pL $PSCS_FILE ${DESTDIR}${PSCS_FILE%/*}
+ else
+ copy_exec $PSCS_FILE
+ fi
+done
+
+if [ -d /etc/reader.conf.d ]; then
+ cp -pLR /etc/reader.conf.d ${DESTDIR}/etc/
fi
-cp -r /usr/lib/pcsc ${DESTDIR}/usr/lib
-if [ -e /etc/reader.conf.d ]
-then
- cp -Rp /etc/reader.conf.d ${DESTDIR}/etc/
-else
- cp /etc/reader.conf ${DESTDIR}/etc
+if [ -e /etc/reader.conf ]; then
+ cp -pL /etc/reader.conf ${DESTDIR}/etc/
fi
# Install opensc commands and conf file
-copy_exec /usr/bin/opensc-tool /bin
-copy_exec /usr/bin/pkcs15-crypt /bin
-cp /etc/opensc/opensc.conf ${DESTDIR}/etc/opensc
+copy_exec /usr/bin/opensc-tool /bin/
+copy_exec /usr/bin/pkcs15-crypt /bin/
+copy_exec /usr/bin/pkcs15-tool /bin/
+cp -pL /etc/opensc/opensc.conf ${DESTDIR}/etc/opensc/
# Install other required utilities
copy_exec /bin/grep /bin
@@ -82,11 +117,4 @@ copy_exec /usr/bin/scriptor_standalone /bin
copy_exec /usr/bin/smartauth.sh /bin
# Libraries
-# cp /usr/lib/libltdl.so* ${DESTDIR}/usr/lib
-# cp /lib/libncurses.so.5 ${DESTDIR}/lib
-if [ -e /lib/*`uname -i`*/libncursesw.so.5 ]
-then
- cp /lib/*`uname -i`*/libncursesw.so.5 ${DESTDIR}/lib
-else
- cp /lib/libncursesw.so.5 ${DESTDIR}/lib
-fi
+copy_plugin libncursesw.so.[0-9]