diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2003-04-09 18:20:51 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2003-04-09 18:20:51 +0000 |
commit | 4c79eaa3b5bf9549a7c803205d16c55dc777d970 (patch) | |
tree | ac5936fcc59c4efd6ce03f10d6a5f5ff8ff67c39 /libutil | |
parent | 5fb7a5cf13a3b79edf8673d5db8bf7e8d5e64030 (diff) | |
download | pw-darwin-4c79eaa3b5bf9549a7c803205d16c55dc777d970.tar.gz pw-darwin-4c79eaa3b5bf9549a7c803205d16c55dc777d970.tar.zst pw-darwin-4c79eaa3b5bf9549a7c803205d16c55dc777d970.zip |
Correctly detect the case where a password entry was changed while we were
preparing to edit it.
PR: bin/50563
Diffstat (limited to 'libutil')
-rw-r--r-- | libutil/pw_util.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libutil/pw_util.c b/libutil/pw_util.c index 053ac56..73d544b 100644 --- a/libutil/pw_util.c +++ b/libutil/pw_util.c @@ -475,8 +475,7 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw) *q = '\0'; fpw = pw_scan(r, PWSCAN_MASTER); *q = t; - if ((old_pw && !pw_equal(fpw, old_pw)) || - (!old_pw && strcmp(fpw->pw_name, pw->pw_name))) { + if (strcmp(fpw->pw_name, pw->pw_name) != 0) { /* nope */ free(fpw); if (write(tfd, p, q - p + 1) != q - p + 1) @@ -484,6 +483,12 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw) ++q; continue; } + if (old_pw && !pw_equal(fpw, old_pw)) { + warnx("entry inconsistent"); + free(fpw); + errno = EINVAL; /* hack */ + goto err; + } free(fpw); /* it is, replace it */ |