1 /* @(#) $Id: ./src/monitord/sign_log.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
14 #include "os_crypto/md5/md5_op.h"
15 #include "os_crypto/sha1/sha1_op.h"
18 /* Signs a log file */
19 void OS_SignLog(char *logfile, char *logfile_old, int log_missing)
27 char logfilesum[OS_FLSIZE +1];
28 char logfilesum_old[OS_FLSIZE +1];
33 /* Clearing the memory */
34 memset(logfilesum, '\0', OS_FLSIZE +1);
35 memset(logfilesum_old, '\0', OS_FLSIZE +1);
38 /* Setting the umask */
42 /* Creating the checksum file names */
43 snprintf(logfilesum, OS_FLSIZE, "%s.sum", logfile);
44 snprintf(logfilesum_old, OS_FLSIZE, "%s.sum", logfile_old);
47 /* generating md5 of the old file */
48 if(OS_MD5_File(logfilesum_old, mf_sum_old) < 0)
50 merror("%s: No previous md5 checksum found: '%s'. "
51 "Starting over.", ARGV0, logfilesum_old);
52 strncpy(mf_sum_old, "none", 6);
55 /* generating sha1 of the old file. */
56 if(OS_SHA1_File(logfilesum_old, sf_sum_old) < 0)
58 merror("%s: No previous sha1 checksum found: '%s'. "
59 "Starting over.", ARGV0, logfilesum_old);
60 strncpy(sf_sum_old, "none", 6);
64 /* Generating md5 of the current file */
65 if(OS_MD5_File(logfile, mf_sum) < 0)
68 merror("%s: File '%s' not found. MD5 checksum skipped.",
70 strncpy(mf_sum, "none", 6);
73 /* Generating sha1 of the current file */
74 if(OS_SHA1_File(logfile, sf_sum) < 0)
77 merror("%s: File '%s' not found. SHA1 checksum skipped.",
79 strncpy(sf_sum, "none", 6);
83 fp = fopen(logfilesum, "w");
86 merror(FOPEN_ERROR, ARGV0, logfilesum);
91 fprintf(fp, "Current checksum:\n");
92 fprintf(fp, "MD5 (%s) = %s\n", logfile, mf_sum);
93 fprintf(fp, "SHA1 (%s) = %s\n\n", logfile, sf_sum);
95 fprintf(fp, "Chained checksum:\n");
96 fprintf(fp, "MD5 (%s) = %s\n", logfilesum_old, mf_sum_old);
97 fprintf(fp, "SHA1 (%s) = %s\n\n", logfilesum_old, sf_sum_old);