From 8d5a556f139a260e3b175e1feeb12f919b1e988e Mon Sep 17 00:00:00 2001 From: Ken Smith Date: Mon, 8 Mar 2004 20:31:37 +0000 Subject: Shift file locking to source file instead of temp file. This fixes data buffering issue that corrupts files if two pw(8)'s run at the same time as well as changing pw(8) so it uses the same locking mechanism as PAM, vipw(8), pwd_mkdb(8), etc. PR: bin/23501 Submitted by: Alex Kapranoff Approved by: rwatson (mentor) MFC after: 5 days --- pw/edgroup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'pw/edgroup.c') diff --git a/pw/edgroup.c b/pw/edgroup.c index 40313d2..1cc46b4 100644 --- a/pw/edgroup.c +++ b/pw/edgroup.c @@ -68,7 +68,7 @@ editgroups(char *name, char **groups) strcpy(grouptmp, groupfile); strcat(grouptmp, ".new"); - if ((infd = open(groupfile, O_RDWR | O_CREAT, 0644)) != -1) { + if ((infd = open(groupfile, O_RDWR | O_CREAT | O_EXLOCK, 0644)) != -1) { FILE *infp; if ((infp = fdopen(infd, "r+")) == NULL) @@ -76,7 +76,7 @@ editgroups(char *name, char **groups) else { int outfd; - if ((outfd = open(grouptmp, O_RDWR | O_CREAT | O_TRUNC | O_EXLOCK, 0644)) != -1) { + if ((outfd = open(grouptmp, O_RDWR | O_CREAT | O_TRUNC, 0644)) != -1) { FILE *outfp; if ((outfp = fdopen(outfd, "w+")) == NULL) @@ -207,8 +207,7 @@ editgroups(char *name, char **groups) /* * This is a gross hack, but we may have corrupted the - * original file. Unfortunately, it will lose preservation - * of the inode. + * original file. */ if (fflush(infp) == EOF || ferror(infp)) rc = rename(grouptmp, groupfile) == 0; -- cgit v1.2.3