Skip to content

Commit

Permalink
fix xattr support
Browse files Browse the repository at this point in the history
  • Loading branch information
ColumPaget committed Feb 6, 2022
1 parent cbc3de1 commit 0b3c057
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

CC = gcc
CFLAGS = -g -O2
LIBS = -lssl -lcrypto libUseful-4/libUseful.a
LIBS = libUseful-4/libUseful.a
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 -DHAVE_LIBCRYPTO=1 -DHAVE_LIBSSL=1
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 encodings.o command-line-args.o ssh.o http.o fingerprint.o include-exclude.o files.o filesigning.o xattr.o check-hash.o find.o memcached.o frontend.o cgi.o xdialog.o
EXE=hashrat

Expand Down
10 changes: 5 additions & 5 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ TestHash z85 "ZEROMQ85 encoding" "wX%ElWFTQ9+Z=X4h"
Title "Testing Misc. Features"

HR_OUT=`./hashrat -version`
if [ "$HR_OUT" = "version: 1.12" ]
if [ "$HR_OUT" = "version: 1.15" ]
then
OkayMessage "Version (-version) works"
else
Expand Down Expand Up @@ -235,12 +235,12 @@ fi

Title "Testing File Locate using different input formats"

TestLocate "hash='md5:6ec9de513a8ff1768eb4768236198cf3' mode='100644' uid='0' gid='0' size='621' mtime='1423180289' inode='2359456' path='test file'" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 'test file ' at ./tests/help.txt" "Locating files with native format input"
TestLocate "6ec9de513a8ff1768eb4768236198cf3 test file" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 'test file ' at ./tests/help.txt" "Locating files with traditional (md5sum) format input"
TestLocate "MD5 (test file) = 6ec9de513a8ff1768eb4768236198cf3" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 'test file ' at ./tests/help.txt" "Locating files with bsd format input"
TestLocate "hash='md5:6ec9de513a8ff1768eb4768236198cf3' mode='100644' uid='0' gid='0' size='621' mtime='1423180289' inode='2359456' path='test file'" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 'test file ' at tests/help.txt" "Locating files with native format input"
TestLocate "6ec9de513a8ff1768eb4768236198cf3 test file" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 'test file ' at tests/help.txt" "Locating files with traditional (md5sum) format input"
TestLocate "MD5 (test file) = 6ec9de513a8ff1768eb4768236198cf3" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 'test file ' at tests/help.txt" "Locating files with bsd format input"

HR_INPUT=`cat tests/test.ioc`
TestLocate "$HR_INPUT" "LOCATED: 6ec9de513a8ff1768eb4768236198cf3 ' Hashrat Test IOC' at ./tests/help.txt" "Locating files with OpenIOC input"
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"
Expand Down
6 changes: 3 additions & 3 deletions command-line-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ void CommandLinePrintUsage()
printf(" %-15s %s\n","-cgi", "Run in HTTP CGI mode");
printf(" %-15s %s\n","-cgi", "Run in HTTP CGI mode");
printf(" %-15s %s\n","-xdialog","Run in 'xdialog' (zenity, yad or qarama) mode");
printf(" %-15s %s\n","-dialog-types <list>","Specify a list of dialog commands and use the first found on the system. Default is 'yad,zenity,qarma'");
printf(" %-15s %s\n","-iprefix <prefix>","String to prefix all input before hashing");
printf(" %-15s %s\n","-oprefix <prefix>","Prefix to add to the front of output hashes");
printf(" %-15s %s\n","-dialog-types <list>","Specify a list of dialog commands and use the first found on the system. Default is 'yad,zenity,qarma'");
printf(" %-15s %s\n","-iprefix <prefix>","String to prefix all input before hashing");
printf(" %-15s %s\n","-oprefix <prefix>","Prefix to add to the front of output hashes");
printf(" %-15s %s\n","-net", "Treat 'file' arguments as either ssh or http URLs, and pull files over the network and then hash them (Allows hashing of files on remote machines).");
printf(" %-15s %s\n","", "URLs are in the format ssh://[username]:[password]@[host]:[port] or http://[username]:[password]@[host]:[port]..");
printf(" %-15s %s\n","-idfile <path>", "Path to an ssh private key file to use to authenticate INSTEAD OF A PASSWORD when pulling files via ssh.");
Expand Down
2 changes: 1 addition & 1 deletion common.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void RunHookScript(const char *Hook, const char *Path, const char *Other)
//must quote twice to get through system comamnd
QuotedPath=QuoteCharsInStr(QuotedPath, Path,"\"'`!|;<> ");
QuotedOther=QuoteCharsInStr(QuotedOther, Other,"\"'`!|;<> ");
S=STREAMSpawnCommand("/bin/sh",0);
S=STREAMSpawnCommand("/bin/sh", "");
if (S)
{
Tempstr=MCopyStr(Tempstr, DiffHook," ",QuotedPath, " ", QuotedOther, ";exit\n",NULL);
Expand Down
9 changes: 4 additions & 5 deletions files.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ int HashratAction(HashratCtx *Ctx, const char *Path, struct stat *Stat)
if (FP)
{
HashItem(Ctx, FP->HashType, Path, Stat, &HashStr);
if (FP->Flags & FP_HASSTAT) if (HashratCheckFile(Ctx, Path, Stat, HashStr, FP)) result=FALSE;
else if (HashratCheckFile(Ctx, Path, Stat, HashStr, FP)) result=FALSE;
if (HashratCheckFile(Ctx, Path, Stat, HashStr, FP)) result=FALSE;
}
else fprintf(stderr,"ERROR: No stored hash for '%s'\n",Path);
}
Expand Down Expand Up @@ -620,10 +619,10 @@ int ProcessItem(HashratCtx *Ctx, const char *Path, struct stat *Stat, int IsTopL
{
char *HashStr=NULL;
int result=FALSE, Flags;
const char *p_Path;
const char *p_Path;

p_Path=Path;
if (strncmp(p_Path, "./", 2)==0) p_Path+=2;
p_Path=Path;
if (strncmp(p_Path, "./", 2)==0) p_Path+=2;


if (! Visited) Visited=MapCreate(1025, LIST_FLAG_CACHE);
Expand Down
16 changes: 8 additions & 8 deletions find.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ TFingerprint *FindPathMatches(HashratCtx *Ctx, TFingerprint *Head, const char *P
TFingerprint *CheckForMatch(HashratCtx *Ctx, const char *Path, struct stat *FStat, const char *HashStr)
{
TFingerprint *Lookup, *Head=NULL, *Prev=NULL, *Item=NULL, *Result=NULL;
const char *p_Path;
const char *p_Path;
void *ptr;

if (! StrValid(Path)) return(NULL);

p_Path=Path;
if (strncmp(p_Path, "./", 2)==0) p_Path++;
p_Path=Path;
if (strncmp(p_Path, "./", 2)==0) p_Path++;
Lookup=TFingerprintCreate(HashStr,"","",p_Path);
switch (Ctx->Action)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ TFingerprint *CheckForMatch(HashratCtx *Ctx, const char *Path, struct stat *FSta
void OutputUnmatchedItem(const void *p_Item, const VISIT which, const int depth)
{
TFingerprint *Item;
char *Tempstr=NULL;
char *Tempstr=NULL;

if ((which==preorder) || (which==leaf))
{
Expand All @@ -180,19 +180,19 @@ void OutputUnmatchedItem(const void *p_Item, const VISIT which, const int depth)
//if a root node of the linked list has been deleted, its path is
//set blank, rather than actually deleting it, as we need it to
//continue acting as the head node, so we check StrValid rather
//than checking for NULL
//than checking for NULL
if (StrValid(Item->Path))
{
if (access(Item->Path, F_OK) !=0) HandleCheckFail(Item->Path, "Missing");
//else HashSingleFile(&Tempstr, Ctx, Ctx->HashType, Item->Path);
//else HashSingleFile(&Tempstr, Ctx, Ctx->HashType, Item->Path);



}
Item=Item->Next;
}
}

Destroy(Tempstr);
Destroy(Tempstr);
}


Expand Down
6 changes: 3 additions & 3 deletions libUseful-4/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CC = gcc
VERSION = 4.73
CFLAGS = -g -O2 -mmmx -msse -msse2
CFLAGS = -g -O2
LDFLAGS=
LIBS = -lssl -lcrypto -lc -lc -lc -lc -lc -lc -lc -lc -lc -lc
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBC=1 -DHAVE_PTSNAME_R=1 -DHAVE_LIBC=1 -DHAVE_CLEARENV=1 -DHAVE_LIBC=1 -DHAVE_SETRESUID=1 -DHAVE_LIBC=1 -DHAVE_GET_CURR_DIR=1 -DHAVE_LIBC=1 -DHAVE_UMOUNT2=1 -DHAVE_LIBC=1 -DHAVE_UMOUNT=1 -DHAVE_LIBC=1 -DHAVE_MKOSTEMP=1 -DHAVE_LIBC=1 -DHAVE_POLL=1 -DUSE_INET6=1 -DHAVE_LIBC=1 -DHAVE_UNSHARE=1 -DHAVE_LIBC=1 -DHAVE_SETNS=1 -DHAVE_LIBCRYPTO=1 -DHAVE_LIBSSL=1 -DHAVE_EVP_BF_CBC=1 -DHAVE_EVP_RC2_CBC=1 -DHAVE_EVP_RC4=1 -DHAVE_EVP_DES_CBC=1 -DHAVE_EVP_DESX_CBC=1 -DHAVE_EVP_CAST5_CBC=1 -DHAVE_EVP_IDEA_CBC=1 -DHAVE_EVP_AES_128_CBC=1 -DHAVE_EVP_AES_256_CBC=1 -DHAVE_X509_CHECK_HOST=1 -DHAVE_SSL_SET_MIN_PROTO_VERSION=1 -DHAVE_DECL_OPENSSL_ADD_ALL_ALGORITHMS=1 -DHAVE_OPENSSL_ADD_ALL_ALGORITHMS=1 -DHAVE_DECL_SSL_SET_TLSEXT_HOST_NAME=1 -DHAVE_SSL_SET_TLSEXT_HOST_NAME=1 -DHAVE_MADVISE -DHAVE_MADVISE_NOFORK -DHAVE_MADVISE_DONTDUMP -DHAVE_MLOCK -DVERSION=\"$(VERSION)\"
LIBS = -lc -lc -lc -lc -lc -lc -lc -lc
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -fPIC -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBC=1 -DHAVE_PTSNAME_R=1 -DHAVE_LIBC=1 -DHAVE_CLEARENV=1 -DHAVE_LIBC=1 -DHAVE_SETRESUID=1 -DHAVE_LIBC=1 -DHAVE_GET_CURR_DIR=1 -DHAVE_LIBC=1 -DHAVE_UMOUNT2=1 -DHAVE_LIBC=1 -DHAVE_UMOUNT=1 -DHAVE_LIBC=1 -DHAVE_MKOSTEMP=1 -DHAVE_LIBC=1 -DHAVE_POLL=1 -DHAVE_MADVISE -DHAVE_MADVISE_NOFORK -DHAVE_MADVISE_DONTDUMP -DHAVE_MLOCK -DVERSION=\"$(VERSION)\"
prefix=/usr/local
OBJ=String.o Array.o List.o IPAddress.o Socket.o Server.o UnixSocket.o Stream.o Errors.o Unicode.o Terminal.o TerminalWidget.o TerminalMenu.o TerminalChoice.o TerminalBar.o FileSystem.o GeneralFunctions.o DataProcessing.o Pty.o Log.o Http.o Gemini.o Smtp.o inet.o Expect.o base64.o crc32.o md5c.o sha1.o sha2.o whirlpool.o jh_ref.o Hash.o Ssh.o Compression.o OAuth.o LibSettings.o Vars.o Time.o Markup.o SpawnPrograms.o Tokenizer.o PatternMatch.o URL.o DataParser.o ConnectionChain.o OpenSSL.o Process.o Encodings.o RawData.o SecureMem.o CommandLineParser.o SysInfo.o

Expand Down
2 changes: 1 addition & 1 deletion libUseful-4/Stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ void STREAMShutdown(STREAM *S)
close(S->in_fd);
S->in_fd=-1;
}

S->State=0;
}

Expand Down
18 changes: 9 additions & 9 deletions libUseful-4/String.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,16 @@ void StrLenCacheAdd(const char *Str, size_t len)
StrLenCacheMinLen=100;
}

//is string already in cache?
for (i=0; i < StrLenCacheSize; i++)
//is string already in cache?
for (i=0; i < StrLenCacheSize; i++)
{
if (StrLenCache[i].Str == NULL) emptyslot=i;
else if (StrLenCache[i].Str == Str)
{
if (StrLenCache[i].Str == NULL) emptyslot=i;
else if (StrLenCache[i].Str == Str)
{
StrLenCache[i].len=len;
return;
}
StrLenCache[i].len=len;
return;
}
}

//strlen caching has been seen to give a benefit with very large strings, but modern processors with built-in strlen
//functions are proabably faster.
Expand Down Expand Up @@ -501,7 +501,7 @@ char *VFormatStr(char *InBuff, const char *InputFmtStr, va_list args)
//This is just plain WRONG, it's a long-standing bug. The solution is to
//us va_copy to make a new one every time and pass that in.
va_copy(argscopy,args);
result=vsnprintf(Tempstr,result,FmtStr,argscopy);
result=vsnprintf(Tempstr, result, FmtStr, argscopy);
va_end(argscopy);

/* old style returns -1 to say couldn't fit data into buffer.. so we */
Expand Down
8 changes: 5 additions & 3 deletions xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ void HashRatSetXAttr(HashratCtx *Ctx, const char *Path, struct stat *Stat, const
char **ptr;
int result;

Tempstr=FormatStr(Tempstr,"%llu:%llu:%s",(unsigned long) time(NULL),(unsigned long long) Stat->st_size,Hash);
Tempstr=FormatStr(Tempstr,"%llu:%llu:%s",(unsigned long long) time(NULL), (unsigned long long) Stat->st_size, Hash);


#ifdef USE_XATTR
if ((Ctx->Flags & CTX_XATTR_ROOT) && (getuid()==0)) Attr=MCopyStr(Attr,"trusted.","hashrat:",HashType,NULL);
else Attr=MCopyStr(Attr,"user.","hashrat:",HashType,NULL);

result=setxattr(Path, Attr, Tempstr, StrLen(Tempstr)+1, 0);
if (result != 0) fprintf(stderr,"ERROR: Failed to store hash in extended attributes for %s\n", Path);
if (result != 0) fprintf(stderr,"ERROR: Failed to store hash in extended attributes for '%s' error was '%s'\n", Path, strerror(errno));
#elif defined USE_EXTATTR
Attr=MCopyStr(Attr,"hashrat:",HashType,NULL);
if ((Ctx->Flags & CTX_XATTR_ROOT) && (getuid()==0)) result=extattr_set_file(Path, EXTATTR_NAMESPACE_SYSTEM, Attr, Tempstr, StrLen(Tempstr)+1);
else result=extattr_set_file(Path, EXTATTR_NAMESPACE_USER, Attr, Tempstr, StrLen(Tempstr)+1);
if (result < 1) fprintf(stderr,"ERROR: Failed to store hash in extended attributes for %s\n", Path);
if (result < 1) fprintf(stderr,"ERROR: Failed to store hash in extended attributes for '%s' error was '%s'\n", Path, strerror(errno));
#else
fprintf(stderr,"XATTR Support not compiled in.\n");
exit(1);
Expand Down Expand Up @@ -111,6 +111,8 @@ int XAttrGetHash(HashratCtx *Ctx, const char *XattrType, const char *HashType, c
Tempstr=MCopyStr(Tempstr,"hashrat:",HashType,NULL);
if ((strcmp(XattrType,"trusted")==0) || (strcmp(XattrType,"system")==0)) len=extattr_get_file(Path, EXTATTR_NAMESPACE_SYSTEM, Tempstr, *Hash, 255);
else len=extattr_get_file(Path, EXTATTR_NAMESPACE_USER, Tempstr, *Hash, 255);
#else
fprintf(stderr,"XATTR Support not compiled in.\n");
#endif

if (len > 0)
Expand Down
6 changes: 3 additions & 3 deletions xdialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ STREAM *XDialogDisplayPage(const char *Dialog, HashratCtx *Config)
Cmd=XDialogFormAddList(Cmd, Dialog, "Line Ending", Tempstr, "");
Cmd=XDialogFormAddTextEntry(Cmd, Dialog, "Input");

printf("CMD: %s\n", Cmd);
printf("CMD: %s\n", Cmd);
S=STREAMOpen(Cmd, "rw");

Destroy(Tempstr);
Expand All @@ -115,8 +115,8 @@ void XDialogDisplayHash(const char *DialogCmd, const char *Hash)
STREAM *S;


if (strcmp(GetBasename(DialogCmd), "yad")==0) Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --info --selectable-labels --title='Your Hash Value' --text='", Hash, "'", NULL);
else Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --info --title='Your Hash Value' --text='", Hash, "'", NULL);
if (strcmp(GetBasename(DialogCmd), "yad")==0) Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --info --selectable-labels --title='Your Hash Value' --text='", Hash, "'", NULL);
else Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --info --title='Your Hash Value' --text='", Hash, "'", NULL);
S=STREAMOpen(Cmd, "rw");
Tempstr=STREAMReadLine(Tempstr, S);
STREAMClose(S);
Expand Down

0 comments on commit 0b3c057

Please sign in to comment.