From owner-freebsd-bugs@FreeBSD.ORG Mon Apr 27 06:40:02 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB9F01065670; Mon, 27 Apr 2009 06:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B79C08FC0C; Mon, 27 Apr 2009 06:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n3R6e1er008408; Mon, 27 Apr 2009 06:40:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n3R6e1vu008407; Mon, 27 Apr 2009 06:40:01 GMT (envelope-from gnats) Resent-Date: Mon, 27 Apr 2009 06:40:01 GMT Resent-Message-Id: <200904270640.n3R6e1vu008407@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@freebsd.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Cc: dougb@freebsd.org Resent-Reply-To: FreeBSD-gnats-submit@freebsd.org, Eygene Ryabinkin Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 385A61065672 for ; Mon, 27 Apr 2009 06:38:17 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45]) by mx1.freebsd.org (Postfix) with ESMTP id D8E038FC13 for ; Mon, 27 Apr 2009 06:38:16 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from shadow.localdomain (cdma-92-36-31-186.msk.skylink.ru [92.36.31.186]) by 0.mx.codelabs.ru with esmtps (TLSv1:CAMELLIA256-SHA:256) id 1LyKTl-00085p-TF for FreeBSD-gnats-submit@freebsd.org; Mon, 27 Apr 2009 10:38:15 +0400 Message-Id: <20090427063800.6D7E31711F@shadow.localdomain> Date: Mon, 27 Apr 2009 10:38:00 +0400 (MSD) From: Eygene Ryabinkin To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 X-GNATS-Notify: dougb@freebsd.org Cc: Subject: bin/134038: [patch] usr.sbin/mergemaster: preserve mode/ownership for existing files X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Eygene Ryabinkin List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Apr 2009 06:40:02 -0000 >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 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 --- 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: