3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
13 #include "os_crypto/md5/md5_op.h"
14 #include "os_crypto/sha1/sha1_op.h"
17 /* Signs a log file */
18 void OS_SignLog(char *logfile, char *logfile_old, int log_missing)
26 char logfilesum[OS_FLSIZE +1];
27 char logfilesum_old[OS_FLSIZE +1];
32 /* Clearing the memory */
33 memset(logfilesum, '\0', OS_FLSIZE +1);
34 memset(logfilesum_old, '\0', OS_FLSIZE +1);
37 /* Setting the umask */
41 /* Creating the checksum file names */
42 snprintf(logfilesum, OS_FLSIZE, "%s.sum", logfile);
43 snprintf(logfilesum_old, OS_FLSIZE, "%s.sum", logfile_old);
46 /* generating md5 of the old file */
47 if(OS_MD5_File(logfilesum_old, mf_sum_old) < 0)
49 merror("%s: No previous md5 checksum found: '%s'. "
50 "Starting over.", ARGV0, logfilesum_old);
51 strncpy(mf_sum_old, "none", 6);
54 /* generating sha1 of the old file. */
55 if(OS_SHA1_File(logfilesum_old, sf_sum_old) < 0)
57 merror("%s: No previous sha1 checksum found: '%s'. "
58 "Starting over.", ARGV0, logfilesum_old);
59 strncpy(sf_sum_old, "none", 6);
63 /* Generating md5 of the current file */
64 if(OS_MD5_File(logfile, mf_sum) < 0)
67 merror("%s: File '%s' not found. MD5 checksum skipped.",
69 strncpy(mf_sum, "none", 6);
72 /* Generating sha1 of the current file */
73 if(OS_SHA1_File(logfile, sf_sum) < 0)
76 merror("%s: File '%s' not found. SHA1 checksum skipped.",
78 strncpy(sf_sum, "none", 6);
82 fp = fopen(logfilesum, "w");
85 merror(FOPEN_ERROR, ARGV0, logfilesum);
90 fprintf(fp, "Current checksum:\n");
91 fprintf(fp, "MD5 (%s) = %s\n", logfile, mf_sum);
92 fprintf(fp, "SHA1 (%s) = %s\n\n", logfile, sf_sum);
94 fprintf(fp, "Chained checksum:\n");
95 fprintf(fp, "MD5 (%s) = %s\n", logfilesum_old, mf_sum_old);
96 fprintf(fp, "SHA1 (%s) = %s\n\n", logfilesum_old, sf_sum_old);