1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 #include "os_crypto/md5/md5_op.h"
12 #include "os_crypto/sha1/sha1_op.h"
17 void OS_SignLog(const char *logfile, const char *logfile_old, int log_missing)
25 char logfilesum[OS_FLSIZE + 1];
26 char logfilesum_old[OS_FLSIZE + 1];
30 /* Clear the memory */
31 memset(logfilesum, '\0', OS_FLSIZE + 1);
32 memset(logfilesum_old, '\0', OS_FLSIZE + 1);
37 /* Create the checksum file names */
38 snprintf(logfilesum, OS_FLSIZE, "%s.sum", logfile);
39 snprintf(logfilesum_old, OS_FLSIZE, "%s.sum", logfile_old);
41 /* Generate MD5 of the old file */
42 if (OS_MD5_File(logfilesum_old, mf_sum_old, OS_TEXT) < 0) {
43 merror("%s: No previous md5 checksum found: '%s'. "
44 "Starting over.", ARGV0, logfilesum_old);
45 strncpy(mf_sum_old, "none", 6);
48 /* Generate SHA-1 of the old file */
49 if (OS_SHA1_File(logfilesum_old, sf_sum_old, OS_TEXT) < 0) {
50 merror("%s: No previous sha1 checksum found: '%s'. "
51 "Starting over.", ARGV0, logfilesum_old);
52 strncpy(sf_sum_old, "none", 6);
55 /* Generate MD5 of the current file */
56 if (OS_MD5_File(logfile, mf_sum, OS_TEXT) < 0) {
58 merror("%s: File '%s' not found. MD5 checksum skipped.",
61 strncpy(mf_sum, "none", 6);
64 /* Generate SHA-1 of the current file */
65 if (OS_SHA1_File(logfile, sf_sum, OS_TEXT) < 0) {
67 merror("%s: File '%s' not found. SHA1 checksum skipped.",
70 strncpy(sf_sum, "none", 6);
73 fp = fopen(logfilesum, "w");
75 merror(FOPEN_ERROR, ARGV0, logfilesum, errno, strerror(errno));
79 fprintf(fp, "Current checksum:\n");
80 fprintf(fp, "MD5 (%s) = %s\n", logfile, mf_sum);
81 fprintf(fp, "SHA1 (%s) = %s\n\n", logfile, sf_sum);
83 fprintf(fp, "Chained checksum:\n");
84 fprintf(fp, "MD5 (%s) = %s\n", logfilesum_old, mf_sum_old);
85 fprintf(fp, "SHA1 (%s) = %s\n\n", logfilesum_old, sf_sum_old);