zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Arkadiusz Miskiewicz <arekm@pld-linux.org>
Cc: zsh-workers@sunsite.dk
Subject: Re: [PATCH]: restore permissions and mode on HISTFILE when renaming it
Date: Fri, 16 Dec 2005 10:39:24 -0800	[thread overview]
Message-ID: <20051216183924.GD2333@dot.blorf.net> (raw)
In-Reply-To: <200512160942.30494.arekm@pld-linux.org>

[-- Attachment #1: Type: text/plain, Size: 795 bytes --]

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..

[-- Attachment #2: preserve.patch --]
[-- Type: text/plain, Size: 1312 bytes --]

--- 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)) {

  parent reply	other threads:[~2005-12-16 18:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-16  8:42 Arkadiusz Miskiewicz
2005-12-16 15:48 ` Bart Schaefer
2005-12-16 18:39 ` Wayne Davison [this message]
2005-12-19 11:56   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051216183924.GD2333@dot.blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=arekm@pld-linux.org \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).