find-esp: return pinned fd to ESP/XBOOTLDR
The reworks the ESP/XBOOTLDR logic to pin the ESP/XBOOTLDR via an fd,
and return that as optional return parameter.
So far we only pinned the parent dir of the ESP/XBOOTLDR, which was
useful when verifying that ESP/XBOOTLDR is actually a mount point by
comparing mount ids. This however became obsolete with
a98a6eb95c. Hence, let's clean this up,
and pin the inode we really care about and return it.
This commit is contained in:
+28
-16
@@ -147,32 +147,44 @@ static int run(int argc, char *argv[]) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to find 'swtpm' binary: %m");
|
||||
|
||||
_cleanup_free_ char *_esp = NULL;
|
||||
const char *esp;
|
||||
if (in_initrd())
|
||||
_cleanup_free_ char *state_dir = NULL;
|
||||
_cleanup_close_ int state_fd = -EBADF;
|
||||
if (in_initrd()) {
|
||||
/* The early ESP support uses only a single mount point, we do not need to search for it. */
|
||||
esp = "/sysefi";
|
||||
else {
|
||||
r = chase("/loader/swtpm",
|
||||
"/sysefi",
|
||||
CHASE_PREFIX_ROOT|CHASE_TRIGGER_AUTOFS|CHASE_PROHIBIT_SYMLINKS|CHASE_MKDIR_0755|CHASE_MUST_BE_DIRECTORY,
|
||||
&state_dir,
|
||||
&state_fd);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to open swtpm state directory in ESP: %m");
|
||||
} else {
|
||||
_cleanup_free_ char *esp_path = NULL;
|
||||
_cleanup_close_ int esp_fd = -EBADF;
|
||||
r = find_esp_and_warn(
|
||||
/* root= */ NULL,
|
||||
/* path= */ NULL,
|
||||
/* unprivileged_mode= */ false,
|
||||
&_esp);
|
||||
&esp_path,
|
||||
&esp_fd);
|
||||
if (r == -ENOKEY) /* This one find_esp_and_warn() doesn't actually log about. */
|
||||
return log_error_errno(r, "No ESP discovered.");
|
||||
if (r < 0)
|
||||
return r;
|
||||
esp = _esp;
|
||||
}
|
||||
|
||||
_cleanup_free_ char *state_dir = NULL;
|
||||
_cleanup_close_ int state_fd = -EBADF;
|
||||
r = chase("/loader/swtpm",
|
||||
esp, CHASE_PREFIX_ROOT|CHASE_TRIGGER_AUTOFS|CHASE_PROHIBIT_SYMLINKS|CHASE_MKDIR_0755|CHASE_MUST_BE_DIRECTORY,
|
||||
&state_dir,
|
||||
&state_fd);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to open swtpm state directory in ESP: %m");
|
||||
_cleanup_free_ char *unprefixed_state_dir = NULL;
|
||||
r = chaseat(esp_fd,
|
||||
"/loader/swtpm",
|
||||
CHASE_TRIGGER_AUTOFS|CHASE_PROHIBIT_SYMLINKS|CHASE_MKDIR_0755|CHASE_MUST_BE_DIRECTORY,
|
||||
&unprefixed_state_dir,
|
||||
&state_fd);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to open swtpm state directory in ESP: %m");
|
||||
|
||||
state_dir = path_join(esp_path, unprefixed_state_dir);
|
||||
if (!state_dir)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
_cleanup_(unlink_and_freep) char *secret = NULL;
|
||||
r = prepare_secret(runtime_dir, &secret);
|
||||
|
||||
Reference in New Issue
Block a user