From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15471 invoked from network); 16 Dec 2005 18:39:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 Dec 2005 18:39:38 -0000 Received: (qmail 95877 invoked from network); 16 Dec 2005 18:39:32 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Dec 2005 18:39:32 -0000 Received: (qmail 8307 invoked by alias); 16 Dec 2005 18:39:29 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22091 Received: (qmail 8298 invoked from network); 16 Dec 2005 18:39:29 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 16 Dec 2005 18:39:29 -0000 Received: (qmail 95608 invoked from network); 16 Dec 2005 18:39:29 -0000 Received: from dsl3-63-249-88-2.cruzio.com (HELO dot.blorf.net) (63.249.88.2) by a.mx.sunsite.dk with SMTP; 16 Dec 2005 18:39:26 -0000 Received: by dot.blorf.net (Postfix, from userid 1000) id 2421A3E69; Fri, 16 Dec 2005 10:39:24 -0800 (PST) Date: Fri, 16 Dec 2005 10:39:24 -0800 From: Wayne Davison To: Arkadiusz Miskiewicz Cc: zsh-workers@sunsite.dk Subject: Re: [PATCH]: restore permissions and mode on HISTFILE when renaming it Message-ID: <20051216183924.GD2333@dot.blorf.net> References: <200512160942.30494.arekm@pld-linux.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="SUOF0GtieIMvvwua" Content-Disposition: inline In-Reply-To: <200512160942.30494.arekm@pld-linux.org> User-Agent: Mutt/1.5.11 --SUOF0GtieIMvvwua Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Dec 16, 2005 at 09:42:29AM +0100, Arkadiusz Miskiewicz wrote: > rename(".historyz.new", ".historyz") [loses] all permissions and > user/owner of the original .historyz file. I think that having rsync maintain the current permissions and group is a desirable feature. I also like Bart's idea that zsh should refuse to re-write the history file (with a warning) if it is currently owned by some other user. The attached patch does this. (If folks like the idea for the upcoming release, I'll go ahead and commit it.) As for the HISTFILE behavior when using sudo, I have code in my .zshrc that makes sure that root writes out its history into its own history file. You can do this by conditionally redefining HISTFILE based on the current user (among other possibilities). ..wayne.. --SUOF0GtieIMvvwua Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="preserve.patch" --- configure.ac 9 Dec 2005 19:20:02 -0000 1.46 +++ configure.ac 16 Dec 2005 18:29:59 -0000 @@ -1098,7 +1098,7 @@ dnl AC_FUNC_STRFTIME AC_CHECK_FUNCS(strftime difftime gettimeofday \ select poll \ readlink faccessx fchdir ftruncate \ - fstat lstat lchown \ + fstat lstat lchown fchown fchmod \ fseeko ftello \ mkfifo _mktemp mkstemp \ waitpid wait3 \ --- Src/hist.c 4 Nov 2005 16:20:34 -0000 1.61 +++ Src/hist.c 16 Dec 2005 18:29:59 -0000 @@ -2080,8 +2080,25 @@ savehistfile(char *fn, int err, int writ tmpfile = bicat(unmeta(fn), ".new"); if (unlink(tmpfile) < 0 && errno != ENOENT) out = NULL; - else - out = fdopen(open(tmpfile, O_CREAT | O_WRONLY | O_EXCL, 0600), "w"); + else { + struct stat sb; + int old_exists = stat(unmeta(fn), &sb) == 0; + + if (old_exists && sb.st_uid != geteuid()) { + tmpfile = NULL; /* Avoid an error about HISTFILE.new */ + out = NULL; + } else + out = fdopen(open(tmpfile, O_CREAT | O_WRONLY | O_EXCL, 0600), "w"); + +#ifdef HAVE_FCHMOD + if (old_exists && out) { +#ifdef HAVE_FCHOWN + fchown(fileno(out), sb.st_uid, sb.st_gid); +#endif + fchmod(fileno(out), sb.st_mode); + } +#endif + } } if (out) { for (; he && he->histnum <= xcurhist; he = down_histent(he)) { --SUOF0GtieIMvvwua--