test-journal-verify.c revision 143bfdaf0b890fa7acadf02d1eafacaef1b696bd
bb5e3b2f129cc39517b925419c22f69a378ec023eh/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
bb5e3b2f129cc39517b925419c22f69a378ec023eh This file is part of systemd.
bb5e3b2f129cc39517b925419c22f69a378ec023eh Copyright 2012 Lennart Poettering
bb5e3b2f129cc39517b925419c22f69a378ec023eh systemd is free software; you can redistribute it and/or modify it
bb5e3b2f129cc39517b925419c22f69a378ec023eh under the terms of the GNU Lesser General Public License as published by
bb5e3b2f129cc39517b925419c22f69a378ec023eh the Free Software Foundation; either version 2.1 of the License, or
bb5e3b2f129cc39517b925419c22f69a378ec023eh (at your option) any later version.
bb5e3b2f129cc39517b925419c22f69a378ec023eh systemd is distributed in the hope that it will be useful, but
bb5e3b2f129cc39517b925419c22f69a378ec023eh WITHOUT ANY WARRANTY; without even the implied warranty of
bb5e3b2f129cc39517b925419c22f69a378ec023eh MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bb5e3b2f129cc39517b925419c22f69a378ec023eh Lesser General Public License for more details.
bb5e3b2f129cc39517b925419c22f69a378ec023eh You should have received a copy of the GNU Lesser General Public License
bb5e3b2f129cc39517b925419c22f69a378ec023eh along with systemd; If not, see <http://www.gnu.org/licenses/>.
bb5e3b2f129cc39517b925419c22f69a378ec023ehstatic int raw_verify(const char *fn, const char *verification_key) {
924f3e72988efae04c4357a6686a06ba300bab18eh r = journal_file_open(fn, O_RDONLY, 0666, true, !!verification_key, NULL, NULL, NULL, &f);
bb5e3b2f129cc39517b925419c22f69a378ec023eh if (r < 0)
bb5e3b2f129cc39517b925419c22f69a378ec023eh r = journal_file_verify(f, verification_key, NULL, NULL, NULL, false);
924f3e72988efae04c4357a6686a06ba300bab18eh char t[] = "/tmp/journal-XXXXXX";
bb5e3b2f129cc39517b925419c22f69a378ec023eh unsigned n;
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* journal_file_open requires a valid machine id */
bb5e3b2f129cc39517b925419c22f69a378ec023eh assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0);
bb5e3b2f129cc39517b925419c22f69a378ec023eh for (n = 0; n < N_ENTRIES; n++) {
bb5e3b2f129cc39517b925419c22f69a378ec023eh assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE));
bb5e3b2f129cc39517b925419c22f69a378ec023eh assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
bb5e3b2f129cc39517b925419c22f69a378ec023eh assert_se(journal_file_open("test.journal", O_RDONLY, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0);
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* journal_file_print_header(f); */
bb5e3b2f129cc39517b925419c22f69a378ec023eh assert_se(journal_file_verify(f, verification_key, &from, &to, &total, true) >= 0);
bb5e3b2f129cc39517b925419c22f69a378ec023eh if (verification_key && JOURNAL_HEADER_SEALED(f->header)) {
bb5e3b2f129cc39517b925419c22f69a378ec023eh format_timespan(c, sizeof(c), total > to ? total - to : 0, 0));
bb5e3b2f129cc39517b925419c22f69a378ec023eh for (p = 38448*8+0; p < ((uint64_t) st.st_size * 8); p ++) {
bb5e3b2f129cc39517b925419c22f69a378ec023eh log_notice(ANSI_HIGHLIGHT_RED_ON ">>>> %"PRIu64" (bit %"PRIu64") can be toggled without detection." ANSI_HIGHLIGHT_OFF, p / 8, p % 8);