The following commit has been merged in the master branch:
commit 8264aa556d52235157fb0c705ab8535a8d6fdd4a
Author: Raphaël Hertzog <[email protected]>
Date:   Fri Jul 26 00:17:36 2013 +0200

    dpkg-maintscript-helper: ensures file ownership before acting
    
    Fix mv_conffile/rm_confffile to not do anything when the conffile is no
    longer owned by the current (or named) package.
    
    Closes: #716948
    
    Based-on-patch-by: Steve Langasek <[email protected]>

diff --git a/debian/changelog b/debian/changelog
index dd60733..5588f9b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -134,6 +134,11 @@ dpkg (1.17.0) UNRELEASED; urgency=low
   * Remove temporary file on error during «dpkg-divert --rename».
   * Fix value caching in Dpkg::Arch by not shadowing the variables.
 
+  [ Raphaël Hertzog ]
+  * Fix dpkg-maintscript-helper rm_conffile and mv_conffile to do nothing
+    when the conffile is no longer owned by the current (or named) package.
+    Thanks to Steve Langasek for the patch. Closes: #716948
+
   [ Updated programs translations ]
   * Fix typo in Spanish translation of update-alternatives.
     Thanks to Javier Fernandez-Sanguino <[email protected]>. Closes: #713020
diff --git a/scripts/dpkg-maintscript-helper.sh 
b/scripts/dpkg-maintscript-helper.sh
index 6e2252e..588019b 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -61,7 +61,7 @@ rm_conffile() {
        postinst)
                if [ "$1" = "configure" ] && [ -n "$2" ] &&
                   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
-                       finish_rm_conffile $CONFFILE
+                       finish_rm_conffile "$CONFFILE"
                fi
                ;;
        postrm)
@@ -72,7 +72,7 @@ rm_conffile() {
                if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
                   [ -n "$2" ] &&
                   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
-                       abort_rm_conffile "$CONFFILE"
+                       abort_rm_conffile "$CONFFILE" "$PACKAGE"
                fi
                ;;
        *)
@@ -86,6 +86,7 @@ prepare_rm_conffile() {
        local PACKAGE="$2"
 
        [ -e "$CONFFILE" ] || return 0
+       ensure_package_owns_conffile "$PACKAGE" "$CONFFILE" || return 0
 
        local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')"
        local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PACKAGE | \
@@ -114,6 +115,9 @@ finish_rm_conffile() {
 
 abort_rm_conffile() {
        local CONFFILE="$1"
+       local PACKAGE="$2"
+
+       ensure_package_owns_conffile "$PACKAGE" "$CONFFILE" || return 0
 
        if [ -e "$CONFFILE.dpkg-remove" ]; then
                echo "Reinstalling $CONFFILE that was moved away"
@@ -164,14 +168,14 @@ mv_conffile() {
        postinst)
                if [ "$1" = "configure" ] && [ -n "$2" ] &&
                   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
-                       finish_mv_conffile "$OLDCONFFILE" "$NEWCONFFILE"
+                       finish_mv_conffile "$OLDCONFFILE" "$NEWCONFFILE" 
"$PACKAGE"
                fi
                ;;
        postrm)
                if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
                   [ -n "$2" ] &&
                   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
-                       abort_mv_conffile "$OLDCONFFILE"
+                       abort_mv_conffile "$OLDCONFFILE" "$PACKAGE"
                fi
                ;;
        *)
@@ -186,6 +190,8 @@ prepare_mv_conffile() {
 
        [ -e "$CONFFILE" ] || return 0
 
+       ensure_package_owns_conffile "$PACKAGE" "$CONFFILE" || return 0
+
        local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')"
        local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PACKAGE | \
                sed -n -e "\' $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
@@ -197,10 +203,12 @@ prepare_mv_conffile() {
 finish_mv_conffile() {
        local OLDCONFFILE="$1"
        local NEWCONFFILE="$2"
+       local PACKAGE="$3"
 
        rm -f $OLDCONFFILE.dpkg-remove
 
        [ -e "$OLDCONFFILE" ] || return 0
+       ensure_package_owns_conffile "$PACKAGE" "$OLDCONFFILE" || return 0
 
        echo "Preserving user changes to $NEWCONFFILE (renamed from 
$OLDCONFFILE)..."
        mv -f "$NEWCONFFILE" "$NEWCONFFILE.dpkg-new"
@@ -209,6 +217,9 @@ finish_mv_conffile() {
 
 abort_mv_conffile() {
        local CONFFILE="$1"
+       local PACKAGE="$2"
+
+       ensure_package_owns_conffile "$PACKAGE" "$CONFFILE" || return 0
 
        if [ -e "$CONFFILE.dpkg-remove" ]; then
                echo "Reinstalling $CONFFILE that was moved away"
@@ -217,6 +228,18 @@ abort_mv_conffile() {
 }
 
 # Common functions
+ensure_package_owns_conffile() {
+       local PACKAGE="$1"
+       local CONFFILE="$2"
+
+       if ! dpkg-query -L "$PACKAGE" | grep -q -x "$CONFFILE"; then
+               debug "Conffile '$CONFFILE' not owned by package " \
+                     "'$PACKAGE', skipping $command"
+               return 1
+       fi
+       return 0
+}
+
 debug() {
        if [ -n "$DPKG_DEBUG" ]; then
                echo "DEBUG: $PROGNAME: $*" >&2

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to