]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
import-creds: show list of imported credentials during initialization of PID 1
authorLennart Poettering <lennart@poettering.net>
Wed, 28 Jun 2023 20:58:07 +0000 (22:58 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 4 Jul 2023 21:02:31 +0000 (23:02 +0200)
Let's make things easier to debug: provide an overview what has been
passed, during boot.

src/core/import-creds.c

index 8c170d6fe5274e67b249477b4d6be46cdae28e63..fb2e9272bdb43f06c77265e0228f908d0a55006c 100644 (file)
@@ -804,6 +804,62 @@ static int setenv_notify_socket(void) {
         return 1;
 }
 
+static int report_credentials_per_func(const char *title, int (*get_directory_func)(const char **ret)) {
+        _cleanup_free_ DirectoryEntries *de = NULL;
+        _cleanup_close_ int dir_fd = -EBADF;
+        _cleanup_free_ char *ll = NULL;
+        const char *d = NULL;
+        int r, c = 0;
+
+        assert(title);
+        assert(get_directory_func);
+
+        r = get_directory_func(&d);
+        if (r < 0) {
+                if (r == -ENXIO) /* Env var not set */
+                        return 0;
+
+                return log_warning_errno(r, "Failed to determine %s directory: %m", title);
+        }
+
+        dir_fd = open(d, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+        if (dir_fd < 0)
+                return log_warning_errno(errno, "Failed to open credentials directory %s: %m", d);
+
+        r = readdir_all(dir_fd, RECURSE_DIR_SORT|RECURSE_DIR_IGNORE_DOT, &de);
+        if (r < 0)
+                return log_warning_errno(r, "Failed to enumerate credentials directory %s: %m", d);
+
+        FOREACH_ARRAY(entry, de->entries, de->n_entries) {
+                const struct dirent *e = *entry;
+
+                if (!credential_name_valid(e->d_name))
+                        continue;
+
+                if (!strextend_with_separator(&ll, ", ", e->d_name))
+                        return log_oom();
+
+                c++;
+        }
+
+        if (ll)
+                log_info("Received %s: %s", title, ll);
+
+        return c;
+}
+
+static void report_credentials(void) {
+        int p, q;
+
+        p = report_credentials_per_func("regular credentials", get_credentials_dir);
+        q = report_credentials_per_func("untrusted credentials", get_encrypted_credentials_dir);
+
+        log_full(p > 0 || q > 0 ? LOG_INFO : LOG_DEBUG,
+                 "Acquired %i regular credentials, %i untrusted credentials.",
+                 p > 0 ? p : 0,
+                 q > 0 ? q : 0);
+}
+
 int import_credentials(void) {
         const char *received_creds_dir = NULL, *received_encrypted_creds_dir = NULL;
         bool envvar_set = false;
@@ -864,6 +920,8 @@ int import_credentials(void) {
                         r = q;
         }
 
+        report_credentials();
+
         /* Propagate vmm_notify_socket credential → $NOTIFY_SOCKET env var */
         (void) setenv_notify_socket();