]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkfs-util: Use actual UID/GID in protofile instead of root
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 26 Oct 2023 14:46:16 +0000 (16:46 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 26 Oct 2023 18:10:31 +0000 (19:10 +0100)
src/shared/mkfs-util.c

index e8356de2b7434d3c7c92eb463f9bc06b0c773921..6ea080869f427043ec64f4244e62b871c7b12b17 100644 (file)
@@ -222,12 +222,13 @@ static int protofile_print_item(
                 data->has_filename_with_spaces = true;
         }
 
-        fprintf(data->file, "%s %c%c%c%03o 0 0 ",
+        fprintf(data->file, "%s %c%c%c%03o "UID_FMT" "GID_FMT" ",
                 copy ?: de->d_name,
                 type,
                 sx->stx_mode & S_ISUID ? 'u' : '-',
                 sx->stx_mode & S_ISGID ? 'g' : '-',
-                (unsigned) (sx->stx_mode & 0777));
+                (unsigned) (sx->stx_mode & 0777),
+                sx->stx_uid, sx->stx_gid);
 
         if (S_ISREG(sx->stx_mode)) {
                 _cleanup_free_ char *p = NULL;
@@ -300,7 +301,8 @@ static int make_protofile(const char *root, char **ret_path, bool *ret_has_filen
               "0 0\n"
               "d--755 0 0\n", f);
 
-        r = recurse_dir_at(AT_FDCWD, root, STATX_TYPE|STATX_MODE, UINT_MAX, RECURSE_DIR_SORT, protofile_print_item, &data);
+        r = recurse_dir_at(AT_FDCWD, root, STATX_TYPE|STATX_MODE|STATX_UID|STATX_GID, UINT_MAX,
+                           RECURSE_DIR_SORT, protofile_print_item, &data);
         if (r < 0)
                 return log_error_errno(r, "Failed to recurse through %s: %m", root);