diff options
author | nate <nate@FreeBSD.org> | 1998-07-16 17:18:25 +0000 |
---|---|---|
committer | nate <nate@FreeBSD.org> | 1998-07-16 17:18:25 +0000 |
commit | e5267d9c1bf272fca670235d30ab651aaa2ee00f (patch) | |
tree | 49d76e28cd830cb33069b9e21dc9eefd92d50241 /usr.sbin/pw/fileupd.c | |
parent | 024928fa98398e514a840e1077afa8eedae5268b (diff) | |
download | FreeBSD-src-e5267d9c1bf272fca670235d30ab651aaa2ee00f.zip FreeBSD-src-e5267d9c1bf272fca670235d30ab651aaa2ee00f.tar.gz |
Fix race condition in pw caused by multiple instances of pwd_mkdb being
run at the same time.
Notes:
The fileupdate function is still somewhat broken. Instead of
returning a failure code if it can't modify the original file it
renames the .new file and continues as though nothing is wrong.
This will cause the lock on the original file to be lost and could
lead to a similar race condition. I left that portion of the code
alone since I feel that the maintainer of the code would have a
better concept of how he wants to handle errors in that function
than I do.
PR: bin/6787
Submitted by: Craig Spannring <cts@internetcds.com>
Diffstat (limited to 'usr.sbin/pw/fileupd.c')
-rw-r--r-- | usr.sbin/pw/fileupd.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/usr.sbin/pw/fileupd.c b/usr.sbin/pw/fileupd.c index 3782bf7..fe46480 100644 --- a/usr.sbin/pw/fileupd.c +++ b/usr.sbin/pw/fileupd.c @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] = - "$Id$"; + "$Id: fileupd.c,v 1.5 1997/10/10 06:23:31 charnier Exp $"; #endif /* not lint */ #include <stdio.h> @@ -76,7 +76,7 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const if (pfxlen <= 1) errno = EINVAL; else { - int infd = open(filename, O_RDWR | O_CREAT | O_EXLOCK, fmode); + int infd = open(filename, O_RDWR | O_CREAT, fmode); if (infd != -1) { FILE *infp = fdopen(infd, "r+"); @@ -168,9 +168,20 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const fputs(line, infp); /* + * If there was a problem with copying + * we will just rename 'file.new' + * to 'file'. * This is a gross hack, but we may have * corrupted the original file - * Unfortunately, it will lose the inode. + * Unfortunately, it will lose the inode + * and hence the lock. + * + * The implications of this is that this invocation of pw + * won't have the file locked and concurrent copies + * of pw, vipw etc could clobber what this one is doing. + * + * It should probably just return an error instead + * of going on like nothing is wrong. */ if (fflush(infp) == EOF || ferror(infp)) rc = rename(file, filename) == 0; |