journal: automatically evolve FSS key even when nothing is logged
authorLennart Poettering <lennart@poettering.net>
Mon, 20 Aug 2012 23:29:17 +0000 (01:29 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Aug 2012 23:29:17 +0000 (01:29 +0200)
src/journal/journal-authenticate.c
src/journal/journal-authenticate.h
src/journal/journal-verify.c
src/journal/journalctl.c
src/journal/journald.c

index 4354810..fd81797 100644 (file)
@@ -211,6 +211,9 @@ int journal_file_maybe_append_tag(JournalFile *f, uint64_t realtime) {
         if (!f->seal)
                 return 0;
 
+        if (realtime <= 0)
+                realtime = now(CLOCK_MONOTONIC);
+
         r = journal_file_fsprg_need_evolve(f, realtime);
         if (r <= 0)
                 return 0;
@@ -517,3 +520,19 @@ int journal_file_parse_verification_key(JournalFile *f, const char *key) {
 
         return 0;
 }
+
+bool journal_file_next_evolve_usec(JournalFile *f, usec_t *u) {
+        uint64_t epoch;
+
+        assert(f);
+        assert(u);
+
+        if (!f->seal)
+                return false;
+
+        epoch = FSPRG_GetEpoch(f->fsprg_state);
+
+        *u = (usec_t) (f->fss_start_usec + f->fss_interval_usec * epoch + f->fss_interval_usec);
+
+        return true;
+}
index 447c7b4..3586464 100644 (file)
@@ -40,3 +40,5 @@ int journal_file_parse_verification_key(JournalFile *f, const char *key);
 
 int journal_file_fsprg_evolve(JournalFile *f, uint64_t realtime);
 int journal_file_fsprg_seek(JournalFile *f, uint64_t epoch);
+
+bool journal_file_next_evolve_usec(JournalFile *f, usec_t *u);
index 29a9229..8604b6e 100644 (file)
 #include "compress.h"
 #include "fsprg.h"
 
-/* FIXME:
- *
- * - evolve key even if nothing happened in regular intervals
- *
- * - check with sparse
- *
- * */
-
 static int journal_file_object_verify(JournalFile *f, Object *o) {
         uint64_t i;
 
index 1dee74a..0bbf4a0 100644 (file)
@@ -233,6 +233,7 @@ static int parse_argv(int argc, char *argv[]) {
                 case ARG_VERIFY_KEY:
                         arg_action = ACTION_VERIFY;
                         arg_verify_key = optarg;
+                        arg_local = true;
                         break;
 
                 case ARG_INTERVAL:
index 7b3b647..f2dd405 100644 (file)
@@ -48,6 +48,7 @@
 #include "journal-rate-limit.h"
 #include "journal-internal.h"
 #include "journal-vacuum.h"
+#include "journal-authenticate.h"
 #include "conf-parser.h"
 #include "journald.h"
 #include "virt.h"
@@ -2969,8 +2970,26 @@ int main(int argc, char *argv[]) {
 
         for (;;) {
                 struct epoll_event event;
+                int t;
 
-                r = epoll_wait(server.epoll_fd, &event, 1, -1);
+#ifdef HAVE_GCRYPT
+                usec_t u;
+
+                if (server.system_journal &&
+                    journal_file_next_evolve_usec(server.system_journal, &u)) {
+                        usec_t n;
+
+                        n = now(CLOCK_MONOTONIC);
+
+                        if (n >= u)
+                                t = 0;
+                        else
+                                t = (int) ((u - n + USEC_PER_MSEC - 1) / USEC_PER_MSEC);
+                } else
+#endif
+                        t = -1;
+
+                r = epoll_wait(server.epoll_fd, &event, 1, t);
                 if (r < 0) {
 
                         if (errno == EINTR)
@@ -2979,14 +2998,20 @@ int main(int argc, char *argv[]) {
                         log_error("epoll_wait() failed: %m");
                         r = -errno;
                         goto finish;
-                } else if (r == 0)
-                        break;
+                }
 
-                r = process_event(&server, &event);
-                if (r < 0)
-                        goto finish;
-                else if (r == 0)
-                        break;
+                if (r > 0) {
+                        r = process_event(&server, &event);
+                        if (r < 0)
+                                goto finish;
+                        else if (r == 0)
+                                break;
+                }
+
+#ifdef HAVE_GCRYPT
+                if (server.system_journal)
+                        journal_file_maybe_append_tag(server.system_journal, 0);
+#endif
         }
 
         log_debug("systemd-journald stopped as pid %lu", (unsigned long) getpid());