core/import-creds: use FOREACH_ARRAY and RET_GATHER where appropriate

This commit is contained in:
Mike Yuan
2024-07-13 22:58:23 +02:00
parent 77c3e07f93
commit 497b17bbad
+9 -15
View File
@@ -202,8 +202,8 @@ static int import_credentials_boot(void) {
continue;
}
for (size_t i = 0; i < de->n_entries; i++) {
const struct dirent *d = de->entries[i];
FOREACH_ARRAY(i, de->entries, de->n_entries) {
const struct dirent *d = *i;
_cleanup_close_ int cfd = -EBADF, nfd = -EBADF;
_cleanup_free_ char *n = NULL;
const char *e;
@@ -848,7 +848,7 @@ static void report_credentials(void) {
int import_credentials(void) {
const char *received_creds_dir = NULL, *received_encrypted_creds_dir = NULL;
bool envvar_set = false;
int r, q;
int r;
r = get_credentials_dir(&received_creds_dir);
if (r < 0 && r != -ENXIO) /* ENXIO → env var not set yet */
@@ -872,15 +872,12 @@ int import_credentials(void) {
else
r = 0;
if (received_encrypted_creds_dir) {
q = symlink_credential_dir("ENCRYPTED_CREDENTIALS_DIRECTORY", received_encrypted_creds_dir, ENCRYPTED_SYSTEM_CREDENTIALS_DIRECTORY);
if (r >= 0)
r = q;
}
if (received_encrypted_creds_dir)
RET_GATHER(r, symlink_credential_dir("ENCRYPTED_CREDENTIALS_DIRECTORY",
received_encrypted_creds_dir,
ENCRYPTED_SYSTEM_CREDENTIALS_DIRECTORY));
q = merge_credentials_trusted(received_creds_dir);
if (r >= 0)
r = q;
RET_GATHER(r, merge_credentials_trusted(received_creds_dir));
} else {
_cleanup_free_ char *v = NULL;
@@ -899,10 +896,7 @@ int import_credentials(void) {
}
r = import_credentials_boot();
q = import_credentials_trusted();
if (r >= 0)
r = q;
RET_GATHER(r, import_credentials_trusted());
}
report_credentials();