assert(ret);
- r = find_xbootldr_and_warn(
- /* root= */ NULL,
- /* path= */ NULL,
- /* unprivileged_mode= */ false,
- &path,
- /* ret_uuid= */ NULL,
- /* ret_devid= */ NULL);
- if (r < 0) {
- if (r != -ENOKEY)
- return log_error_errno(r, "Failed to find XBOOTLDR partition: %m");
-
- r = find_esp_and_warn(
- /* root= */ NULL,
- /* path= */ NULL,
- /* unprivileged_mode= */ false,
- &path,
- /* ret_part= */ NULL,
- /* ret_pstart= */ NULL,
- /* ret_psize= */ NULL,
- /* ret_uuid= */ NULL,
- /* ret_devid= */ NULL);
- if (r < 0) {
- if (r != -ENOKEY)
- return log_error_errno(r, "Failed to find ESP partition: %m");
-
- *ret = NULL;
- return 0; /* not found! */
- }
+ r = get_global_boot_credentials_path(&path);
+ if (r < 0)
+ return r;
+ if (r == 0) {
+ *ret = NULL;
+ return 0; /* not found! */
}
r = sd_id128_get_machine(&machine_id);
if (!filename_is_valid(fn))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Credential name '%s' would not be a valid file name, refusing.", fn);
- joined = path_join(path, "loader/credentials", fn);
+ joined = path_join(path, fn);
if (!joined)
return log_oom();
#include "env-util.h"
#include "fd-util.h"
#include "fileio.h"
+#include "find-esp.h"
#include "format-util.h"
#include "fs-util.h"
#include "io-util.h"
return 0;
}
+int get_global_boot_credentials_path(char **ret) {
+ _cleanup_free_ char *path = NULL;
+ int r;
+
+ assert(ret);
+
+ /* Determines where to put global boot credentials in. Returns the path to the "/loader/credentials/"
+ * directory below the XBOOTLDR or ESP partition. Any credentials placed in this directory can be
+ * picked up later in the initrd. */
+
+ r = find_xbootldr_and_warn(
+ /* root= */ NULL,
+ /* path= */ NULL,
+ /* unprivileged_mode= */ false,
+ &path,
+ /* ret_uuid= */ NULL,
+ /* ret_devid= */ NULL);
+ if (r < 0) {
+ if (r != -ENOKEY)
+ return log_error_errno(r, "Failed to find XBOOTLDR partition: %m");
+
+ r = find_esp_and_warn(
+ /* root= */ NULL,
+ /* path= */ NULL,
+ /* unprivileged_mode= */ false,
+ &path,
+ /* ret_part= */ NULL,
+ /* ret_pstart= */ NULL,
+ /* ret_psize= */ NULL,
+ /* ret_uuid= */ NULL,
+ /* ret_devid= */ NULL);
+ if (r < 0) {
+ if (r != -ENOKEY)
+ return log_error_errno(r, "Failed to find ESP partition: %m");
+
+ *ret = NULL;
+ return 0; /* not found! */
+ }
+ }
+
+ _cleanup_free_ char *joined = path_join(path, "loader/credentials");
+ if (!joined)
+ return log_oom();
+
+ log_debug("Determined global boot credentials path as: %s", joined);
+
+ *ret = TAKE_PTR(joined);
+ return 1; /* found! */
+}
+
static int pick_up_credential_one(
int credential_dir_fd,
const char *credential_name,
int ipc_encrypt_credential(const char *name, usec_t timestamp, usec_t not_after, uid_t uid, const struct iovec *input, CredentialFlags flags, struct iovec *ret);
int ipc_decrypt_credential(const char *validate_name, usec_t validate_timestamp, uid_t uid, const struct iovec *input, CredentialFlags flags, struct iovec *ret);
+int get_global_boot_credentials_path(char **ret);
+
typedef struct PickUpCredential {
const char *credential_prefix;
const char *target_dir;