]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tpm2-util: create leading dirs for anchor secret
authorLennart Poettering <lennart@poettering.net>
Tue, 16 Dec 2025 11:10:32 +0000 (12:10 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 Dec 2025 13:28:10 +0000 (22:28 +0900)
Fixes #40087

src/shared/tpm2-util.c

index f04ec6429ec39bebe41a74c6ea1faf627d16aaaf..e089cfbc5eaffaa7ecfe997bdc3bb4d1c1da5df8 100644 (file)
@@ -7,6 +7,7 @@
 #include "ansi-color.h"
 #include "bitfield.h"
 #include "boot-entry.h"
+#include "chase.h"
 #include "constants.h"
 #include "creds-util.h"
 #include "cryptsetup-util.h"
@@ -6947,9 +6948,10 @@ static int tpm2_nvpcr_write_anchor_secret(
 
         /* Writes the encrypted credential of the anchor secret to directory 'dir' and file 'fname' */
 
-        _cleanup_close_ int dfd = open_mkdir(dir, O_CLOEXEC, 0755);
-        if (dfd < 0)
-                return log_error_errno(dfd, "Failed to create '%s' directory: %m", dir);
+        _cleanup_close_ int dfd = -EBADF;
+        r = chase(dir, /* root= */ NULL, CHASE_MKDIR_0755|CHASE_MUST_BE_DIRECTORY, /* ret_path= */ NULL, &dfd);
+        if (r < 0)
+                return log_error_errno(r, "Failed to create '%s' directory: %m", dir);
 
         _cleanup_free_ char *joined = path_join(dir, fname);
         if (!joined)