user-util: add new wrappers for reading/writing {passwd,shadow,gshadow} database files (#8521)

The API povided by the glibc is too error-prone as one has to deal directly
with errno in order to detect if errors occured.

Suggested by Zbigniew.
This commit is contained in:
Franck Bui
2018-03-21 15:26:02 +01:00
committed by Lennart Poettering
parent ed47df8967
commit 100d5f6ee6
4 changed files with 198 additions and 98 deletions
+5 -4
View File
@@ -20,7 +20,6 @@
#include <fcntl.h>
#include <getopt.h>
#include <shadow.h>
#include <unistd.h>
#ifdef HAVE_CRYPT_H
@@ -586,6 +585,8 @@ static int prompt_root_password(void) {
static int write_root_shadow(const char *path, const struct spwd *p) {
_cleanup_fclose_ FILE *f = NULL;
int r;
assert(path);
assert(p);
@@ -594,9 +595,9 @@ static int write_root_shadow(const char *path, const struct spwd *p) {
if (!f)
return -errno;
errno = 0;
if (putspent(p, f) != 0)
return errno > 0 ? -errno : -EIO;
r = putspent_sane(p, f);
if (r < 0)
return r;
return fflush_sync_and_check(f);
}