X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fos_crypto%2Fmd5_sha1%2Fmd5_sha1_op.c;h=b3471f4b3f5ff16fe453a83e42d244768db92508;hp=c2a168a43598ee49454e401bfcb96424d70425fc;hb=6ef2f786c6c8ead94841b5f93baf9f43421f08c8;hpb=301048b51990573e58a30dc4a5bb4ec285cad554 diff --git a/src/os_crypto/md5_sha1/md5_sha1_op.c b/src/os_crypto/md5_sha1/md5_sha1_op.c index c2a168a..b3471f4 100755 --- a/src/os_crypto/md5_sha1/md5_sha1_op.c +++ b/src/os_crypto/md5_sha1/md5_sha1_op.c @@ -1,4 +1,5 @@ -/* @(#) $Id$ */ +/* @(#) $Id: ./src/os_crypto/md5_sha1/md5_sha1_op.c, 2011/09/08 dcid Exp $ + */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. @@ -16,10 +17,11 @@ #include "../md5/md5.h" #include "../sha1/sha.h" +#include "headers/defs.h" + - -int OS_MD5_SHA1_File(char * fname, char *md5output, char *sha1output) +int OS_MD5_SHA1_File(char *fname, char *prefilter_cmd, char *md5output, char *sha1output) { int n; FILE *fp; @@ -27,19 +29,30 @@ int OS_MD5_SHA1_File(char * fname, char *md5output, char *sha1output) unsigned char sha1_digest[SHA_DIGEST_LENGTH]; unsigned char md5_digest[16]; + char cmd[OS_MAXSTR]; + SHA_CTX sha1_ctx; MD5_CTX md5_ctx; - + /* Clearing the memory. */ md5output[0] = '\0'; sha1output[0] = '\0'; buf[2048 +1] = '\0'; - fp = fopen(fname,"r"); - if(!fp) - return(-1); - + /* Use prefilter_cmd if set */ + if (prefilter_cmd == NULL) { + fp = fopen(fname,"r"); + if(!fp) + return(-1); + } else { + strncpy(cmd, prefilter_cmd, sizeof(cmd) - 1); + strcat(cmd, " "); + strncat(cmd, fname, sizeof(cmd) - strlen(cmd) - 1); + fp = popen(cmd, "r"); + if(!fp) + return(-1); + } /* Initializing both hashes */ MD5Init(&md5_ctx); @@ -74,7 +87,11 @@ int OS_MD5_SHA1_File(char * fname, char *md5output, char *sha1output) /* Closing it */ - fclose(fp); + if (prefilter_cmd == NULL) { + fclose(fp); + } else { + pclose(fp); + } return(0); }