aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2015-07-02 17:30:59 +0000
committerRenato Botelho <garga@FreeBSD.org>2015-07-02 17:30:59 +0000
commitd32a66b2a22df44ec11073b9d7b7cf9c130511cb (patch)
tree117a7f93582c746c2d9f1203b60edb19ede05ae6 /lib
parentd2676f552ed4a98882a6f96a528dea48eee6999e (diff)
Notes
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/gr_util.c22
-rw-r--r--lib/libutil/pw_util.33
-rw-r--r--lib/libutil/pw_util.c2
3 files changed, 23 insertions, 4 deletions
diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c
index b0b0b36f0818..93b3eb2f92fc 100644
--- a/lib/libutil/gr_util.c
+++ b/lib/libutil/gr_util.c
@@ -141,7 +141,7 @@ gr_tmp(int mfd)
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkstemp(tempname)) == -1)
+ if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
@@ -318,10 +318,28 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr)
int
gr_mkdb(void)
{
+ int fd;
+
if (chmod(tempname, 0644) != 0)
return (-1);
- return (rename(tempname, group_file));
+ if (rename(tempname, group_file) != 0)
+ return (-1);
+
+ /*
+ * Make sure new group file is safe on disk. To improve performance we
+ * will call fsync() to the directory where file lies
+ */
+ if ((fd = open(group_dir, O_RDONLY|O_DIRECTORY)) == -1)
+ return (-1);
+
+ if (fsync(fd) != 0) {
+ close(fd);
+ return (-1);
+ }
+
+ close(fd);
+ return(0);
}
/*
diff --git a/lib/libutil/pw_util.3 b/lib/libutil/pw_util.3
index 706368fbffed..b558916c82d5 100644
--- a/lib/libutil/pw_util.3
+++ b/lib/libutil/pw_util.3
@@ -233,7 +233,8 @@ function returns 0 in case of success and -1 in case of failure.
The
.Fn pw_lock
function locks the master password file.
-It returns 0 in case of success and -1 in case of failure.
+It returns a file descriptor to master password file in case of success
+and -1 in case of failure.
.Pp
The
.Fn pw_scan
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index befd1fb02d70..af749d5240de 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -226,7 +226,7 @@ pw_tmp(int mfd)
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkstemp(tempname)) == -1)
+ if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)