Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
e8f2cdad
Commit
e8f2cdad
authored
20 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
smb_hash() no longer assumes ASCIIZ string (now requires length argument).
Created smb_hashstr() to create hashes of ASCIIZ data.
parent
f6e1bb49
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/smblib/smblib.c
+32
-20
32 additions, 20 deletions
src/smblib/smblib.c
src/smblib/smblib.h
+2
-1
2 additions, 1 deletion
src/smblib/smblib.h
with
34 additions
and
21 deletions
src/smblib/smblib.c
+
32
−
20
View file @
e8f2cdad
...
@@ -2459,17 +2459,37 @@ static char* strip_chars(uchar* str, uchar* set)
...
@@ -2459,17 +2459,37 @@ static char* strip_chars(uchar* str, uchar* set)
/* Allocates and calculates hashes of data (based on flags) */
/* Allocates and calculates hashes of data (based on flags) */
/* Returns NULL on failure */
/* Returns NULL on failure */
hash_t
*
SMBCALL
smb_hash
(
ulong
msgnum
,
ulong
t
,
unsigned
source
,
unsigned
flags
,
uchar
*
data
)
hash_t
*
SMBCALL
smb_hash
(
ulong
msgnum
,
ulong
t
,
unsigned
source
,
unsigned
flags
,
uchar
*
data
,
size_t
length
)
{
{
uchar
*
p
=
data
;
size_t
len
;
hash_t
*
hash
;
hash_t
*
hash
;
if
((
hash
=
(
hash_t
*
)
malloc
(
sizeof
(
hash_t
)))
==
NULL
)
if
((
hash
=
(
hash_t
*
)
malloc
(
sizeof
(
hash_t
)))
==
NULL
)
return
(
NULL
);
return
(
NULL
);
if
(
flags
&~
SMB_HASH_MASK
)
{
/* pre-processing */
hash
->
number
=
msgnum
;
if
((
p
=
strdup
(
data
))
==
NULL
)
hash
->
time
=
t
;
hash
->
source
=
source
;
hash
->
flags
=
flags
;
if
(
flags
&
SMB_HASH_CRC16
)
hash
->
crc16
=
crc16
(
data
,
length
);
if
(
flags
&
SMB_HASH_CRC32
)
hash
->
crc32
=
crc32
(
data
,
length
);
if
(
flags
&
SMB_HASH_MD5
)
MD5_calc
(
hash
->
md5
,
data
,
length
);
return
(
hash
);
}
/* Allocates and calculates hashes of data (based on flags) */
/* Returns NULL on failure */
hash_t
*
SMBCALL
smb_hashstr
(
ulong
msgnum
,
ulong
t
,
unsigned
source
,
unsigned
flags
,
uchar
*
str
)
{
uchar
*
p
=
str
;
hash_t
*
hash
;
if
(
flags
&~
SMB_HASH_MASK
)
{
/* string pre-processing */
if
((
p
=
strdup
(
str
))
==
NULL
)
return
(
NULL
);
return
(
NULL
);
if
(
flags
&
SMB_HASH_UPPERCASE
)
if
(
flags
&
SMB_HASH_UPPERCASE
)
strupr
(
p
);
strupr
(
p
);
...
@@ -2478,24 +2498,16 @@ hash_t* SMBCALL smb_hash(ulong msgnum, ulong t, unsigned source, unsigned flags,
...
@@ -2478,24 +2498,16 @@ hash_t* SMBCALL smb_hash(ulong msgnum, ulong t, unsigned source, unsigned flags,
if
(
flags
&
SMB_HASH_STRIP_WSP
)
if
(
flags
&
SMB_HASH_STRIP_WSP
)
strip_chars
(
p
,
"
\t\r\n
"
);
strip_chars
(
p
,
"
\t\r\n
"
);
}
}
len
=
strlen
(
p
);
hash
->
number
=
msgnum
;
hash
=
smb_hash
(
msgnum
,
t
,
source
,
flags
,
p
,
strlen
(
p
));
hash
->
time
=
t
;
hash
->
source
=
source
;
hash
->
flags
=
flags
;
if
(
flags
&
SMB_HASH_CRC16
)
hash
->
crc16
=
crc16
(
p
,
len
);
if
(
flags
&
SMB_HASH_CRC32
)
hash
->
crc32
=
crc32
(
p
,
len
);
if
(
flags
&
SMB_HASH_MD5
)
MD5_calc
(
hash
->
md5
,
p
,
len
);
if
(
p
!=
data
)
/* duped string */
if
(
p
!=
str
)
/* duped string */
free
(
p
);
free
(
p
);
return
(
hash
);
return
(
hash
);
}
}
/* Allocatese and calculates all hashes for a single message */
/* Allocatese and calculates all hashes for a single message */
/* Returns NULL on failure */
/* Returns NULL on failure */
hash_t
**
SMBCALL
smb_msghashes
(
smb_t
*
smb
,
smbmsg_t
*
msg
,
uchar
*
text
)
hash_t
**
SMBCALL
smb_msghashes
(
smb_t
*
smb
,
smbmsg_t
*
msg
,
uchar
*
text
)
...
@@ -2514,15 +2526,15 @@ hash_t** SMBCALL smb_msghashes(smb_t* smb, smbmsg_t* msg, uchar* text)
...
@@ -2514,15 +2526,15 @@ hash_t** SMBCALL smb_msghashes(smb_t* smb, smbmsg_t* msg, uchar* text)
memset
(
hashes
,
0
,
sizeof
(
hash_t
*
)
*
SMB_MAX_HASH_COUNT
);
memset
(
hashes
,
0
,
sizeof
(
hash_t
*
)
*
SMB_MAX_HASH_COUNT
);
if
(
msg
->
id
!=
NULL
if
(
msg
->
id
!=
NULL
&&
(
hash
=
smb_hash
(
msg
->
hdr
.
number
,
t
,
RFC822MSGID
,
flags
,
msg
->
id
))
!=
NULL
)
&&
(
hash
=
smb_hash
str
(
msg
->
hdr
.
number
,
t
,
RFC822MSGID
,
flags
,
msg
->
id
))
!=
NULL
)
hashes
[
h
++
]
=
hash
;
hashes
[
h
++
]
=
hash
;
if
(
msg
->
ftn_msgid
!=
NULL
if
(
msg
->
ftn_msgid
!=
NULL
&&
(
hash
=
smb_hash
(
msg
->
hdr
.
number
,
t
,
FIDOMSGID
,
flags
,
msg
->
ftn_msgid
))
!=
NULL
)
&&
(
hash
=
smb_hash
str
(
msg
->
hdr
.
number
,
t
,
FIDOMSGID
,
flags
,
msg
->
ftn_msgid
))
!=
NULL
)
hashes
[
h
++
]
=
hash
;
hashes
[
h
++
]
=
hash
;
if
(
text
!=
NULL
if
(
text
!=
NULL
&&
(
hash
=
smb_hash
(
msg
->
hdr
.
number
,
t
,
TEXT_BODY
,
flags
|
SMB_HASH_STRIP_WSP
,
text
))
!=
NULL
)
&&
(
hash
=
smb_hash
str
(
msg
->
hdr
.
number
,
t
,
TEXT_BODY
,
flags
|
SMB_HASH_STRIP_WSP
,
text
))
!=
NULL
)
hashes
[
h
++
]
=
hash
;
hashes
[
h
++
]
=
hash
;
return
(
hashes
);
return
(
hashes
);
...
...
This diff is collapsed.
Click to expand it.
src/smblib/smblib.h
+
2
−
1
View file @
e8f2cdad
...
@@ -164,7 +164,8 @@ SMBEXPORT int SMBCALL smb_updatethread(smb_t* smb, smbmsg_t* remsg, ulong newms
...
@@ -164,7 +164,8 @@ SMBEXPORT int SMBCALL smb_updatethread(smb_t* smb, smbmsg_t* remsg, ulong newms
/* hash-related functions */
/* hash-related functions */
SMBEXPORT
int
SMBCALL
smb_findhash
(
smb_t
*
smb
,
hash_t
**
compare_list
,
hash_t
*
found
);
SMBEXPORT
int
SMBCALL
smb_findhash
(
smb_t
*
smb
,
hash_t
**
compare_list
,
hash_t
*
found
);
SMBEXPORT
int
SMBCALL
smb_hashmsg
(
smb_t
*
smb
,
smbmsg_t
*
msg
,
uchar
*
text
);
SMBEXPORT
int
SMBCALL
smb_hashmsg
(
smb_t
*
smb
,
smbmsg_t
*
msg
,
uchar
*
text
);
SMBEXPORT
hash_t
*
SMBCALL
smb_hash
(
ulong
msgnum
,
ulong
time
,
unsigned
source
,
unsigned
flags
,
uchar
*
str
);
SMBEXPORT
hash_t
*
SMBCALL
smb_hash
(
ulong
msgnum
,
ulong
time
,
unsigned
source
,
unsigned
flags
,
uchar
*
data
,
size_t
length
);
SMBEXPORT
hash_t
*
SMBCALL
smb_hashstr
(
ulong
msgnum
,
ulong
time
,
unsigned
source
,
unsigned
flags
,
uchar
*
str
);
SMBEXPORT
hash_t
**
SMBCALL
smb_msghashes
(
smb_t
*
smb
,
smbmsg_t
*
msg
,
uchar
*
text
);
SMBEXPORT
hash_t
**
SMBCALL
smb_msghashes
(
smb_t
*
smb
,
smbmsg_t
*
msg
,
uchar
*
text
);
SMBEXPORT
int
SMBCALL
smb_addhashes
(
smb_t
*
smb
,
hash_t
**
hash_list
);
SMBEXPORT
int
SMBCALL
smb_addhashes
(
smb_t
*
smb
,
hash_t
**
hash_list
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment