From owner-freebsd-audit@FreeBSD.ORG Wed Jan 12 13:53:39 2005 Return-Path: Delivered-To: freebsd-audit@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F114E16A4CE; Wed, 12 Jan 2005 13:53:38 +0000 (GMT) Received: from heechee.tobez.org (heechee.tobez.org [217.157.39.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id B7C6343D46; Wed, 12 Jan 2005 13:53:37 +0000 (GMT) (envelope-from tobez@tobez.org) Received: by heechee.tobez.org (Postfix, from userid 1001) id 81BD7125465; Wed, 12 Jan 2005 14:53:36 +0100 (CET) Date: Wed, 12 Jan 2005 14:53:36 +0100 From: Anton Berezin To: freebsd-audit@freebsd.org Message-ID: <20050112135336.GC68344@heechee.tobez.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i cc: DougB@FreeBSD.org Subject: [PATCH] review requested, add a feature to mergemaster X-BeenThere: freebsd-audit@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD Security Audit List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jan 2005 13:53:39 -0000 Following the idea by Sune Stjerneby, suggestions from Andrzej Tobola and Phil Regnauld, and a bit of discussion on -current, I would like to request a review of a new mergemaster feature aimed to simplify manual work in some cases. A new option is added: -R cvsroot For files that contain a $FreeBSD$ string, but which does not match the one in the corresponding file in the temporary root, attempt to extract the same version from the FreeBSD CVS repository specified by cvsroot. The mergemaster utility will then compare the CVS version with the installed version using diff(1). If they are identical, mergemaster will assume that the file in the destination directory was not modified and therefore can be safely overwritten by the ver- sion in the temporary root directory. The patch is against fresh HEAD. Index: mergemaster.8 =================================================================== RCS file: /home/ncvs/src/usr.sbin/mergemaster/mergemaster.8,v retrieving revision 1.29 diff -u -r1.29 mergemaster.8 --- mergemaster.8 2 Jul 2004 23:12:48 -0000 1.29 +++ mergemaster.8 12 Jan 2005 13:41:25 -0000 @@ -39,6 +39,7 @@ .Op Fl u Ar N .Op Fl w Ar N .Op Fl D Ar /path +.Op Fl R Ar cvsroot .Sh DESCRIPTION The .Nm @@ -222,6 +223,23 @@ .Pa /path/to/temp/root instead of the default .Pa /var/tmp/temproot . +.It Fl R Ar cvsroot +For files that contain a $FreeBSD$ string, +but which does not match the one in the corresponding file +in the temporary root, +attempt to extract the same version from the +.Fx +CVS repository specified by +.Ar cvsroot. +The +.Nm +utility will then compare the CVS version with the installed version using +.Xr diff 1 . +If they are identical, +.Nm +will assume that the file in the destination directory +was not modified and therefore can be safely +overwritten by the version in the temporary root directory. .It Fl d Add the date and time to the name of the temporary root directory. Index: mergemaster.sh =================================================================== RCS file: /home/ncvs/src/usr.sbin/mergemaster/mergemaster.sh,v retrieving revision 1.51 diff -u -r1.51 mergemaster.sh --- mergemaster.sh 7 Mar 2004 10:10:19 -0000 1.51 +++ mergemaster.sh 12 Jan 2005 13:52:11 -0000 @@ -30,6 +30,7 @@ echo ' -P Preserve files that are overwritten' echo " -m /path/directory Specify location of source to do the make in" echo " -t /path/directory Specify temp root directory" + echo " -R cvsroot Specify cvs repository and instruct to use it" echo " -d Add date and time to directory name (e.g., /var/tmp/temproot.`date +%m%d.%H.%M`)" echo " -u N Specify a numeric umask" echo " -w N Specify a screen width in columns to sdiff" @@ -238,7 +239,7 @@ # Check the command line options # -while getopts ":ascrvhipCPm:t:du:w:D:" COMMAND_LINE_ARGUMENT ; do +while getopts ":ascrvhipCPm:t:R:du:w:D:" COMMAND_LINE_ARGUMENT ; do case "${COMMAND_LINE_ARGUMENT}" in s) STRICT=yes @@ -284,6 +285,9 @@ t) TEMPROOT=${OPTARG} ;; + R) + CVSROOT=${OPTARG} + ;; d) TEMPROOT=${TEMPROOT}.`date +%m%d.%H.%M` ;; @@ -896,21 +900,59 @@ echo " *** Temp ${COMPFILE} and installed are the same, deleting" rm "${COMPFILE}" else - # Ok, the files are different, so show the user where they differ. - # Use user's choice of diff methods; and user's pager if they have one. - # Use more if not. - # Use unified diffs by default. Context diffs give me a headache. :) - # - case "${AUTO_RUN}" in + DO_DIFF_LOOP=yes + + case "${CVSROOT}" in '') - # prompt user to install/delete/merge changes - diff_loop ;; *) - # If this is an auto run, make it official - echo " *** ${COMPFILE} will remain for your consideration" - ;; - esac # Auto run test + CVSFILE=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null | + sed -e "s#.*[$]${CVS_ID_TAG}: \(src/.*\),v .*#\1#" 2>/dev/null` + CVSREV=`grep "[$]${CVS_ID_TAG}:" ${DESTDIR}${COMPFILE#.} 2>/dev/null | + sed -e "s#.*[$]${CVS_ID_TAG}: src/.*,v \([0-9.]*\) .*#\1#" 2>/dev/null` + if [ -n "${CVSFILE}" -a -n "${CVSREV}" ]; then + CVSFILE_N=`echo "${CVSFILE}"|wc -l` + CVSREV_N=`echo "${CVSREV}"|wc -l` + if [ ${CVSFILE_N} -eq 1 -a ${CVSREV_N} -eq 1 ]; then + CVSTEMP=`mktemp -t mmcvs` + cvs -d ${CVSROOT} co -r${CVSREV} -p ${CVSFILE} >${CVSTEMP} 2>/dev/null + if diff -q ${DIFF_OPTIONS} "${DESTDIR}${COMPFILE#.}" "${CVSTEMP}" > \ + /dev/null 2>&1; then + rm -f ${CVSTEMP} + echo '' + echo " *** The installed version of ${COMPFILE} is the same as" + echo " its CVS revision ${CVSREV}, overwriting it" + echo '' + if mm_install "${COMPFILE}"; then + echo " *** ${COMPFILE} installed successfully" + else + echo " *** Problem installing ${COMPFILE}, it will remain to merge by hand" + fi + unset DO_DIFF_LOOP + fi # same file in CVS and in DESTDIR, can overwrite it + rm -f ${CVSTEMP} + fi # CVSFILE and CVSREV can be used + fi # CVSFILE and CVSREV non-empty + ;; + esac # cvs root test + + if [ -n "${DO_DIFF_LOOP}" ]; then + # Ok, the files are different, so show the user where they differ. + # Use user's choice of diff methods; and user's pager if they have one. + # Use more if not. + # Use unified diffs by default. Context diffs give me a headache. :) + # + case "${AUTO_RUN}" in + '') + # prompt user to install/delete/merge changes + diff_loop + ;; + *) + # If this is an auto run, make it official + echo " *** ${COMPFILE} will remain for your consideration" + ;; + esac # Auto run test + fi # Yes, do a diff loop fi # Yes, the files are different fi # Yes, the file still remains to be checked done # This is for the do way up there at the beginning of the comparison Cheers, \Anton. -- The moronity of the universe is a monotonically increasing function. -- Jarkko Hietaniemi