]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Fail early if we're missing privileges to populate a filesystem
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 11 Oct 2022 08:56:16 +0000 (10:56 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 15 Nov 2022 19:23:51 +0000 (20:23 +0100)
src/partition/repart.c

index 0bc50552838aef48b90babc5d530783d72d5aff9..6f4da2c6b5f96695e46196610b49e81c6c9bfa75 100644 (file)
@@ -1594,6 +1594,11 @@ static int partition_read_definition(Partition *p, const char *path, const char
                 return log_syntax(NULL, LOG_ERR, path, 1, SYNTHETIC_ERRNO(EINVAL),
                                   "Minimize= can only be enabled if Format= is set");
 
+        if ((!strv_isempty(p->copy_files) || !strv_isempty(p->make_directories)) && !mkfs_supports_root_option(p->format) && geteuid() != 0)
+                return log_syntax(NULL, LOG_ERR, path, 1, SYNTHETIC_ERRNO(EPERM),
+                                  "Need to be root to populate %s filesystems with CopyFiles=/MakeDirectories=",
+                                  p->format);
+
         if (p->verity != VERITY_OFF || p->encrypt != ENCRYPT_OFF) {
                 r = dlopen_cryptsetup();
                 if (r < 0)