bin/134038: [patch] usr.sbin/mergemaster: preserve mode/ownership for existing files

Eygene Ryabinkin rea-fbsd at codelabs.ru
Mon Apr 27 06:40:02 UTC 2009


>Number:         134038
>Category:       bin
>Synopsis:       [patch] usr.sbin/mergemaster: preserve mode/ownership for existing files
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 27 06:40:01 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Eygene Ryabinkin
>Release:        FreeBSD 7.2-PRERELEASE amd64
>Organization:
Code Labs
>Environment:

System: FreeBSD 7.2-PRERELEASE amd64

>Description:

Currently mergemaster sets default permissions and ownership for all
merged and installed files.  This could choke the system if
administrator had set non-default ownership and/or values and some parts
of the system rely on that settings.

>How-To-Repeat:

Take some file, for example /etc/defaults/rc.conf, modify it, set
non-default permissions (!= 444) and ownership (!= root:wheel), run
mergemaster and try to install/merge the file.  Check
permissions/ownership when mergemaster will finish: they will be reset
to defaults.

>Fix:

The following patch will fix the thing.

--- preserve-ownership-mode-for-merged-and-installed-files.diff begins here ---
>From 2f23988faaf4d9d789a88df961a0d50241a97275 Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea-fbsd at codelabs.ru>
Date: Sun, 26 Apr 2009 22:50:22 +0400

It is good to respect administrator's opinion on the ownership and mode
for various system files.  Currently merge and install operations reset
the mode and ownership, but this was fixed by this commit.

Signed-off-by: Eygene Ryabinkin <rea-fbsd at codelabs.ru>
---
 usr.sbin/mergemaster/mergemaster.sh |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/mergemaster/mergemaster.sh b/usr.sbin/mergemaster/mergemaster.sh
index e444996..0b74301 100755
--- a/usr.sbin/mergemaster/mergemaster.sh
+++ b/usr.sbin/mergemaster/mergemaster.sh
@@ -768,6 +768,11 @@ install_error () {
   exit 1
 }
 
+# Arguments:
+# - file mode;
+# - source file;
+# - destination directory;
+# - flags for install (can be empty).
 do_install_and_rm () {
   case "${PRESERVE_FILES}" in
   [Yy][Ee][Ss])
@@ -779,7 +784,7 @@ do_install_and_rm () {
   esac
 
   if [ ! -d "${3}/${2##*/}" ]; then
-    if install -m ${1} ${2} ${3}; then
+    if install -m ${1} ${4} ${2} ${3}; then
       unlink ${2}
     else
       install_error ${2} ${3}
@@ -813,7 +818,15 @@ mm_install () {
     install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}"
   fi
 
-  FILE_MODE=`find_mode "${1}"`
+  # Don't reset ownership and permissions for existing files:
+  # administrator may have reasons to set them to non-default
+  # values.
+  if [ -f "${DESTDIR}${COMFILE#.}" ]; then
+    FILE_MODE=`find_mode "${DESTDIR}${COMPFILE#.}"`
+    INSTALL_FLAGS=`stat -f '-o %u -g %g' "${DESTDIR}${COMPFILE#.}"`
+  else
+    FILE_MODE=`find_mode "${1}"`
+  fi
 
   if [ ! -x "${1}" ]; then
     case "${1#.}" in
@@ -882,14 +895,16 @@ mm_install () {
 
     case "${DONT_INSTALL}" in
     '')
-      do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
+      do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" \
+        "${INSTALL_FLAGS}"
       ;;
     *)
       unset DONT_INSTALL
       ;;
     esac
   else	# File matched -x
-    do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}"
+    do_install_and_rm "${FILE_MODE}" "${1}" "${DESTDIR}${INSTALL_DIR}" \
+      "${INSTALL_FLAGS}"
   fi
   return $?
 }
-- 
1.6.2.4
--- preserve-ownership-mode-for-merged-and-installed-files.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list