mirror of
https://github.com/zsh-users/zsh
synced 2024-09-29 12:44:46 +00:00
Two changes in the HIST_SAVE_BY_COPY code: (1) preserve the group
and permissions on the history file, and (2) fail if zsh's euid differs from the file's uid (since that would change the history file's owner).
This commit is contained in:
parent
f7037211ad
commit
78168105de
22
Src/hist.c
22
Src/hist.c
|
@ -2080,8 +2080,26 @@ savehistfile(char *fn, int err, int writeflags)
|
|||
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()) {
|
||||
free(tmpfile);
|
||||
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)) {
|
||||
|
|
Loading…
Reference in a new issue