X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fmonitord%2Fsign_log.c;fp=src%2Fmonitord%2Fsign_log.c;h=0aaec29035e3d6da331d612343b4f474f8e9644c;hp=40b37b46dca59bb718803b183f1dfa16f6fd7f0c;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/monitord/sign_log.c b/src/monitord/sign_log.c old mode 100755 new mode 100644 index 40b37b4..0aaec29 --- a/src/monitord/sign_log.c +++ b/src/monitord/sign_log.c @@ -1,6 +1,3 @@ -/* @(#) $Id: ./src/monitord/sign_log.c, 2011/09/08 dcid Exp $ - */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -13,10 +10,11 @@ #include "shared.h" #include "os_crypto/md5/md5_op.h" #include "os_crypto/sha1/sha1_op.h" +#include "monitord.h" -/* Signs a log file */ -void OS_SignLog(char *logfile, char *logfile_old, int log_missing) +/* Sign a log file */ +void OS_SignLog(const char *logfile, const char *logfile_old, int log_missing) { os_md5 mf_sum; os_md5 mf_sum_old; @@ -24,70 +22,60 @@ void OS_SignLog(char *logfile, char *logfile_old, int log_missing) os_sha1 sf_sum; os_sha1 sf_sum_old; - char logfilesum[OS_FLSIZE +1]; - char logfilesum_old[OS_FLSIZE +1]; + char logfilesum[OS_FLSIZE + 1]; + char logfilesum_old[OS_FLSIZE + 1]; FILE *fp; + /* Clear the memory */ + memset(logfilesum, '\0', OS_FLSIZE + 1); + memset(logfilesum_old, '\0', OS_FLSIZE + 1); - /* Clearing the memory */ - memset(logfilesum, '\0', OS_FLSIZE +1); - memset(logfilesum_old, '\0', OS_FLSIZE +1); - - - /* Setting the umask */ + /* Set umask */ umask(0027); - - /* Creating the checksum file names */ + /* Create the checksum file names */ snprintf(logfilesum, OS_FLSIZE, "%s.sum", logfile); snprintf(logfilesum_old, OS_FLSIZE, "%s.sum", logfile_old); - - /* generating md5 of the old file */ - if(OS_MD5_File(logfilesum_old, mf_sum_old) < 0) - { + /* Generate MD5 of the old file */ + if (OS_MD5_File(logfilesum_old, mf_sum_old, OS_TEXT) < 0) { merror("%s: No previous md5 checksum found: '%s'. " "Starting over.", ARGV0, logfilesum_old); strncpy(mf_sum_old, "none", 6); } - /* generating sha1 of the old file. */ - if(OS_SHA1_File(logfilesum_old, sf_sum_old) < 0) - { + /* Generate SHA-1 of the old file */ + if (OS_SHA1_File(logfilesum_old, sf_sum_old, OS_TEXT) < 0) { merror("%s: No previous sha1 checksum found: '%s'. " "Starting over.", ARGV0, logfilesum_old); strncpy(sf_sum_old, "none", 6); } - - /* Generating md5 of the current file */ - if(OS_MD5_File(logfile, mf_sum) < 0) - { - if(log_missing) + /* Generate MD5 of the current file */ + if (OS_MD5_File(logfile, mf_sum, OS_TEXT) < 0) { + if (log_missing) { merror("%s: File '%s' not found. MD5 checksum skipped.", - ARGV0, logfile); + ARGV0, logfile); + } strncpy(mf_sum, "none", 6); } - /* Generating sha1 of the current file */ - if(OS_SHA1_File(logfile, sf_sum) < 0) - { - if(log_missing) + /* Generate SHA-1 of the current file */ + if (OS_SHA1_File(logfile, sf_sum, OS_TEXT) < 0) { + if (log_missing) { merror("%s: File '%s' not found. SHA1 checksum skipped.", - ARGV0, logfile); + ARGV0, logfile); + } strncpy(sf_sum, "none", 6); } - fp = fopen(logfilesum, "w"); - if(!fp) - { - merror(FOPEN_ERROR, ARGV0, logfilesum); + if (!fp) { + merror(FOPEN_ERROR, ARGV0, logfilesum, errno, strerror(errno)); return; } - fprintf(fp, "Current checksum:\n"); fprintf(fp, "MD5 (%s) = %s\n", logfile, mf_sum); fprintf(fp, "SHA1 (%s) = %s\n\n", logfile, sf_sum); @@ -99,6 +87,4 @@ void OS_SignLog(char *logfile, char *logfile_old, int log_missing) return; } - -/* EOF */