chiark / gitweb /
journal: after verification output validated time range
[elogind.git] / src / journal / journal-file.c
index 274f22db170a5e79a3a0e8040e42420e1f4b1b9a..4d7a6ff17d4b1ab6ec8ac018985eb314b48507bd 100644 (file)
@@ -65,7 +65,7 @@ void journal_file_close(JournalFile *f) {
         assert(f);
 
         /* Write the final tag */
-        if (f->authenticate)
+        if (f->seal)
                 journal_file_append_tag(f);
 
         /* Sync everything to disk, before we mark the file offline */
@@ -96,8 +96,8 @@ void journal_file_close(JournalFile *f) {
 #endif
 
 #ifdef HAVE_GCRYPT
-        if (f->fsprg_file)
-                munmap(f->fsprg_file, PAGE_ALIGN(f->fsprg_file_size));
+        if (f->fss_file)
+                munmap(f->fss_file, PAGE_ALIGN(f->fss_file_size));
         else if (f->fsprg_state)
                 free(f->fsprg_state);
 
@@ -125,7 +125,7 @@ static int journal_file_init_header(JournalFile *f, JournalFile *template) {
                 htole32(f->compress ? HEADER_INCOMPATIBLE_COMPRESSED : 0);
 
         h.compatible_flags =
-                htole32(f->authenticate ? HEADER_COMPATIBLE_AUTHENTICATED : 0);
+                htole32(f->seal ? HEADER_COMPATIBLE_SEALED : 0);
 
         r = sd_id128_randomize(&h.file_id);
         if (r < 0)
@@ -195,7 +195,7 @@ static int journal_file_verify_header(JournalFile *f) {
          * compatible flags, too */
         if (f->writable) {
 #ifdef HAVE_GCRYPT
-                if ((le32toh(f->header->compatible_flags) & ~HEADER_COMPATIBLE_AUTHENTICATED) != 0)
+                if ((le32toh(f->header->compatible_flags) & ~HEADER_COMPATIBLE_SEALED) != 0)
                         return -EPROTONOSUPPORT;
 #else
                 if (f->header->compatible_flags != 0)
@@ -207,8 +207,8 @@ static int journal_file_verify_header(JournalFile *f) {
         if (le64toh(f->header->header_size) < HEADER_SIZE_MIN)
                 return -EBADMSG;
 
-        if ((le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_AUTHENTICATED) &&
-                !JOURNAL_HEADER_CONTAINS(f->header, n_tags))
+        if ((le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED) &&
+                !JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
                 return -EBADMSG;
 
         if ((uint64_t) f->last_stat.st_size < (le64toh(f->header->header_size) + le64toh(f->header->arena_size)))
@@ -240,7 +240,7 @@ static int journal_file_verify_header(JournalFile *f) {
         }
 
         f->compress = !!(le32toh(f->header->incompatible_flags) & HEADER_INCOMPATIBLE_COMPRESSED);
-        f->authenticate = !!(le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_AUTHENTICATED);
+        f->seal = !!(le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED);
 
         return 0;
 }
@@ -1885,36 +1885,36 @@ void journal_file_print_header(JournalFile *f) {
                "Arena size: %llu\n"
                "Data Hash Table Size: %llu\n"
                "Field Hash Table Size: %llu\n"
-               "Objects: %llu\n"
-               "Entry Objects: %llu\n"
                "Rotate Suggested: %s\n"
                "Head Sequential Number: %llu\n"
                "Tail Sequential Number: %llu\n"
                "Head Realtime Timestamp: %s\n"
-               "Tail Realtime Timestamp: %s\n",
+               "Tail Realtime Timestamp: %s\n"
+               "Objects: %llu\n"
+               "Entry Objects: %llu\n",
                f->path,
                sd_id128_to_string(f->header->file_id, a),
                sd_id128_to_string(f->header->machine_id, b),
                sd_id128_to_string(f->header->boot_id, c),
                sd_id128_to_string(f->header->seqnum_id, c),
-               f->header->state == STATE_OFFLINE ? "offline" :
-               f->header->state == STATE_ONLINE ? "online" :
-               f->header->state == STATE_ARCHIVED ? "archived" : "unknown",
-               (f->header->compatible_flags & HEADER_COMPATIBLE_AUTHENTICATED) ? " AUTHENTICATED" : "",
-               (f->header->compatible_flags & ~HEADER_COMPATIBLE_AUTHENTICATED) ? " ???" : "",
+               f->header->state == STATE_OFFLINE ? "OFFLINE" :
+               f->header->state == STATE_ONLINE ? "ONLINE" :
+               f->header->state == STATE_ARCHIVED ? "ARCHIVED" : "UNKNOWN",
+               (f->header->compatible_flags & HEADER_COMPATIBLE_SEALED) ? " SEALED" : "",
+               (f->header->compatible_flags & ~HEADER_COMPATIBLE_SEALED) ? " ???" : "",
                (f->header->incompatible_flags & HEADER_INCOMPATIBLE_COMPRESSED) ? " COMPRESSED" : "",
                (f->header->incompatible_flags & ~HEADER_INCOMPATIBLE_COMPRESSED) ? " ???" : "",
                (unsigned long long) le64toh(f->header->header_size),
                (unsigned long long) le64toh(f->header->arena_size),
                (unsigned long long) le64toh(f->header->data_hash_table_size) / sizeof(HashItem),
                (unsigned long long) le64toh(f->header->field_hash_table_size) / sizeof(HashItem),
-               (unsigned long long) le64toh(f->header->n_objects),
-               (unsigned long long) le64toh(f->header->n_entries),
                yes_no(journal_file_rotate_suggested(f)),
                (unsigned long long) le64toh(f->header->head_entry_seqnum),
                (unsigned long long) le64toh(f->header->tail_entry_seqnum),
                format_timestamp(x, sizeof(x), le64toh(f->header->head_entry_realtime)),
-               format_timestamp(y, sizeof(y), le64toh(f->header->tail_entry_realtime)));
+               format_timestamp(y, sizeof(y), le64toh(f->header->tail_entry_realtime)),
+               (unsigned long long) le64toh(f->header->n_objects),
+               (unsigned long long) le64toh(f->header->n_entries));
 
         if (JOURNAL_HEADER_CONTAINS(f->header, n_data))
                 printf("Data Objects: %llu\n"
@@ -1927,6 +1927,13 @@ void journal_file_print_header(JournalFile *f) {
                        "Field Hash Table Fill: %.1f%%\n",
                        (unsigned long long) le64toh(f->header->n_fields),
                        100.0 * (double) le64toh(f->header->n_fields) / ((double) (le64toh(f->header->field_hash_table_size) / sizeof(HashItem))));
+
+        if (JOURNAL_HEADER_CONTAINS(f->header, n_tags))
+                printf("Tag Objects: %llu\n",
+                       (unsigned long long) le64toh(f->header->n_tags));
+        if (JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
+                printf("Entry Array Objects: %llu\n",
+                       (unsigned long long) le64toh(f->header->n_entry_arrays));
 }
 
 int journal_file_open(
@@ -1934,7 +1941,7 @@ int journal_file_open(
                 int flags,
                 mode_t mode,
                 bool compress,
-                bool authenticate,
+                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 JournalFile *template,
@@ -1964,7 +1971,7 @@ int journal_file_open(
         f->prot = prot_from_flags(flags);
         f->writable = (flags & O_ACCMODE) != O_RDONLY;
         f->compress = compress;
-        f->authenticate = authenticate;
+        f->seal = seal;
 
         if (mmap_cache)
                 f->mmap = mmap_cache_ref(mmap_cache);
@@ -2000,10 +2007,10 @@ int journal_file_open(
                 newly_created = true;
 
                 /* Try to load the FSPRG state, and if we can't, then
-                 * just don't do authentication */
-                r = journal_file_load_fsprg(f);
+                 * just don't do sealing */
+                r = journal_file_fss_load(f);
                 if (r < 0)
-                        f->authenticate = false;
+                        f->seal = false;
 
                 r = journal_file_init_header(f, template);
                 if (r < 0)
@@ -2034,7 +2041,7 @@ int journal_file_open(
         }
 
         if (!newly_created && f->writable) {
-                r = journal_file_load_fsprg(f);
+                r = journal_file_fss_load(f);
                 if (r < 0)
                         goto fail;
         }
@@ -2051,7 +2058,7 @@ int journal_file_open(
                         goto fail;
         }
 
-        r = journal_file_setup_hmac(f);
+        r = journal_file_hmac_setup(f);
         if (r < 0)
                 goto fail;
 
@@ -2088,7 +2095,7 @@ fail:
         return r;
 }
 
-int journal_file_rotate(JournalFile **f, bool compress, bool authenticate) {
+int journal_file_rotate(JournalFile **f, bool compress, bool seal) {
         char *p;
         size_t l;
         JournalFile *old_file, *new_file = NULL;
@@ -2127,7 +2134,7 @@ int journal_file_rotate(JournalFile **f, bool compress, bool authenticate) {
 
         old_file->header->state = STATE_ARCHIVED;
 
-        r = journal_file_open(old_file->path, old_file->flags, old_file->mode, compress, authenticate, NULL, old_file->mmap, old_file, &new_file);
+        r = journal_file_open(old_file->path, old_file->flags, old_file->mode, compress, seal, NULL, old_file->mmap, old_file, &new_file);
         journal_file_close(old_file);
 
         *f = new_file;
@@ -2139,7 +2146,7 @@ int journal_file_open_reliably(
                 int flags,
                 mode_t mode,
                 bool compress,
-                bool authenticate,
+                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 JournalFile *template,
@@ -2149,7 +2156,7 @@ int journal_file_open_reliably(
         size_t l;
         char *p;
 
-        r = journal_file_open(fname, flags, mode, compress, authenticate,
+        r = journal_file_open(fname, flags, mode, compress, seal,
                               metrics, mmap_cache, template, ret);
         if (r != -EBADMSG && /* corrupted */
             r != -ENODATA && /* truncated */
@@ -2184,7 +2191,7 @@ int journal_file_open_reliably(
 
         log_warning("File %s corrupted or uncleanly shut down, renaming and replacing.", fname);
 
-        return journal_file_open(fname, flags, mode, compress, authenticate,
+        return journal_file_open(fname, flags, mode, compress, seal,
                                  metrics, mmap_cache, template, ret);
 }