summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/basic/user-util.h4
-rw-r--r--src/firstboot/firstboot.c41
2 files changed, 31 insertions, 14 deletions
diff --git a/src/basic/user-util.h b/src/basic/user-util.h
index c042b67e0a..f7ff35d0e0 100644
--- a/src/basic/user-util.h
+++ b/src/basic/user-util.h
@@ -80,8 +80,8 @@ int take_etc_passwd_lock(const char *root);
#define UID_MAPPED_ROOT ((uid_t) (INT32_MAX-1))
#define GID_MAPPED_ROOT ((gid_t) (INT32_MAX-1))
-#define ETC_PASSWD_LOCK_NAME ".pwd.lock"
-#define ETC_PASSWD_LOCK_PATH "/etc/" ETC_PASSWD_LOCK_NAME
+#define ETC_PASSWD_LOCK_FILENAME ".pwd.lock"
+#define ETC_PASSWD_LOCK_PATH "/etc/" ETC_PASSWD_LOCK_FILENAME
/* The following macros add 1 when converting things, since UID 0 is a valid UID, while the pointer
* NULL is special */
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index c1b739dd4c..ba7e08913f 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -230,16 +230,17 @@ static int prompt_loop(const char *text, char **l, unsigned percentage, bool (*i
}
static int should_configure(int dir_fd, const char *filename) {
- int r;
-
assert(dir_fd >= 0);
assert(filename);
- r = faccessat(dir_fd, filename, F_OK, AT_SYMLINK_NOFOLLOW);
- if (r < 0 && errno != ENOENT)
- return log_error_errno(errno, "Failed to access %s: %m", filename);
+ if (faccessat(dir_fd, filename, F_OK, AT_SYMLINK_NOFOLLOW) < 0) {
+ if (errno != ENOENT)
+ return log_error_errno(errno, "Failed to access %s: %m", filename);
+
+ return true; /* missing */
+ }
- return r < 0 || arg_force;
+ return arg_force; /* exists, but if --force was given we should still configure the file. */
}
static bool locale_is_ok(const char *name) {
@@ -344,7 +345,11 @@ static int process_locale(int rfd) {
if (r <= 0)
return r;
- if (arg_copy_locale && !dir_fd_is_root(rfd)) {
+ r = dir_fd_is_root(rfd);
+ if (r < 0)
+ return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
+
+ if (arg_copy_locale && r == 0) {
r = copy_file_atomic_at(AT_FDCWD, "/etc/locale.conf", pfd, f, 0644, COPY_REFLINK);
if (r != -ENOENT) {
if (r < 0)
@@ -429,7 +434,11 @@ static int process_keymap(int rfd) {
if (r <= 0)
return r;
- if (arg_copy_keymap && !dir_fd_is_root(rfd)) {
+ r = dir_fd_is_root(rfd);
+ if (r < 0)
+ return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
+
+ if (arg_copy_keymap && r == 0) {
r = copy_file_atomic_at(AT_FDCWD, "/etc/vconsole.conf", pfd, f, 0644, COPY_REFLINK);
if (r != -ENOENT) {
if (r < 0)
@@ -517,7 +526,11 @@ static int process_timezone(int rfd) {
if (r <= 0)
return r;
- if (arg_copy_timezone && !dir_fd_is_root(rfd)) {
+ r = dir_fd_is_root(rfd);
+ if (r < 0)
+ return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
+
+ if (arg_copy_timezone && r == 0) {
_cleanup_free_ char *s = NULL;
r = readlink_malloc("/etc/localtime", &s);
@@ -969,11 +982,15 @@ static int process_root_account(int rfd) {
return 0;
}
- r = make_lock_file_at(pfd, ETC_PASSWD_LOCK_NAME, LOCK_EX, &lock);
+ r = make_lock_file_at(pfd, ETC_PASSWD_LOCK_FILENAME, LOCK_EX, &lock);
if (r < 0)
return log_error_errno(r, "Failed to take a lock on /etc/passwd: %m");
- if (arg_copy_root_shell && !dir_fd_is_root(rfd)) {
+ k = dir_fd_is_root(rfd);
+ if (k < 0)
+ return log_error_errno(k, "Failed to check if directory file descriptor is root: %m");
+
+ if (arg_copy_root_shell && k == 0) {
struct passwd *p;
errno = 0;
@@ -990,7 +1007,7 @@ static int process_root_account(int rfd) {
if (r < 0)
return r;
- if (arg_copy_root_password && !dir_fd_is_root(rfd)) {
+ if (arg_copy_root_password && k == 0) {
struct spwd *p;
errno = 0;