[Forensics-changes] [hashrat] 01/02: Import Upstream version 1.8.11+dfsg

Giovani Augusto Ferreira giovani at moszumanska.debian.org
Thu Nov 2 11:01:58 UTC 2017


This is an automated email from the git hooks/post-receive script.

giovani pushed a commit to branch debian
in repository hashrat.

commit 11f14b44f71fb485831d526e5313024f8bff0229
Author: Giovani Augusto Ferreira <giovani at debian.org>
Date:   Thu Nov 2 08:59:30 2017 -0200

    Import Upstream version 1.8.11+dfsg
---
 Makefile                    | 70 ---------------------------------------------
 README                      |  9 ++++--
 check-hash.c                |  8 ++----
 check.sh                    | 25 ++++++++++++++--
 common.c                    | 42 +++++++++++++++------------
 common.h                    |  4 +--
 files.c                     | 35 ++++++++++++-----------
 hashrat.1                   |  5 +---
 "tests/bad'file name\".txt" |  1 +
 9 files changed, 76 insertions(+), 123 deletions(-)

diff --git a/Makefile b/Makefile
deleted file mode 100644
index dfc06b9..0000000
--- a/Makefile
+++ /dev/null
@@ -1,70 +0,0 @@
-
-CC = gcc
-VERSION = 
-CFLAGS = -g -O2
-LIBS = 
-INSTALL=/bin/install -c
-prefix=/usr/local
-bindir=$(prefix)${exec_prefix}/bin
-FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -D_FILE_OFFSET_BITS=64
-OBJ=common.o command-line-args.o ssh.o fingerprint.o files.o filesigning.o xattr.o cgi.o check-hash.o find.o memcached.o
-EXE=hashrat
-
-all: hashrat
-
-hashrat: $(OBJ) main.c
-	@cd libUseful-2.5; $(MAKE)
-	$(CC) $(FLAGS) -o$(EXE) $(OBJ) main.c libUseful-2.5/libUseful-2.5.a $(LIBS) 
-
-common.o: common.h common.c
-	$(CC) $(FLAGS) -c common.c
-
-fingerprint.o: fingerprint.h fingerprint.c
-	$(CC) $(FLAGS) -c fingerprint.c
-
-files.o: files.h files.c
-	$(CC) $(FLAGS) -c files.c
-
-filesigning.o: filesigning.h filesigning.c
-	$(CC) $(FLAGS) -c filesigning.c
-
-find.o: find.h find.c
-	$(CC) $(FLAGS) -c find.c
-
-check-hash.o: check-hash.h check-hash.c
-	$(CC) $(FLAGS) -c check-hash.c
-
-xattr.o: xattr.h xattr.c
-	$(CC) $(FLAGS) -c xattr.c
-
-ssh.o: ssh.h ssh.c
-	$(CC) $(FLAGS) -c ssh.c
-
-cgi.o: cgi.h cgi.c
-	$(CC) $(FLAGS) -c cgi.c
-
-memcached.o: memcached.h memcached.c
-	$(CC) $(FLAGS) -c memcached.c
-
-command-line-args.o: command-line-args.h command-line-args.c
-	$(CC) $(FLAGS) -c command-line-args.c
-
-check: hashrat
-	@./check.sh
-
-clean:
-	-rm -f *.o */*.o */*.a */*.so $(EXE)
-	-rm -f config.log config.status */config.log */config.status
-	-rm -fr autom4te.cache */autom4te.cache
-
-distclean:
-	-rm -f *.o */*.o */*.a */*.so $(EXE)
-	-rm -f config.log config.status */config.log */config.status Makefile */Makefile
-	-rm -fr autom4te.cache */autom4te.cache
-
-
-install: hashrat
-	-mkdir -p $(DESTDIR)$(prefix)/bin
-	cp -f $(EXE) $(DESTDIR)$(prefix)/bin
-	-mkdir -p $(DESTDIR)$(prefix)/share/man/man1
-	cp -f hashrat.1 $(DESTDIR)$(prefix)/share/man/man1
diff --git a/README b/README
index 6d3d63b..1c9adce 100644
--- a/README
+++ b/README
@@ -87,8 +87,8 @@ Options:
   -dups           Search for duplicate files.
   -memcached <server> Specify memcached server. (Overrides reading list from stdin if used with -m, -c or -cf).
   -mcd <server>   Specify memcached server. (Overrides reading list from stdin if used with -m, -c or -cf).
-  -h <script>     Script to run when a file fails CHECK mode, or is found in MATCH mode.
-  -hook <script>  Script to run when a file fails CHECK mode, or is found in FIND mode
+  -h <script>     Script to run when a file fails CHECK mode, or is found in MATCH mode. (see 'Hookscripts' below)
+  -hook <script>  Script to run when a file fails CHECK mode, or is found in MATCH mode. (see 'Hookscripts' below)
   -color          Use ANSI color codes on output when checking hashes.
   -strict         Strict mode: when checking, check file mtime, owner, group, and inode as well as it's hash
   -S              Strict mode: when checking, check file mtime, owner, group, and inode as well as it's hash
@@ -112,6 +112,11 @@ Options:
   -star-input     When reading data from stdin in linemode replace characters with stars.
 
 
+Hookscripts
+
+	hookscripts are passed the path of the  appropriate file as an argument. In 'find duplicates' mode a second argument is passed, which is the duplicate file.
+
+
 Hashrat can also detect if it's being run under any of the following names (e.g., via symlinks)
 
   md5sum          run with '-trad -md5'
diff --git a/check-hash.c b/check-hash.c
index 483f901..f3cf4b2 100644
--- a/check-hash.c
+++ b/check-hash.c
@@ -2,6 +2,7 @@
 #include "fingerprint.h"
 #include "files.h"
 
+
 void HandleCheckFail(char *Path, char *ErrorMessage)
 {
 char *Tempstr=NULL;
@@ -9,12 +10,7 @@ char *Tempstr=NULL;
   if (Flags & FLAG_COLOR) printf("%s%s: FAILED. '%s'.%s\n",ANSICode(ANSI_RED, 0, 0),Path, ErrorMessage, ANSI_NORM);
 	else printf("%s: FAILED. %s.\n",Path,ErrorMessage);
 
-  if (StrLen(DiffHook))
-  {
-    Tempstr=MCopyStr(Tempstr,DiffHook," '",Path,"'",NULL);
-    system(Tempstr);
-  }
-
+	RunHookScript(DiffHook, Path, "");
   DestroyString(Tempstr);
 }
 
diff --git a/check.sh b/check.sh
index 038f7ed..1bf3ab2 100755
--- a/check.sh
+++ b/check.sh
@@ -71,6 +71,22 @@ else
 fi
 }
 
+
+TestLocateHook()
+{
+rm -f locatehook.out
+HR_OUT=`echo $1 | ./hashrat -m -r . -hook "echo found > locatehook.out"`
+
+if [ -e locatehook.out ]
+then
+	OkayMessage "$3 works."
+else 
+	FailMessage "$3 BROKEN."
+fi
+}
+
+
+
 TestExitCodes()
 {
 if [ "$4" = "FindDuplicates" ]
@@ -137,7 +153,7 @@ TestHash z85 "ZEROMQ85 encoding" "wX%ElWFTQ9+Z=X4h"
 Title "Testing Misc. Features"
 
 HR_OUT=`./hashrat -version`
-if [ "$HR_OUT" = "version: 1.8.7" ]
+if [ "$HR_OUT" = "version: 1.8.10" ]
 then
 	OkayMessage "Version (-version) works"
 else
@@ -154,7 +170,7 @@ else
 fi
 
 HR_OUT=`./hashrat -dir -sha1 -trad tests`
-if [ "$HR_OUT" = "b8b4058dc499ee1f330926a5a073a2c598b10c91  tests" ]
+if [ "$HR_OUT" = "9521674698e62496698c42f63c9cde9bc6399a03  tests" ]
 then
   OkayMessage "Directory hashing works"
 else
@@ -163,7 +179,7 @@ fi
 
 
 HR_OUT=`./hashrat -sha1 -trad -r tests | ./hashrat -sha1`
-if [ "$HR_OUT" = "06af1d9f777bbeb1eecd76d71d869089683ded1b" ]
+if [ "$HR_OUT" = "a31f3b27b58f8b26a3c2237beb9de410d1117fba" ]
 then
 	OkayMessage "Recursive file hashing works"
 else
@@ -198,6 +214,9 @@ TestLocate "MD5 (test file) = 6ec9de513a8ff1768eb4768236198cf3" "LOCATED: 6ec9de
 HR_INPUT=`cat tests/test.ioc`
 TestLocate "$HR_INPUT" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 ' Hashrat Test IOC' at ./tests/help.txt" "Locating files with OpenIOC input"
 
+Title "Test hook functions"
+TestLocateHook "hash='md5:6ec9de513a8ff1768eb4768236198cf3' mode='100644' uid='0' gid='0' size='621' mtime='1423180289' inode='2359456' path='test file'" "" "Hook function for file locate"
+TestLocateHook "hash='md5:6933ee7eb504d29312b23a47d2dac374' mode='100644' uid='0' gid='0' size='621' mtime='1423180289' inode='2359456' path='test file'" "" "Hook function for file locate of files with bad characters in name"
 
 Title "Testing exit codes for different operations"
 
diff --git a/common.c b/common.c
index c4441dc..3fa4089 100644
--- a/common.c
+++ b/common.c
@@ -127,30 +127,34 @@ char *Tempstr=NULL;
 }
 
 
-void HandleCompareResult(char *Path, char *Status, int Flags, char *ErrorMessage)
+void RunHookScript(const char *Hook, const char *Path, const char *Other)
 {
-char *Tempstr=NULL;
-int Color=0;
+char *Tempstr=NULL, *QuotedPath=NULL, *QuotedOther=NULL;
+STREAM *S;
 
-  if (Flags & FLAG_COLOR) 
-	{
-		switch (Flags & FLAG_RESULT_MASK)
+  if (StrValid(Hook))
+  {
+		//must quote twice to get through system comamnd
+    QuotedPath=QuoteCharsInStr(QuotedPath, Path,"\"'`!|;<> 	");
+    QuotedOther=QuoteCharsInStr(QuotedOther, Other,"\"'`!|;<> 	");
+		S=STREAMSpawnCommand("/bin/sh","","",0);
+		if (S)
 		{
-			case RESULT_FAIL: Color=ANSI_RED; break;
-			case RESULT_PASS: Color=ANSI_GREEN; break;
-			case RESULT_WARN: Color=ANSI_YELLOW; break;
+    	Tempstr=MCopyStr(Tempstr, DiffHook," ",QuotedPath, " ", QuotedOther, ";exit\n",NULL);
+			STREAMWriteLine(Tempstr,S);
+			STREAMFlush(S);
+
+			Tempstr=STREAMReadLine(Tempstr,S);
+			while (Tempstr)
+			{
+			printf("%s\n",Tempstr);
+			Tempstr=STREAMReadLine(Tempstr,S);
+			}
 		}
-	}
-
-	if (Color > 0) printf("%s%s: %s. '%s'.%s\n",ANSICode(ANSI_RED, 0, 0),Status, Path, ErrorMessage, ANSI_NORM);
-  else printf("%s: %s. %s.\n",Status, Path,ErrorMessage);
-
-  if ((Flags & RESULT_RUNHOOK) && StrLen(DiffHook))
-  {
-    Tempstr=MCopyStr(Tempstr,DiffHook," '",Path,"'",NULL);
-    system(Tempstr);
   }
 
-  DestroyString(Tempstr);
+DestroyString(Tempstr);
+DestroyString(QuotedPath);
+DestroyString(QuotedOther);
 }
 
diff --git a/common.h b/common.h
index 5742348..ff6735e 100644
--- a/common.h
+++ b/common.h
@@ -72,7 +72,7 @@
 
 #define IGNORE -1
 
-#define VERSION "1.8.9"
+#define VERSION "1.8.11"
 
 
 typedef struct
@@ -115,6 +115,6 @@ TFingerprint *TFingerprintCreate(const char *Hash, const char *HashType, const c
 void HashratCtxDestroy(void *p_Ctx);
 void HashratStoreHash(HashratCtx *Ctx, char *Path, struct stat *Stat, char *Hash);
 int HashratOutputInfo(HashratCtx *Ctx, STREAM *S, char *Path, struct stat *Stat, char *Hash);
-void HandleCompareResult(char *Path, char *Status, int Flags, char *ErrorMessage);
+void RunHookScript(const char *Hook, const char *Path, const char *Other);
 
 #endif
diff --git a/files.c b/files.c
index c042f0b..463f07e 100644
--- a/files.c
+++ b/files.c
@@ -182,7 +182,7 @@ int HashratHashFile(HashratCtx *Ctx, THash *Hash, int Type, char *Path, off_t Fi
 STREAM *S;
 char *Tempstr=NULL, *User=NULL, *Pass=NULL;
 int result, val, RetVal=FALSE;
-off_t bytes_read=0;
+off_t bytes_read=0, oval;
 
 switch (Type)
 {
@@ -210,8 +210,9 @@ if (S)
 {
 Tempstr=SetStrLen(Tempstr,BUFSIZ);
 
-val=FileSize;
-if ((val==0) || ( val > BUFSIZ)) val=BUFSIZ;
+oval=FileSize;
+if ((oval==0) || ( oval > BUFSIZ)) val=BUFSIZ;
+else val=(int)oval;
 result=STREAMReadBytes(S,Tempstr,val);
 while (result > 0)
 {
@@ -223,8 +224,9 @@ while (result > 0)
 	if (FileSize > 0)
 	{
 	if ((Type != FT_HTTP) && (bytes_read >= FileSize)) break;
-	val=FileSize - bytes_read;
-	if (val > BUFSIZ) val=BUFSIZ;
+	oval=FileSize - bytes_read;
+	if (oval > BUFSIZ) val=BUFSIZ;
+	else val=(int)oval;
 	}
 	result=STREAMReadBytes(S,Tempstr,val);
 }
@@ -267,7 +269,7 @@ int HashratHashSingleFile(HashratCtx *Ctx, char *HashType, int FileType, char *P
 THash *Hash;
 struct stat XattrStat;
 char *ptr;
-int size=0;
+off_t size=0;
 
 		*RetStr=CopyStr(*RetStr,"");
 
@@ -416,12 +418,6 @@ char *Tempstr=NULL;
 		break;
 	}
 
-  if (StrValid(DiffHook))
-  {
-    Tempstr=MCopyStr(Tempstr,DiffHook," '",Path,"'",NULL);
-    system(Tempstr);
-  }
-
 
 DestroyString(Tempstr);
 
@@ -436,7 +432,7 @@ int HashratAction(HashratCtx *Ctx, char *Path, struct stat *Stat)
 {
 char *HashStr=NULL;
 int Type, result=FALSE;
-TFingerprint *FP;
+TFingerprint *FP=NULL;
 
 switch (Ctx->Action)
 {
@@ -468,7 +464,6 @@ case ACT_CHECK:
 					//we return TRUE on FAILURE, as we are signaling a significant event
 					result=TRUE;
 			}
-			TFingerprintDestroy(FP);	
 		}
 		else if (Flags & FLAG_VERBOSE) fprintf(stderr,"ZERO LENGTH FILE: %s\n",Path);
 	}
@@ -508,7 +503,6 @@ case ACT_CHECK_MEMCACHED:
 
 		if (FP && HashratCheckFile(Ctx, Path, NULL, HashStr, FP)) result=FALSE;
 		else fprintf(stderr,"ERROR: No stored hash for '%s'\n",Path);
-		TFingerprintDestroy(FP);
 		}
 		else if (Flags & FLAG_VERBOSE) fprintf(stderr,"ZERO LENGTH FILE: %s\n",Path);
 	}
@@ -532,7 +526,6 @@ case ACT_FINDMATCHES_MEMCACHED:
 			result=TRUE;
 		}
 		else DiffCount++;
-		TFingerprintDestroy(FP);	
 		}
 		else if (Flags & FLAG_VERBOSE) fprintf(stderr,"ZERO LENGTH FILE: %s\n",Path);
 	}
@@ -552,13 +545,14 @@ case ACT_FINDDUPLICATES:
 				MatchCount++;
 			//here we return true if a match found
 				result=TRUE;
-				TFingerprintDestroy(FP);	
 			}
 			else 
 			{
 				FP=TFingerprintCreate(HashStr, Ctx->HashType, "", Path);
 				DiffCount++;
 				MatchAdd(FP, Path, 0);
+				//as we've added FP to an internal list we don't want it destroyed
+				FP=NULL;
 			}
 		}
 	}
@@ -567,6 +561,13 @@ case ACT_FINDDUPLICATES:
 break;
 }
 
+if (result==TRUE) 
+{
+	if (FP) RunHookScript(DiffHook, Path, FP->Path);
+	else RunHookScript(DiffHook, Path, "");
+}
+
+if (FP) TFingerprintDestroy(FP);	
 DestroyString(HashStr);
 
 return(result);
diff --git a/hashrat.1 b/hashrat.1
index cf62168..31857a1 100644
--- a/hashrat.1
+++ b/hashrat.1
@@ -188,11 +188,8 @@ Specify memcached server. This option overrides reading list from stdin if used
 .TP
 .B
 \fB-h\fP <script>
-Script \fIto\fP run when a \fIfile\fP fails CHECK mode, or is found in MATCH mode.
-.TP
-.B
 \fB-hook\fP <script>
-Script \fIto\fP run when a \fIfile\fP fails CHECK mode, or is found in FIND mode
+Script \fIto\fP run when a \fIfile\fP fails CHECK mode, or is found in MATCH mode. Script is passed the filename as an argument. In 'find duplicates' mode a second file name (the duplicate) will be passed as the second argument.
 .TP
 .B
 \fB-color\fP
diff --git "a/tests/bad'file name\".txt" "b/tests/bad'file name\".txt"
new file mode 100644
index 0000000..b9a818c
--- /dev/null
+++ "b/tests/bad'file name\".txt"	
@@ -0,0 +1 @@
+test file with ' in the name

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/hashrat.git



More information about the forensics-changes mailing list