本文整理汇总了C#中Smb2FunctionalClient.SessionSetup方法的典型用法代码示例。如果您正苦于以下问题:C# Smb2FunctionalClient.SessionSetup方法的具体用法?C# Smb2FunctionalClient.SessionSetup怎么用?C# Smb2FunctionalClient.SessionSetup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smb2FunctionalClient
的用法示例。
在下文中一共展示了Smb2FunctionalClient.SessionSetup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BVT_SMB2Basic_CancelRegisteredChangeNotify
public void BVT_SMB2Basic_CancelRegisteredChangeNotify()
{
uint status;
string testDirectory = CreateTestDirectory(TestConfig.SutComputerName, TestConfig.BasicFileShare);
BaseTestSite.Log.Add(
LogEntryKind.Debug,
"Test directory \"{0}\" was created on share \"{1}\"", testDirectory, TestConfig.BasicFileShare);
client1 = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client1.Smb2Client.ChangeNotifyResponseReceived += new Action<FILE_NOTIFY_INFORMATION[],Packet_Header,CHANGE_NOTIFY_Response>(OnChangeNotifyResponseReceived);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a client to create a file by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT; CREATE");
client1.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
status = client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
status = client1.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId1;
status = client1.TreeConnect(uncSharePath, out treeId1);
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileId1;
status = client1.Create(
treeId1,
testDirectory,
CreateOptions_Values.FILE_DIRECTORY_FILE,
out fileId1,
out serverCreateContexts);
BaseTestSite.Log.Add(
LogEntryKind.Comment,
"Client starts to register CHANGE_NOTIFY on directory \"{0}\"", testDirectory);
client1.ChangeNotify(treeId1, fileId1, CompletionFilter_Values.FILE_NOTIFY_CHANGE_LAST_ACCESS);
BaseTestSite.Log.Add(
LogEntryKind.Comment,
"Client starts to cancel the registered CHANGE_NOTIFY on directory \"{0}\"", testDirectory);
client1.Cancel();
BaseTestSite.Assert.IsTrue(
changeNotificationReceived.WaitOne(TestConfig.WaitTimeoutInMilliseconds),
"Change notification should be received within {0} milliseconds", TestConfig.WaitTimeoutInMilliseconds);
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
receivedChangeNotifyHeader.Status, "CHANGE_NOTIFY is not expected to success after cancel, actually server returns {0}.",
Smb2Status.GetStatusCode(receivedChangeNotifyHeader.Status));
BaseTestSite.CaptureRequirementIfAreEqual(
Smb2Status.STATUS_CANCELLED,
receivedChangeNotifyHeader.Status,
RequirementCategory.STATUS_CANCELLED.Id,
RequirementCategory.STATUS_CANCELLED.Description);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF");
client1.Close(treeId1, fileId1);
client1.TreeDisconnect(treeId1);
client1.LogOff();
}
示例2: TriggerBreakFromClient
/// <summary>
/// Attempt to trigger LeaseBreakNotification from a separate client
/// </summary>
/// <param name="client">Client to trigger LeaseBreakNotification</param>
/// <param name="requestDialect">Negotiate dialects</param>
/// <param name="serverName">Name of file server to access</param>
/// <param name="isDirectory">True value indicating to open a directory, false for a file</param>
/// <param name="requestedLeaseState">LeaseState when open the directory or file</param>
/// <param name="accessMask">AccessMask when open the directory or file</param>
private void TriggerBreakFromClient(
Smb2FunctionalClient client,
DialectRevision[] requestDialect,
string serverName,
bool isDirectory,
LeaseStateValues requestedLeaseState,
AccessMask accessMask)
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "AfterFailover: Attempt to access same file/directory to trigger LeaseBreakNotification from a separate client with LeaseState {0} and AccessMask {1}", requestedLeaseState, accessMask);
#region Negotiate
status = client.Negotiate(
requestDialect,
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
checker: (Packet_Header header, NEGOTIATE_Response response) =>
{
TestConfig.CheckNegotiateDialect(DialectRevision.Smb30, response);
});
#endregion
#region SESSION_SETUP
status = client.SessionSetup(
TestConfig.DefaultSecurityPackage,
serverName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
#endregion
#region TREE_CONNECT to share
uint treeId;
status = client.TreeConnect(uncSharePath, out treeId);
#endregion
#region CREATE
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileId;
status = client.Create(
treeId, // To break lease on directory, create a new child item
isDirectory ? testDirectory + @"\child.txt" : fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
new Smb2CreateContextRequest[]
{
new Smb2CreateRequestLeaseV2
{
LeaseKey = Guid.NewGuid(),
LeaseState = requestedLeaseState
}
},
accessMask: accessMask,
shareAccess: ShareAccess_Values.NONE,
checker: (header, response) => { });
#endregion
BaseTestSite.Log.Add(
LogEntryKind.Debug,
"AfterFailover: Finish triggering a LeaseBreakNotification from a separate client.");
}
示例3: Connect
/// <summary>
/// Common method used to connect to target server, including the following message sequences:
/// 1. Negotiate
/// 2. Session Setup
/// 3. Tree Connect
/// </summary>
/// <param name="smb2Dialect"></param>
/// <param name="client"></param>
/// <param name="clientGuid"></param>
/// <param name="account"></param>
/// <param name="connectShareType"></param>
/// <param name="treeId"></param>
/// <param name="clientBeforeDisconnection"></param>
protected virtual void Connect(DialectRevision smb2Dialect, Smb2FunctionalClient client, Guid clientGuid, AccountCredential account, ConnectShareType connectShareType, out uint treeId, Smb2FunctionalClient clientBeforeDisconnection)
{
DialectRevision[] requestDialect = Smb2Utility.GetDialects(smb2Dialect);
Capabilities_Values clientCapabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES;
SecurityMode_Values clientSecurityMode = SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED;
IPAddress targetIPAddress = (connectShareType == ConnectShareType.CAShare) ? testConfig.CAShareServerIP : testConfig.SutIPAddress;
string targetServer = (connectShareType == ConnectShareType.CAShare) ? testConfig.CAShareServerName : testConfig.SutComputerName;
client.ConnectToServer(TestConfig.UnderlyingTransport, targetServer, targetIPAddress);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "The client with clientGuid {0} sends NEGOTIATE request.", clientGuid);
client.Negotiate(
requestDialect,
TestConfig.IsSMB1NegotiateEnabled,
clientSecurityMode,
clientCapabilities,
clientGuid);
if (null != clientBeforeDisconnection)
{
BaseTestSite.Log.Add(LogEntryKind.TestStep, "The client with clientGuid {0} sends SESSION_SETUP request to reconnect to the previous session.", clientGuid);
client.ReconnectSessionSetup(
clientBeforeDisconnection,
testConfig.DefaultSecurityPackage,
targetServer,
account,
testConfig.UseServerGssToken);
}
else
{
BaseTestSite.Log.Add(LogEntryKind.TestStep, "The client with clientGuid {0} sends SESSION_SETUP request.", clientGuid);
client.SessionSetup(
testConfig.DefaultSecurityPackage,
targetServer,
account,
testConfig.UseServerGssToken);
}
BaseTestSite.Log.Add(LogEntryKind.TestStep, "The client with clientGuid {0} sends TREE_CONNECT request.", clientGuid);
client.TreeConnect(
durableHandleUncSharePath,
out treeId,
checker: (header, response) =>
{
BaseTestSite.Log.Add(
LogEntryKind.Debug,
"Capabilities in TREE_CONNECT response: {0}", response.Capabilities);
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"{0} should be successful", header.Command);
if (connectShareType == ConnectShareType.CAShare)
{
BaseTestSite.Assert.AreEqual(
Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY,
Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY & response.Capabilities,
"The share should have SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY capability");
}
if (connectShareType == ConnectShareType.BasicShare)
{
BaseTestSite.Assert.AreNotEqual(
Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY,
Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY & response.Capabilities,
"The share should not have SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY capability");
}
});
}
示例4: ValidateByteLockRangeFromAnotherClient
/// <summary>
/// Read and write file within byte lock range when the file is locked or unlocked
/// </summary>
/// <param name="isLocked">Set true to indicate that byte lock range is taken on the file</param>
/// <param name="serverName">Name of file server to access</param>
/// <param name="targetFileName">Target file name to read and write</param>
private void ValidateByteLockRangeFromAnotherClient(bool isLocked, string serverName, string targetFileName)
{
uint status = 0;
Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client.ConnectToServer(TestConfig.UnderlyingTransport, serverName, currentAccessIp);
status = client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
status = client.SessionSetup(
TestConfig.DefaultSecurityPackage,
serverName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId;
status = client.TreeConnect(uncSharePath, out treeId);
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileId;
status = client.Create(
treeId,
targetFileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out serverCreateContexts);
string data;
Random random = new Random();
uint offset = (uint)random.Next(0, TestConfig.WriteBufferLengthInKb * 1024 - 1);
uint length = (uint)random.Next(0, (int)(TestConfig.WriteBufferLengthInKb * 1024 - offset));
status = client.Read(treeId, fileId, offset, length, out data);
status = client.Write(treeId, fileId, contentWrite, checker: (header, response) => { });
if (isLocked)
{
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Write content to locked range of file from different client is not expected to success");
BaseTestSite.CaptureRequirementIfAreEqual(
Smb2Status.STATUS_FILE_LOCK_CONFLICT,
status,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Id,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Description);
}
else
{
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Write content in file should succeed, actual status is {0}", Smb2Status.GetStatusCode(status));
}
}
示例5: ReconnectOpenRequest
public void ReconnectOpenRequest(
DurableV1ReconnectContext durableV1ReconnectContext,
DurableV2ReconnectContext durableV2ReconnectContext,
OplockLeaseType oplockLeaseType,
LeaseKeyDifferentialType leaseKeyDifferentialType,
ClientIdType clientIdType,
CreateGuidType createGuidType)
{
if ((oplockLeaseType == OplockLeaseType.LeaseV1 || oplockLeaseType == OplockLeaseType.LeaseV2)
&& !testConfig.IsLeasingSupported)
Site.Assert.Inconclusive("Test case is applicable in servers that support leasing.");
bool isSameLeaseKey = (leaseKeyDifferentialType == LeaseKeyDifferentialType.SameLeaseKey);
bool isSameClient = (clientIdType == ClientIdType.SameClient);
bool isSameCreateGuid = (createGuidType == CreateGuidType.SameCreateGuid);
FILEID fileIdAfterDisconnection;
Smb2CreateContextResponse[] serverCreateContexts;
IPAddress targetIPAddress;
string targetServer;
string targetShare;
#region Construct Create Contexts
Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext(
DurableV1RequestContext.DurableV1RequestContextNotExist,
DurableV2RequestContext.DurableV2RequestContextNotExist,
durableV1ReconnectContext,
durableV2ReconnectContext,
oplockLeaseType,
isSameLeaseKey,
isSameCreateGuid);
#endregion
#region Client reconnect to server
Site.Log.Add(LogEntryKind.Debug, "Client reconnect to server");
#region Reconnect to Common Share or CA Share
if (!isCAShare)
{
targetIPAddress = testConfig.SutIPAddress;
targetServer = testConfig.SutComputerName;
targetShare = testConfig.BasicFileShare;
}
else
{
targetIPAddress = testConfig.CAShareServerIP;
targetServer = testConfig.CAShareServerName;
targetShare = testConfig.CAShareName;
}
// Connect to Server
testClientAfterDisconnection = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
testClientAfterDisconnection.CreditGoal = 10;
testClientAfterDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress);
// Negotiate
testClientAfterDisconnection.Negotiate(
requestDialect,
testConfig.IsSMB1NegotiateEnabled,
capabilityValue: clientCapabilities,
// If the reconnect use the same client guid, then keep client guid the same value, otherwise use a new client guid.
clientGuid: (isSameClient ? clientGuid : Guid.NewGuid()));
uint status = testClientAfterDisconnection.SessionSetup(
testConfig.DefaultSecurityPackage,
targetServer,
testConfig.AccountCredential,
testConfig.UseServerGssToken);
Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Reconnect Session Setup should be successful, actual status is {0}", Smb2Status.GetStatusCode(status));
// TreeConnect
testClientAfterDisconnection.TreeConnect(sharePath, out treeIdAfterDisconnection);
#endregion
#region Send Create request according to different context combination
RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
switch (oplockLeaseType)
{
case OplockLeaseType.NoOplockOrLease:
{
requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
}
break;
case OplockLeaseType.BatchOplock:
{
requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
}
break;
case OplockLeaseType.LeaseV1:
case OplockLeaseType.LeaseV2:
{
requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
}
break;
}
//.........这里部分代码省略.........
示例6: InitializeClient
/// <summary>
/// The two client connects to the two IP addresses of scaleout file server
/// Negotiate, SessionSetup, TreeConnect
/// </summary>
private Smb2FunctionalClient InitializeClient(IPAddress ip, out uint treeId)
{
Smb2FunctionalClient client = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
client.ConnectToServerOverTCP(ip);
client.Negotiate(
Smb2Utility.GetDialects(DialectRevision.Smb21),
testConfig.IsSMB1NegotiateEnabled);
client.SessionSetup(
testConfig.DefaultSecurityPackage,
testConfig.ScaleOutFileServerName,
testConfig.AccountCredential,
testConfig.UseServerGssToken);
client.TreeConnect(Smb2Utility.GetUncPath(testConfig.ScaleOutFileServerName, testConfig.CAShareName), out treeId);
return client;
}
示例7: CreateOpenFromClient
/// <summary>
/// Create an open from client, this include NEGOTIATE and SESSION_SETUP with server, TREE_CONNECT to the share and CREATE an open to file/directory
/// </summary>
/// <param name="client">Client used to take the operation</param>
/// <param name="clientGuid">Client GUID for negotiation</param>
/// <param name="targetName">File/directory name for the open</param>
/// <param name="isDirectory">Set true if create open to a directory, set false if create open to a file</param>
/// <param name="accessMask">Desired access when create the open</param>
/// <param name="treeId">Out param for tree id used to connect to the share</param>
/// <param name="fileId">Out param for file id that is associated with the open</param>
/// <param name="shareAccess">Optional param for share access when create the open</param>
/// <returns>Status value returned from CREATE request</returns>
private uint CreateOpenFromClient(Smb2FunctionalClient client, Guid clientGuid, string targetName, bool isDirectory, LeaseStateValues requestLeaseState, AccessMask accessMask, out uint treeId, out FILEID fileId, ShareAccess_Values shareAccess = ShareAccess_Values.FILE_SHARE_DELETE | ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE)
{
#region Negotiate
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client {0} sends NEGOTIATE request with the following capabilities: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES.", clientGuid.ToString());
client.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
clientGuid: clientGuid,
checker: (Packet_Header header, NEGOTIATE_Response response) =>
{
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"Negotiation is expected success, actually server returns {0}", Smb2Status.GetStatusCode(header.Status));
TestConfig.CheckNegotiateDialect(DialectRevision.Smb30, response);
TestConfig.CheckNegotiateCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING, response);
});
#endregion
#region SESSION_SETUP
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client {0} sends SESSION_SETUP request.", clientGuid.ToString());
status = client.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
#endregion
#region TREE_CONNECT to share
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client {0} sends TREE_CONNECT request.", clientGuid.ToString());
status = client.TreeConnect(uncSharePath, out treeId);
#endregion
#region CREATE
Smb2CreateContextResponse[] serverCreateContexts;
CreateOptions_Values createOptions;
if (isDirectory)
{
createOptions = CreateOptions_Values.FILE_DIRECTORY_FILE;
}
else
{
createOptions = CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
}
// Include FILE_DELETE_ON_CLOSE if accessMask has DELETE
if ((accessMask & AccessMask.DELETE) == AccessMask.DELETE)
{
createOptions = createOptions | CreateOptions_Values.FILE_DELETE_ON_CLOSE;
}
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client {0} sends CREATE request with the lease state in SMB2_CREATE_REQUEST_LEASE_V2 set to {1}.", clientGuid.ToString(), requestLeaseState);
status = client.Create(
treeId,
targetName,
createOptions,
out fileId,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
new Smb2CreateContextRequest[]
{
new Smb2CreateRequestLeaseV2
{
LeaseKey = clientGuid,
LeaseState = requestLeaseState
}
},
accessMask: accessMask,
shareAccess: shareAccess,
checker: (header, response) => { });
return status;
#endregion
}
示例8: CreateFile
private void CreateFile(string uncShare, string fileName, int lengthInByte)
{
Site.Log.Add(
LogEntryKind.Debug,
"Create file {0} in share {1}", fileName, uncShare);
Smb2FunctionalClient client = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
client.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress);
client.CreditGoal = 32;
client.Negotiate(
new DialectRevision[] { ModelUtility.GetDialectRevision(config.MaxSmbVersionSupported) },
testConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_LARGE_MTU);
client.SessionSetup(
testConfig.DefaultSecurityPackage,
testConfig.SutComputerName,
testConfig.AccountCredential,
testConfig.UseServerGssToken);
uint tId;
client.TreeConnect(
uncShare,
out tId);
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fId;
client.Create(
tId,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fId,
out serverCreateContexts);
string content;
if (isMultiCreditSupportedOnConnection)
{
content = Smb2Utility.CreateRandomStringInByte(lengthInByte);
client.Write(tId, fId, content);
}
else
{
// Write several times if server does not support multi credit
int writeTimes = lengthInByte / (64 * 1024);
int rest = lengthInByte % (64 * 1024);
ulong offset = 0;
for (int time = 0; time < writeTimes; time++)
{
content = Smb2Utility.CreateRandomString(64);
client.Write(tId, fId, content, offset);
offset += 64 * 1024;
}
if (rest != 0)
{
content = Smb2Utility.CreateRandomStringInByte(rest);
client.Write(tId, fId, content, offset);
}
}
client.Close(tId, fId);
client.TreeDisconnect(tId);
client.LogOff();
client.Disconnect();
Site.Log.Add(
LogEntryKind.Debug,
"Create file {0} in share {1}", fileName, uncShare);
}
示例9: BVT_SMB2Basic_QueryAndSet_FileInfo
public void BVT_SMB2Basic_QueryAndSet_FileInfo()
{
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Starts a client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT.");
client1 = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client1.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
client1.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId1;
client1.TreeConnect(uncSharePath, out treeId1);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with desired access set to GENERIC_READ and GENERIC_WRITE to create a file.");
Smb2CreateContextResponse[] serverCreateContexts;
CREATE_Response? createResponse = null;
string fileName = Guid.NewGuid().ToString() + ".txt";
FILEID fileId1;
client1.Create(
treeId1,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId1,
out serverCreateContexts,
accessMask: AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE,
checker: (Packet_Header header, CREATE_Response response) =>
{
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"CREATE should succeed, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status));
BaseTestSite.Log.Add(LogEntryKind.TestStep,
"FileBasicInformation in CREATE response: \r\nCreationTime: {0}\r\nLastAccessTime:{1}\r\nLastWriteTime: {2}\r\nChangeTime: {3}\r\nFileAttributes: {4}",
Smb2Utility.ConvertToDateTimeUtc(response.CreationTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
Smb2Utility.ConvertToDateTimeUtc(response.LastAccessTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
Smb2Utility.ConvertToDateTimeUtc(response.LastWriteTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
Smb2Utility.ConvertToDateTimeUtc(response.ChangeTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
response.FileAttributes);
createResponse = response;
});
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends QUERY_INFO request to query file attributes.");
byte[] outputBuffer;
client1.QueryFileAttributes(
treeId1,
(byte)FileInformationClasses.FileBasicInformation,
QUERY_INFO_Request_Flags_Values.SL_RESTART_SCAN,
fileId1,
new byte[0] { },
out outputBuffer);
FileBasicInformation fileBasicInfo = TypeMarshal.ToStruct<FileBasicInformation>(outputBuffer);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "FileBasicInformation in QUERY_INFO response: \r\nCreationTime: {0}\r\nLastAccessTime:{1}\r\nLastWriteTime: {2}\r\nChangeTime: {3}\r\nFileAttributes: {4}",
Smb2Utility.ConvertToDateTimeUtc(fileBasicInfo.CreationTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
Smb2Utility.ConvertToDateTimeUtc(fileBasicInfo.LastAccessTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
Smb2Utility.ConvertToDateTimeUtc(fileBasicInfo.LastWriteTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
Smb2Utility.ConvertToDateTimeUtc(fileBasicInfo.ChangeTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"),
fileBasicInfo.FileAttributes);
BaseTestSite.Assert.AreEqual(createResponse.Value.CreationTime, fileBasicInfo.CreationTime, "CreationTime received in QUERY_INFO response should be identical with that got in CREATE response");
BaseTestSite.Assert.AreEqual(createResponse.Value.LastAccessTime, fileBasicInfo.LastAccessTime, "LastAccessTime received in QUERY_INFO response should be identical with that got in CREATE response");
BaseTestSite.Assert.AreEqual(createResponse.Value.LastWriteTime, fileBasicInfo.LastWriteTime, "LastWriteTime received in QUERY_INFO response should be identical with that got in CREATE response");
BaseTestSite.Assert.AreEqual(createResponse.Value.ChangeTime, fileBasicInfo.ChangeTime, "ChangeTime received in QUERY_INFO response should be identical with that got in CREATE response");
BaseTestSite.Assert.AreEqual(createResponse.Value.FileAttributes, fileBasicInfo.FileAttributes, "FileAttributes received in QUERY_INFO response should be identical with that got in CREATE response");
FileBasicInformation fileBasicInfoToSet = fileBasicInfo;
DateTime dateTimeToSet = DateTime.UtcNow;
fileBasicInfoToSet.LastAccessTime = Smb2Utility.ConvertToFileTime(dateTimeToSet);
byte[] inputBuffer;
inputBuffer = TypeMarshal.ToBytes<FileBasicInformation>(fileBasicInfoToSet);
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client sends SetFileAttributes request to set LastAccessTime for the file to {0}", dateTimeToSet.ToString("MM/dd/yyy hh:mm:ss.ffffff"));
client1.SetFileAttributes(
treeId1,
(byte)FileInformationClasses.FileBasicInformation,
fileId1,
inputBuffer);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends QUERY request to query file attributes.");
client1.QueryFileAttributes(
treeId1,
(byte)FileInformationClasses.FileBasicInformation,
QUERY_INFO_Request_Flags_Values.SL_RESTART_SCAN,
fileId1,
new byte[0] { },
out outputBuffer);
fileBasicInfo = TypeMarshal.ToStruct<FileBasicInformation>(outputBuffer);
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"LastAccessTime in QUERY_INFO response after SET_INFO {0}",
Smb2Utility.ConvertToDateTimeUtc(fileBasicInfo.LastAccessTime).ToString("MM/dd/yyy hh:mm:ss.ffffff"));
BaseTestSite.Assert.AreNotEqual(
createResponse.Value.LastAccessTime,
fileBasicInfo.LastAccessTime,
"LastAccessTime (dwHighDateTime:{0}, dwLowDateTime:{1}) after SET_INFO should not be equal to the value (dwHighDateTime:{2}, dwLowDateTime:{3}) before SET_INFO",
//.........这里部分代码省略.........
示例10: BVT_SMB2Basic_LockAndUnLock
public void BVT_SMB2Basic_LockAndUnLock()
{
uint status;
string content = Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb);
#region From client1 lock a byte range and try to write content to the file within the range
BaseTestSite.Log.Add(
LogEntryKind.Comment,
"From client1 locks a byte range and try to write content to the file within the range.");
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Start client1 to create a file with sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT; CREATE.");
client1 = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client1.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
status = client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
status = client1.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId1;
status = client1.TreeConnect(uncSharePath, out treeId1);
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileId1;
string fileName = Guid.NewGuid().ToString() + ".txt";
status = client1.Create(
treeId1,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId1,
out serverCreateContexts);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client1 writes content to the file created.");
status = client1.Write(treeId1, fileId1, content);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down client1 by sending CLOSE request.");
client1.Close(treeId1, fileId1);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client1 sends CREATE request.");
status = client1.Create(
treeId1,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId1,
out serverCreateContexts);
//Construct LOCK_ELEMENT
LOCK_ELEMENT[] locks = new LOCK_ELEMENT[1];
uint lockSequence = 0;
locks[0].Offset = 0;
locks[0].Length = (ulong)TestConfig.WriteBufferLengthInKb * 1024;
locks[0].Flags = LOCK_ELEMENT_Flags_Values.LOCKFLAG_SHARED_LOCK;
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client1 starts to lock a byte range for file \"{0}\" with parameters offset:{1}, length:{2}, flags: {3})",
fileName, locks[0].Offset, locks[0].Length, locks[0].Flags.ToString());
status = client1.Lock(treeId1, lockSequence++, fileId1, locks);
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client1 sends WRITE request to write content to the locking range");
status = client1.Write(
treeId1,
fileId1,
content,
checker: (header, response) =>
{
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"All opens MUST NOT be allowed to write within the range when SMB2_LOCKFLAG_SHARED_LOCK set, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status));
BaseTestSite.CaptureRequirementIfAreEqual(
Smb2Status.STATUS_FILE_LOCK_CONFLICT,
header.Status,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Id,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Description);
});
#endregion
#region From client2 to read and write the locking range of the same file after lock
BaseTestSite.Log.Add(
LogEntryKind.Comment,
"From client2 to read and take shared lock on the locking range of the same file after lock");
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Start client2 to create a file with sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT; CREATE.");
client2 = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client2.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
status = client2.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
status = client2.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId2;
status = client2.TreeConnect(uncSharePath, out treeId2);
FILEID fileId2;
//.........这里部分代码省略.........
示例11: ConnectToShare
private void ConnectToShare(Smb2FunctionalClient client, Guid clientGuid, string uncShareName, out uint treeId)
{
client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.FileServerNameContainingSharedVHD, TestConfig.FileServerIPContainingSharedVHD);
client.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled,
SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED,
Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
clientGuid);
client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
client.TreeConnect(uncShareName, out treeId);
}
示例12: AccessShare
protected bool AccessShare(AccountCredential user, string sharePath)
{
bool accessSucceed = true;
Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
try
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends NEGOTIATE message.");
client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends SESSION_SETUP message using account: {0}@{1}.", user.AccountName, user.DomainName);
client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, user, false);
uint treeId;
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends TREE_CONNECT message to access share: {0}.", sharePath);
client.TreeConnect(sharePath, out treeId, checker: (header, response) =>
{
if (header.Status == Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "Access succeeded in TREE_CONNECT phase.");
accessSucceed = true;
}
else if (header.Status == Smb2Status.STATUS_ACCESS_DENIED)
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "Access denied in TREE_CONNECT phase.");
accessSucceed = false;
}
else
{
BaseTestSite.Assert.Fail("Unexpected error code in TREE_CONNECT response: {0}", Smb2Status.GetStatusCode(header.Status));
}
});
if (!accessSucceed)
{
client.LogOff();
return false;
}
FILEID fileId;
Smb2CreateContextResponse[] createContexResponse;
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends CREATE request.");
uint status = client.Create(
treeId,
null,
CreateOptions_Values.FILE_DIRECTORY_FILE,
out fileId,
out createContexResponse,
accessMask: AccessMask.FILE_READ_DATA | AccessMask.FILE_READ_ATTRIBUTES,
createDisposition: CreateDisposition_Values.FILE_OPEN,
checker: (header, response) =>
{
if (header.Status == Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "Access succeeded in CREATE phase.");
accessSucceed = true;
}
else if (header.Status == Smb2Status.STATUS_ACCESS_DENIED)
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "Access denied in CREATE phase.");
accessSucceed = false;
}
else
{
BaseTestSite.Assert.Fail("Unexpected error code in CREATE response: {0}", Smb2Status.GetStatusCode(header.Status));
}
});
if (status == Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF.");
client.Close(treeId, fileId);
}
client.TreeDisconnect(treeId);
client.LogOff();
}
finally
{
client.Disconnect();
}
return accessSucceed;
}
示例13: ConnectToShare
protected bool ConnectToShare(Smb2FunctionalClient client, AccountCredential user, string sharePath, out uint treeId)
{
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends NEGOTIATE message.");
client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
AccountCredential accountCredential = user;
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends SESSION_SETUP message using account: {0}@{1}.", accountCredential.AccountName, accountCredential.DomainName);
client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, accountCredential, false);
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends TREE_CONNECT message to access share: {0}.", sharePath);
uint status = client.TreeConnect(sharePath, out treeId, checker: (header, response) => { });
if (status == Smb2Status.STATUS_SUCCESS)
{
return true;
}
if (status == Smb2Status.STATUS_BAD_NETWORK_NAME)
{
return false;
}
throw new Exception(string.Format("Share detection failed with unexpected error: {0}", Smb2Status.GetStatusCode(status)));
}
示例14: ConnectToShare
private void ConnectToShare(Smb2FunctionalClient client, out uint treeId)
{
client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
client.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_ENCRYPTION); // To enable encryption later.
client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
client.TreeConnect(Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare), out treeId);
}
示例15: ConnectToShare
private void ConnectToShare(
Smb2FunctionalClient client,
Guid clientGuid,
out uint treeId)
{
client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.CAShareServerName, TestConfig.CAShareServerIP);
// Negotiate
client.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
clientGuid: clientGuid,
checker: (header, response) =>
{
BaseTestSite.Assert.AreEqual<NtStatus>(
NtStatus.STATUS_SUCCESS,
(NtStatus)header.Status,
"Negotiate should be successfully");
TestConfig.CheckNegotiateDialect(DialectRevision.Smb30, response);
TestConfig.CheckNegotiateCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES, response);
}
);
// SMB2 SESSION SETUP
client.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.CAShareServerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
// SMB2 Tree Connect
client.TreeConnect(
Smb2Utility.GetUncPath(TestConfig.CAShareServerName, TestConfig.CAShareName),
out treeId,
checker: (header, response) =>
{
BaseTestSite.Assert.AreEqual<NtStatus>(
NtStatus.STATUS_SUCCESS,
(NtStatus)header.Status,
"TreeConnect should be successfully");
// Check IsCA
BaseTestSite.Assert.IsTrue(
response.Capabilities.HasFlag(Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY),
"Share should support capabilities of SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY ");
});
}