Imported Upstream version 2.7
[ossec-hids.git] / src / os_crypto / md5_sha1 / md5_sha1_op.c
index c2a168a..b3471f4 100755 (executable)
@@ -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.
 
 #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);
 }