-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land #233, add ms-dfsnm defs and functions
- Loading branch information
Showing
15 changed files
with
390 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module RubySMB | ||
module Dcerpc | ||
module Dfsnm | ||
|
||
UUID = '4fc742e0-4a10-11cf-8273-00aa004ae673' | ||
VER_MAJOR = 3 | ||
VER_MINOR = 0 | ||
|
||
# Operation numbers | ||
NETR_DFS_ADD_STD_ROOT = 0x000c | ||
NETR_DFS_REMOVE_STD_ROOT = 0x000d | ||
|
||
require 'ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_request' | ||
require 'ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_response' | ||
require 'ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_request' | ||
require 'ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_response' | ||
|
||
# Create a new stand-alone DFS namespace. | ||
# | ||
# @param server_name [String] The host name of the DFS root target. | ||
# @param root_share [String] The DFS root target share name. | ||
# @param comment [String] A comment associated with the DFS namespace. | ||
# @return nothing is returned on success | ||
# @raise [RubySMB::Dcerpc::Error::InvalidPacket] if the response is not a | ||
# NetrDfsAddStdRootResponse packet | ||
# @raise [RubySMB::Dcerpc::Error::DfsnmError] if the response error status | ||
# is not ERROR_SUCCESS | ||
def netr_dfs_add_std_root(server_name, root_share, comment: '') | ||
netr_dfs_add_std_root_request = NetrDfsAddStdRootRequest.new( | ||
server_name: server_name, | ||
root_share: root_share, | ||
comment: comment | ||
) | ||
response = dcerpc_request(netr_dfs_add_std_root_request) | ||
begin | ||
netr_dfs_add_std_root_response = NetrDfsAddStdRootResponse.read(response) | ||
rescue IOError | ||
raise RubySMB::Dcerpc::Error::InvalidPacket, 'Error reading NetrDfsAddStdRootResponse' | ||
end | ||
unless netr_dfs_add_std_root_response.error_status == WindowsError::Win32::ERROR_SUCCESS | ||
status_code = WindowsError::Win32.find_by_retval(netr_dfs_add_std_root_response.error_status.value).first | ||
raise RubySMB::Dcerpc::Error::DfsnmError.new( | ||
"Error returned with netr_dfs_add_std_root: #{status_code}", | ||
status_code: status_code | ||
) | ||
end | ||
|
||
nil | ||
end | ||
|
||
# Delete the specified stand-alone DFS namespace. | ||
# | ||
# @param server_name [String] The host name of the DFS root target. | ||
# @param root_share [String] The DFS root target share name. | ||
# @return nothing is returned on success | ||
# @raise [RubySMB::Dcerpc::Error::InvalidPacket] if the response is not a | ||
# NetrDfsRemoveStdRootResponse packet | ||
# @raise [RubySMB::Dcerpc::Error::DfsnmError] if the response error status | ||
# is not ERROR_SUCCESS | ||
def netr_dfs_remove_std_root(server_name, root_share) | ||
netr_dfs_remove_std_root_request = NetrDfsRemoveStdRootRequest.new( | ||
server_name: server_name, | ||
root_share: root_share | ||
) | ||
response = dcerpc_request(netr_dfs_remove_std_root_request) | ||
begin | ||
netr_dfs_remove_std_root_response = NetrDfsRemoveStdRootResponse.read(response) | ||
rescue IOError | ||
raise RubySMB::Dcerpc::Error::InvalidPacket, 'Error reading NetrDfsRemoveStdRootResponse' | ||
end | ||
unless netr_dfs_remove_std_root_response.error_status == WindowsError::Win32::ERROR_SUCCESS | ||
status_code = WindowsError::Win32.find_by_retval(netr_dfs_remove_std_root_response.error_status.value).first | ||
raise RubySMB::Dcerpc::Error::DfsnmError.new( | ||
"Error returned with netr_dfs_remove_std_root: #{status_code}", | ||
status_code: status_code | ||
) | ||
end | ||
|
||
nil | ||
end | ||
|
||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_request.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module RubySMB | ||
module Dcerpc | ||
module Dfsnm | ||
|
||
# [3.1.4.4.1 NetrDfsAddStdRoot (Opnum 12)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dfsnm/b18ef17a-7a9c-4e22-b1bf-6a4d07e87b2d) | ||
class NetrDfsAddStdRootRequest < BinData::Record | ||
attr_reader :opnum | ||
|
||
endian :little | ||
|
||
ndr_conf_var_wide_stringz :server_name | ||
ndr_conf_var_wide_stringz :root_share | ||
ndr_conf_var_wide_stringz :comment | ||
ndr_uint32 :api_flags | ||
|
||
def initialize_instance | ||
super | ||
@opnum = NETR_DFS_ADD_STD_ROOT | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_response.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module RubySMB | ||
module Dcerpc | ||
module Dfsnm | ||
|
||
# [3.1.4.4.1 NetrDfsAddStdRoot (Opnum 12)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dfsnm/b18ef17a-7a9c-4e22-b1bf-6a4d07e87b2d) | ||
class NetrDfsAddStdRootResponse < BinData::Record | ||
attr_reader :opnum | ||
|
||
endian :little | ||
|
||
ndr_uint32 :error_status | ||
|
||
def initialize_instance | ||
super | ||
@opnum = NETR_DFS_ADD_STD_ROOT | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_request.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module RubySMB | ||
module Dcerpc | ||
module Dfsnm | ||
|
||
# [3.1.4.4.2 NetrDfsRemoveStdRoot (Opnum 13)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dfsnm/e9da023d-554a-49bc-837a-69f22d59fd18) | ||
class NetrDfsRemoveStdRootRequest < BinData::Record | ||
attr_reader :opnum | ||
|
||
endian :little | ||
|
||
ndr_conf_var_wide_stringz :server_name | ||
ndr_conf_var_wide_stringz :root_share | ||
ndr_uint32 :api_flags | ||
|
||
def initialize_instance | ||
super | ||
@opnum = NETR_DFS_REMOVE_STD_ROOT | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_response.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module RubySMB | ||
module Dcerpc | ||
module Dfsnm | ||
|
||
# [3.1.4.4.2 NetrDfsRemoveStdRoot (Opnum 13)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dfsnm/e9da023d-554a-49bc-837a-69f22d59fd18) | ||
class NetrDfsRemoveStdRootResponse < BinData::Record | ||
attr_reader :opnum | ||
|
||
endian :little | ||
|
||
ndr_uint32 :error_status | ||
|
||
def initialize_instance | ||
super | ||
@opnum = NETR_DFS_REMOVE_STD_ROOT | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_request_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
RSpec.describe RubySMB::Dcerpc::Dfsnm::NetrDfsAddStdRootRequest do | ||
subject(:packet) { described_class.new } | ||
|
||
it { is_expected.to respond_to :server_name } | ||
it { is_expected.to respond_to :root_share } | ||
it { is_expected.to respond_to :comment } | ||
it { is_expected.to respond_to :api_flags } | ||
it { is_expected.to respond_to :opnum } | ||
|
||
it 'is little endian' do | ||
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little | ||
end | ||
it 'is a BinData::Record' do | ||
expect(packet).to be_a(BinData::Record) | ||
end | ||
describe '#server_name' do | ||
it 'is a NdrConfVarWideStringz structure' do | ||
expect(packet.server_name).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz | ||
end | ||
end | ||
describe '#root_share' do | ||
it 'is a NdrConfVarWideStringz structure' do | ||
expect(packet.root_share).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz | ||
end | ||
end | ||
describe '#comment' do | ||
it 'is a NdrConfVarWideStringz structure' do | ||
expect(packet.comment).to be_a RubySMB::Dcerpc::Ndr::NdrConfVarWideStringz | ||
end | ||
end | ||
describe '#api_flags' do | ||
it 'is a NdrUint32 structure' do | ||
expect(packet.api_flags).to be_a RubySMB::Dcerpc::Ndr::NdrUint32 | ||
end | ||
end | ||
describe '#initialize_instance' do | ||
it 'sets #opnum to NETR_DFS_ADD_STD_ROOT constant' do | ||
expect(packet.opnum).to eq(RubySMB::Dcerpc::Dfsnm::NETR_DFS_ADD_STD_ROOT) | ||
end | ||
end | ||
it 'reads itself' do | ||
new_packet = described_class.new({ | ||
server_name: 'serverName', | ||
root_share: 'rootShare', | ||
comment: 'comment' | ||
}) | ||
expected_output = { | ||
server_name: 'serverName'.encode('utf-16le'), | ||
root_share: 'rootShare'.encode('utf-16le'), | ||
comment: 'comment'.encode('utf-16le'), | ||
api_flags: 0 | ||
} | ||
expect(packet.read(new_packet.to_binary_s)).to eq(expected_output) | ||
end | ||
end | ||
|
||
|
34 changes: 34 additions & 0 deletions
34
spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_response_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
RSpec.describe RubySMB::Dcerpc::Dfsnm::NetrDfsAddStdRootResponse do | ||
subject(:packet) { described_class.new } | ||
|
||
it { is_expected.to respond_to :error_status } | ||
it { is_expected.to respond_to :opnum } | ||
|
||
it 'is little endian' do | ||
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little | ||
end | ||
it 'is a BinData::Record' do | ||
expect(packet).to be_a(BinData::Record) | ||
end | ||
describe '#error_status' do | ||
it 'is a NdrUint32 structure' do | ||
expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32 | ||
end | ||
end | ||
describe '#initialize_instance' do | ||
it 'sets #opnum to NETR_DFS_ADD_STD_ROOT constant' do | ||
expect(packet.opnum).to eq(RubySMB::Dcerpc::Dfsnm::NETR_DFS_ADD_STD_ROOT) | ||
end | ||
end | ||
it 'reads itself' do | ||
new_packet = described_class.new({ | ||
error_status: 0 | ||
}) | ||
expected_output = { | ||
error_status: 0 | ||
} | ||
expect(packet.read(new_packet.to_binary_s)).to eq(expected_output) | ||
end | ||
end | ||
|
||
|
Oops, something went wrong.