X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_crypto%2Fmd5_sha1%2Fmd5_sha1_op.c;h=dd367c7a0e0fff9041a49052febb62a3718d0376;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=c2a168a43598ee49454e401bfcb96424d70425fc;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;p=ossec-hids.git diff --git a/src/os_crypto/md5_sha1/md5_sha1_op.c b/src/os_crypto/md5_sha1/md5_sha1_op.c old mode 100755 new mode 100644 index c2a168a..dd367c7 --- a/src/os_crypto/md5_sha1/md5_sha1_op.c +++ b/src/os_crypto/md5_sha1/md5_sha1_op.c @@ -1,5 +1,3 @@ -/* @(#) $Id$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -9,75 +7,82 @@ * Foundation */ - #include #include -#include "md5_sha1_op.h" +#include "md5_sha1_op.h" #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(const char *fname, const char *prefilter_cmd, os_md5 md5output, os_sha1 sha1output, int mode) { - int n; + size_t n; FILE *fp; - unsigned char buf[2048 +2]; + unsigned char buf[2048 + 2]; unsigned char sha1_digest[SHA_DIGEST_LENGTH]; unsigned char md5_digest[16]; SHA_CTX sha1_ctx; MD5_CTX md5_ctx; - - /* Clearing the memory. */ + /* Clear the memory */ md5output[0] = '\0'; sha1output[0] = '\0'; - buf[2048 +1] = '\0'; - - fp = fopen(fname,"r"); - if(!fp) - return(-1); - + buf[2048 + 1] = '\0'; + + /* Use prefilter_cmd if set */ + if (prefilter_cmd == NULL) { + fp = fopen(fname, mode == OS_BINARY ? "rb" : "r"); + if (!fp) { + return (-1); + } + } else { + char cmd[OS_MAXSTR]; + size_t target_length = strlen(prefilter_cmd) + 1 + strlen(fname); + int res = snprintf(cmd, sizeof(cmd), "%s %s", prefilter_cmd, fname); + if (res < 0 || (unsigned int)res != target_length) { + return (-1); + } + fp = popen(cmd, "r"); + if (!fp) { + return (-1); + } + } - /* Initializing both hashes */ + /* Initialize both hashes */ MD5Init(&md5_ctx); SHA1_Init(&sha1_ctx); - - /* Updating for each one. */ - while((n = fread(buf, 1, 2048, fp)) > 0) - { + /* Update for each one */ + while ((n = fread(buf, 1, 2048, fp)) > 0) { buf[n] = '\0'; - SHA1_Update(&sha1_ctx, buf, (unsigned long)n); - MD5Update(&md5_ctx, buf, n); + SHA1_Update(&sha1_ctx, buf, n); + MD5Update(&md5_ctx, buf, (unsigned)n); } SHA1_Final(&(sha1_digest[0]), &sha1_ctx); MD5Final(md5_digest, &md5_ctx); - - /* Setting output for md5. */ - for(n = 0;n < 16; n++) - { + /* Set output for MD5 */ + for (n = 0; n < 16; n++) { snprintf(md5output, 3, "%02x", md5_digest[n]); - md5output+=2; + md5output += 2; } - /* Setting output for sha1. */ - for (n = 0; n