Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/pwd_mkdb/pwd_mkdb.c
Context not available. | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <libgen.h> | |||||
#include <limits.h> | #include <limits.h> | ||||
#include <pwd.h> | #include <pwd.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
Context not available. | |||||
clean = FILE_INSECURE; | clean = FILE_INSECURE; | ||||
cp(buf2, buf, PERM_INSECURE); | cp(buf2, buf, PERM_INSECURE); | ||||
dp = dbopen(buf, | dp = dbopen(buf, | ||||
O_RDWR|O_EXCL, PERM_INSECURE, DB_HASH, &openinfo); | O_RDWR|O_EXCL|O_SYNC, PERM_INSECURE, DB_HASH, &openinfo); | ||||
if (dp == NULL) | if (dp == NULL) | ||||
error(buf); | error(buf); | ||||
Context not available. | |||||
clean = FILE_SECURE; | clean = FILE_SECURE; | ||||
cp(sbuf2, sbuf, PERM_SECURE); | cp(sbuf2, sbuf, PERM_SECURE); | ||||
sdp = dbopen(sbuf, | sdp = dbopen(sbuf, | ||||
O_RDWR|O_EXCL, PERM_SECURE, DB_HASH, &openinfo); | O_RDWR|O_EXCL|O_SYNC, PERM_SECURE, DB_HASH, &openinfo); | ||||
if (sdp == NULL) | if (sdp == NULL) | ||||
error(sbuf); | error(sbuf); | ||||
Context not available. | |||||
method = 0; | method = 0; | ||||
} else { | } else { | ||||
dp = dbopen(buf, | dp = dbopen(buf, | ||||
O_RDWR|O_CREAT|O_EXCL, PERM_INSECURE, DB_HASH, &openinfo); | O_RDWR|O_CREAT|O_EXCL|O_SYNC, PERM_INSECURE, DB_HASH, &openinfo); | ||||
if (dp == NULL) | if (dp == NULL) | ||||
error(buf); | error(buf); | ||||
clean = FILE_INSECURE; | clean = FILE_INSECURE; | ||||
sdp = dbopen(sbuf, | sdp = dbopen(sbuf, | ||||
O_RDWR|O_CREAT|O_EXCL, PERM_SECURE, DB_HASH, &openinfo); | O_RDWR|O_CREAT|O_EXCL|O_SYNC, PERM_SECURE, DB_HASH, &openinfo); | ||||
if (sdp == NULL) | if (sdp == NULL) | ||||
error(sbuf); | error(sbuf); | ||||
clean = FILE_SECURE; | clean = FILE_SECURE; | ||||
Context not available. | |||||
mv(char *from, char *to) | mv(char *from, char *to) | ||||
{ | { | ||||
char buf[MAXPATHLEN]; | char buf[MAXPATHLEN]; | ||||
char *to_dir; | |||||
int to_dir_fd = -1; | |||||
if (rename(from, to)) { | /* | ||||
* Make sure file is safe on disk. To improve performance we will call | |||||
* fsync() to the directory where file lies | |||||
*/ | |||||
if (rename(from, to) != 0 || | |||||
(to_dir = dirname(to)) == NULL || | |||||
(to_dir_fd = open(to_dir, O_RDONLY|O_DIRECTORY)) == -1 || | |||||
fsync(to_dir_fd) != 0) { | |||||
int sverrno = errno; | int sverrno = errno; | ||||
(void)snprintf(buf, sizeof(buf), "%s to %s", from, to); | (void)snprintf(buf, sizeof(buf), "%s to %s", from, to); | ||||
errno = sverrno; | errno = sverrno; | ||||
if (to_dir_fd != -1) | |||||
close(to_dir_fd); | |||||
error(buf); | error(buf); | ||||
} | } | ||||
if (to_dir_fd != -1) | |||||
close(to_dir_fd); | |||||
} | } | ||||
void | void | ||||
Context not available. |