Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Marsaud Smb2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Marsaud Smb2
Commits
83b2fc58
Commit
83b2fc58
authored
Jan 19, 2014
by
Benjamin Chelli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor messages to remove duplicate code
parent
7656a83b
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
148 additions
and
190 deletions
+148
-190
lib/messages/close.js
lib/messages/close.js
+7
-17
lib/messages/create.js
lib/messages/create.js
+8
-17
lib/messages/negotiate.js
lib/messages/negotiate.js
+7
-17
lib/messages/open.js
lib/messages/open.js
+8
-17
lib/messages/query_directory.js
lib/messages/query_directory.js
+11
-19
lib/messages/read.js
lib/messages/read.js
+10
-16
lib/messages/session_setup_step1.js
lib/messages/session_setup_step1.js
+15
-18
lib/messages/session_setup_step2.js
lib/messages/session_setup_step2.js
+7
-19
lib/messages/set_info.js
lib/messages/set_info.js
+7
-17
lib/messages/tree_connect.js
lib/messages/tree_connect.js
+12
-17
lib/messages/write.js
lib/messages/write.js
+10
-16
lib/tools/message.js
lib/tools/message.js
+46
-0
No files found.
lib/messages/close.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
,
params
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
CLOSE
'
...
...
@@ -17,19 +18,8 @@ module.exports = {
,
request
:{
'
FileId
'
:
params
.
FileId
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
});
}
}
});
lib/messages/create.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
,
params
){
var
buffer
=
new
Buffer
(
params
.
path
,
'
ucs2
'
);
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
CREATE
'
...
...
@@ -25,19 +27,8 @@ module.exports = {
,
'
NameOffset
'
:
0x0078
,
'
CreateContextsOffset
'
:
0x007A
+
buffer
.
length
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
,
response
.
getResponse
());
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
});
}
}
});
lib/messages/negotiate.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
NEGOTIATE
'
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
});
}
}
});
lib/messages/open.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
,
params
){
var
buffer
=
new
Buffer
(
params
.
path
,
'
ucs2
'
);
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
CREATE
'
...
...
@@ -20,19 +22,8 @@ module.exports = {
,
'
NameOffset
'
:
0x0078
,
'
CreateContextsOffset
'
:
0x007A
+
buffer
.
length
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
,
response
.
getResponse
());
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
});
}
}
});
lib/messages/query_directory.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
,
params
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
QUERY_DIRECTORY
'
...
...
@@ -18,24 +19,15 @@ module.exports = {
'
FileId
'
:
params
.
FileId
,
'
Buffer
'
:
new
Buffer
(
'
*
'
,
'
ucs2
'
)
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
,
parseFiles
(
response
.
getResponse
().
Buffer
)
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
});
}
,
parseResponse
:
function
(
response
){
return
parseFiles
(
response
.
getResponse
().
Buffer
);
}
}
});
...
...
lib/messages/read.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
,
file
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
READ
'
...
...
@@ -19,19 +20,12 @@ module.exports = {
,
'
Length
'
:
file
.
Length
,
'
Offset
'
:
file
.
Offset
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
,
response
.
getResponse
().
Buffer
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
});
}
,
parseResponse
:
function
(
response
){
return
response
.
getResponse
().
Buffer
;
}
}
});
lib/messages/session_setup_step1.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
,
ntlm
=
require
(
'
ntlm
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
SESSION_SETUP
'
...
...
@@ -19,21 +20,17 @@ module.exports = {
,
connection
.
domain
)
}
})
});
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_MORE_PROCESSING_REQUIRED
'
){
,
successCode
:
'
STATUS_MORE_PROCESSING_REQUIRED
'
,
onSuccess
:
function
(
connection
,
response
){
var
h
=
response
.
getHeaders
();
connection
.
SessionId
=
h
.
SessionId
;
connection
.
nonce
=
ntlm
.
decodeType2
(
response
.
getResponse
().
Buffer
);
cb
&&
cb
(
null
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
}
}
}
);
lib/messages/session_setup_step2.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
,
ntlm
=
require
(
'
ntlm
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
SESSION_SETUP
'
...
...
@@ -23,21 +24,8 @@ module.exports = {
,
connection
.
password
)
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_LOGON_FAILURE
'
){
cb
&&
cb
(
new
Error
(
'
Login attempt fail
'
));
}
else
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
});
}
}
});
lib/messages/set_info.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
...
...
@@ -21,8 +20,10 @@ var fileInfoClasses = {
,
'
FileValidDataLengthInformation
'
:
39
};
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
,
params
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
SET_INFO
'
...
...
@@ -34,19 +35,8 @@ module.exports = {
,
'
FileId
'
:
params
.
FileId
,
'
Buffer
'
:
params
.
Buffer
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
,
response
.
getResponse
());
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
});
}
}
});
lib/messages/tree_connect.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
TREE_CONNECT
'
...
...
@@ -16,20 +17,14 @@ module.exports = {
,
request
:{
'
Buffer
'
:
new
Buffer
(
connection
.
fullPath
,
'
ucs2
'
)
}
})
});
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
,
onSuccess
:
function
(
connection
,
response
){
var
h
=
response
.
getHeaders
();
connection
.
TreeId
=
h
.
TreeId
;
cb
&&
cb
(
null
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
}
}
}
}
);
lib/messages/write.js
View file @
83b2fc58
var
SMB2Message
=
require
(
'
../message
'
)
,
MsErref
=
require
(
'
../tools/ms_erref
'
)
,
bigint
=
require
(
'
../tools/bigint
'
)
,
message
=
require
(
'
../tools/message
'
)
;
module
.
exports
=
{
module
.
exports
=
message
({
generate
:
function
(
connection
,
params
){
return
new
SMB2Message
({
headers
:{
'
Command
'
:
'
WRITE
'
...
...
@@ -19,19 +20,12 @@ module.exports = {
,
'
Offset
'
:
params
.
Offset
,
'
Buffer
'
:
params
.
Buffer
}
})
}
,
parse
:
function
(
connection
,
cb
){
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
'
STATUS_SUCCESS
'
){
cb
&&
cb
(
null
,
response
.
getResponse
().
Buffer
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
});
}
,
parseResponse
:
function
(
response
){
return
response
.
getResponse
().
Buffer
;
}
}
});
lib/tools/message.js
0 → 100644
View file @
83b2fc58
var
MsErref
=
require
(
'
./ms_erref
'
)
,
bigint
=
require
(
'
./bigint
'
)
;
var
defaults
=
{
successCode
:
'
STATUS_SUCCESS
'
,
parse
:
function
(
connection
,
cb
){
var
self
=
this
;
return
function
(
response
){
var
h
=
response
.
getHeaders
()
,
err
=
MsErref
.
getStatus
(
bigint
.
fromBuffer
(
h
.
Status
).
toNumber
())
;
if
(
err
.
code
==
self
.
successCode
){
self
.
onSuccess
&&
self
.
onSuccess
(
connection
,
response
);
cb
&&
cb
(
null
,
self
.
parseResponse
&&
self
.
parseResponse
(
response
)
);
}
else
{
cb
&&
cb
(
new
Error
(
MsErref
.
getErrorMessage
(
err
)));
}
};
}
,
parseResponse
:
function
(
response
){
return
response
.
getResponse
();
}
};
module
.
exports
=
function
(
obj
){
for
(
var
key
in
defaults
)
{
obj
[
key
]
=
obj
[
key
]
||
defaults
[
key
];
}
return
obj
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment