From 4c69c3a259ab39100f1453443c8a7679f5080d4a Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Sat, 30 Jan 2010 16:48:51 +0000 Subject: [PATCH] debian/update-reader.conf: add a SHA1 on the first line of the configuration file to detect manual edition. Closes: #565896 "pcscd: overwrites changes in configuration files" urgency=medium because of RC bug. --- debian/changelog | 9 +++++++++ debian/update-reader.conf | 41 +++++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index a67e148..7595f4a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +pcsc-lite (1.5.5-2) unstable; urgency=medium + + * debian/update-reader.conf: add a SHA1 on the first line of the + configuration file to detect manual edition. Closes: #565896 "pcscd: + overwrites changes in configuration files" + urgency=medium because of RC bug. + + -- Ludovic Rousseau Sat, 30 Jan 2010 17:40:44 +0100 + pcsc-lite (1.5.5-1) unstable; urgency=low * New upstream release diff --git a/debian/update-reader.conf b/debian/update-reader.conf index 80fe52c..abccf85 100644 --- a/debian/update-reader.conf +++ b/debian/update-reader.conf @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash # # This is the update-reader.conf script for Debian GNU/Linux. # Written by Ludovic Rousseau @@ -27,24 +27,44 @@ CFGFILE=/etc/reader.conf TMPFILE=`mktemp /tmp/reader.conf.XXXXXX` HEADER="### This file is automatically generated by update-reader.conf" +trap "rm -f $TMPFILE; exit" INT TERM EXIT set -e # Reset the sorting order since we depend on it LC_COLLATE=C export LC_COLLATE +needforce=0 if [ -f "$CFGFILE" ]; then - if ! sed -ne 1p "$CFGFILE" | grep -q "^$HEADER" ; then - echo "Error: the current $CFGFILE is not automatically generated." - if [ "$1" != "force" ]; then - echo "Use \"update-reader.conf force\" to force (re)generation." - exit 1 + FIRSTLINE=$(head -1 "$CFGFILE") + if [ "$FIRSTLINE" != "$HEADER" ]; then + #echo "new format or manual" + sha=$(echo "$FIRSTLINE" | cut -f2 -d' ') + #echo $sha + if [ ${#sha} -ne 40 ]; then + echo "Error: file $CFGFILE is not automatically generated." + needforce=1 else - echo "force specified, (re)generating file anyway." + sha2=$(tail --lines=+2 "$CFGFILE" | sha1sum | cut -f1 -d' ') + #echo $sha2 + if [ $sha != $sha2 ]; then + echo "Error: file $CFGFILE was manually edited." + needforce=1 + fi fi fi fi +if [ "$1" = "force" ]; then + echo "force specified, (re)generating file anyway." + needforce=0 +fi + +if [ $needforce -eq 1 ]; then + echo "Use \"update-reader.conf force\" to force (re)generation." + exit 1 +fi + if [ 0 -ne "`id -u`" ]; then echo "You have to be root to run $0" exit 2 @@ -54,11 +74,10 @@ if [ -e "$CFGFILE" ]; then cp -f "$CFGFILE" "${CFGFILE}.old" fi -echo "$HEADER" > "$TMPFILE" - for cfg in /etc/reader.conf.d/* ; do if ! echo "$cfg" | grep -q '\(\.dpkg-[a-z]*\|~\)$' ; then echo "### update-reader.conf: start processing $cfg" >> "$TMPFILE" + echo >> "$TMPFILE" if [ -x "$cfg" ]; then "$cfg" >> "$TMPFILE" else @@ -70,7 +89,9 @@ for cfg in /etc/reader.conf.d/* ; do fi done -cp "$TMPFILE" "$CFGFILE" +echo -n "#SHA1 " > "$CFGFILE" +sha1sum "$TMPFILE" >> "$CFGFILE" +cat "$TMPFILE" >> "$CFGFILE" chmod 644 "$CFGFILE" rm -f "$TMPFILE"