]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r285050, r285053, r285059:
authorgarga <garga@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Mon, 6 Jul 2015 13:01:01 +0000 (13:01 +0000)
committergarga <garga@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Mon, 6 Jul 2015 13:01:01 +0000 (13:01 +0000)
commit9b36054203d855b2028d3e3326ea87aa52eb605a
tree405345f80080e535bfc241ee0b84241f929bdfc2
parentbbc3900da4a9ff7cde2124d9ae47d85b0e664594
MFC r285050, r285053, r285059:

When passwd or group information is changed (by pw, vipw, chpass, ...)
temporary file is created and then a rename() call move it to official file.
This operation didn't have any check to make sure data was written to disk
and if a power cycle happens system could end up with a 0 length passwd
or group database.

There is a pfSense bug with more information about it:

https://redmine.pfsense.org/issues/4523

The following changes were made to protect passwd and group operations:

* lib/libutil/gr_util.c:
 - Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file
 - After rename(), fsync() call on directory for faster result

* lib/libutil/pw_util.c
 - Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file

* usr.sbin/pwd_mkdb/pwd_mkdb.c
 - Added O_SYNC flag on dbopen() calls
 - After rename(), fsync() call on directory for faster result

* lib/libutil/pw_util.3
 - pw_lock() returns a file descriptor to master password file on success

Differential Revision: https://reviews.freebsd.org/D2978
Approved by: re (kib), bapt (implicit agreed)
Sponsored by: Netgate

git-svn-id: svn://svn.freebsd.org/base/stable/10@285205 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
lib/libutil/gr_util.c
lib/libutil/pw_util.3
lib/libutil/pw_util.c
usr.sbin/pwd_mkdb/pwd_mkdb.c