本文整理汇总了C#中Smb2FunctionalClient.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Smb2FunctionalClient.Close方法的具体用法?C# Smb2FunctionalClient.Close怎么用?C# Smb2FunctionalClient.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smb2FunctionalClient
的用法示例。
在下文中一共展示了Smb2FunctionalClient.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BVT_SMB2Basic_QueryAndSet_FileInfo
//.........这里部分代码省略.........
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",
fileBasicInfo.LastAccessTime.dwHighDateTime, fileBasicInfo.LastAccessTime.dwLowDateTime, createResponse.Value.LastAccessTime.dwHighDateTime, createResponse.Value.LastAccessTime.dwLowDateTime);
BaseTestSite.Assert.AreEqual(
fileBasicInfoToSet.LastAccessTime,
fileBasicInfo.LastAccessTime,
"LastAccessTime (dwHighDateTime:{0}, dwLowDateTime:{1}) queried after SET_INFO should be equal to the desired value (dwHighDateTime:{2}, dwLowDateTime:{3})",
fileBasicInfo.LastAccessTime.dwHighDateTime, fileBasicInfo.LastAccessTime.dwLowDateTime, fileBasicInfoToSet.LastAccessTime.dwHighDateTime, fileBasicInfoToSet.LastAccessTime.dwLowDateTime);
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: 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();
}
示例3: ReconnectSharedVHDWithoutDeviceContext
public void ReconnectSharedVHDWithoutDeviceContext()
{
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"1. Client opens a shared virtual disk file with SMB2 create contexts " +
"SVHDX_OPEN_DEVICE_CONTEXT and SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 (persistent bit is set). ");
Smb2FunctionalClient clientBeforeDisconnect = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
uint treeId;
Guid clientGuid = Guid.NewGuid();
ConnectToShare(clientBeforeDisconnect, clientGuid, TestConfig.FullPathShareContainingSharedVHD, out treeId);
Guid createGuid = Guid.NewGuid();
Guid initiatorId = Guid.NewGuid();
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileIdBeforeDisconnect;
clientBeforeDisconnect.Create
(treeId,
TestConfig.NameOfSharedVHDX + fileNameSuffix,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileIdBeforeDisconnect,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
new Smb2CreateContextRequest[]
{
new Smb2CreateSvhdxOpenDeviceContext
{
Version = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1,
OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
InitiatorHostName = TestConfig.InitiatorHostName,
InitiatorHostNameLength = (ushort)(TestConfig.InitiatorHostName.Length * 2), // InitiatorHostName is a null-terminated Unicode UTF-16 string
InitiatorId = initiatorId
},
new Smb2CreateDurableHandleRequestV2
{
CreateGuid = createGuid,
Flags = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT
}
});
bool persistentHandleReturned = false;
if (serverCreateContexts != null && serverCreateContexts[0] is Smb2CreateDurableHandleResponseV2)
{
var durableResponse = serverCreateContexts[0] as Smb2CreateDurableHandleResponseV2;
if (durableResponse.Flags.HasFlag(CREATE_DURABLE_HANDLE_RESPONSE_V2_Flags.DHANDLE_FLAG_PERSISTENT))
{
persistentHandleReturned = true;
}
}
BaseTestSite.Assert.IsTrue(persistentHandleReturned, "Server should return a persistent handle.");
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"2. Client disconnects from the server.");
clientBeforeDisconnect.Disconnect();
Smb2FunctionalClient clientAfterDisconnect = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
ConnectToShare(clientAfterDisconnect, clientGuid, TestConfig.FullPathShareContainingSharedVHD, out treeId);
FILEID fileIdAfterDisconnect;
uint status = clientAfterDisconnect.Create
(treeId,
TestConfig.NameOfSharedVHDX + fileNameSuffix,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileIdAfterDisconnect,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
new Smb2CreateContextRequest[]
{
new Smb2CreateDurableHandleReconnectV2
{
CreateGuid = createGuid,
Flags = CREATE_DURABLE_HANDLE_RECONNECT_V2_Flags.DHANDLE_FLAG_PERSISTENT,
FileId = new FILEID { Persistent = fileIdBeforeDisconnect.Persistent }
}
},
checker: (header, response) => { });
BaseTestSite.Assert.AreEqual(
(uint)Smb2Status.STATUS_SUCCESS,
status,
"3. Client reconnects the persistent handle without create context SVHDX_OPEN_DEVICE_CONTEXT and expects success. Actual status is: {0}",
GetStatus(status));
clientAfterDisconnect.Close(treeId, fileIdAfterDisconnect);
clientAfterDisconnect.TreeDisconnect(treeId);
clientAfterDisconnect.LogOff();
clientAfterDisconnect.Disconnect();
}
示例4: 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;
//.........这里部分代码省略.........
示例5: OperateFileOrDirectory
/// <summary>
/// Create or delete a file or directory with a given name.
/// </summary>
/// <param name="client">the functional client used to create</param>
/// <param name="isDirectory">true for file and false for directory</param>
/// <param name="isDeleteFlagSet">true for delete flag set</param>
/// <param name="isNonAdmin">true for non admin account credential</param>
/// <param name="fileNametype">the file name type: ValidFileName, SymbolicLinkInMiddle, SymbolicLinkAtLast, InvalidSymbolicLink</param>
/// <param name="isValidAccessMask">true for valid access mask, which should contain DELETE or GENERIC_ALL</param>
private void OperateFileOrDirectory(Smb2FunctionalClient client, bool isDirectory, bool isDeleteFlagSet, bool isNonAdmin, FileNameType fileNameType, bool isValidAccessMask)
{
CreateOptions_Values createOption;
CreateDisposition_Values createDisposition;
if (isDirectory)
{
createOption = CreateOptions_Values.FILE_DIRECTORY_FILE;
}
else
{
createOption = CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
}
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT.");
client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
AccountCredential accountCredential = isNonAdmin ? TestConfig.NonAdminAccountCredential : TestConfig.AccountCredential;
client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, accountCredential, false);
uint treeId;
client.TreeConnect(sharePath, out treeId);
FILEID fileId;
Smb2CreateContextResponse[] createContextResponse;
AccessMask accessMask = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE;
accessMask = isValidAccessMask ? accessMask : AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE;
// The delete flag is set in the following situations: 1. Delete an existed file; 2. Test CreateOptions_Values.FILE_DELETE_ON_CLOSE combined with DesiredAccess
createOption = isDeleteFlagSet ? (createOption | CreateOptions_Values.FILE_DELETE_ON_CLOSE) : createOption;
// The createDisposition is set to FILE_OPEN if the file already existed; else, if it's the first time to create a file, this field should be set to FILE_CREATE
createDisposition = (fileNameType == FileNameType.ExistedValidFileName) ? CreateDisposition_Values.FILE_OPEN : CreateDisposition_Values.FILE_CREATE;
fileName = GetFileName(isDirectory, fileNameType);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with create option: {0} and create disposition: {1}", createOption, createDisposition);
uint status = client.Create(
treeId,
fileName,
createOption,
out fileId,
out createContextResponse,
accessMask: accessMask,
createDisposition: createDisposition,
checker: (header, response) =>
{
CheckCreateResponse(isNonAdmin, createOption, accessMask, header, response, fileNameType);
});
if (status == Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF.");
client.Close(treeId, fileId);
}
client.TreeDisconnect(treeId);
client.LogOff();
}
示例6: 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;
}
示例7: CreateNewFile
protected void CreateNewFile(string sharePath, string fileName)
{
Smb2FunctionalClient clientAdmin;
clientAdmin = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
clientAdmin.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
uint treeId;
ConnectToShare(clientAdmin, TestConfig.AccountCredential, sharePath, out treeId);
FILEID fileId;
Smb2CreateContextResponse[] createContextResponses;
clientAdmin.Create(
treeId,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out createContextResponses,
accessMask: AccessMask.FILE_READ_DATA | AccessMask.FILE_WRITE_DATA |
AccessMask.FILE_APPEND_DATA | AccessMask.FILE_READ_EA |
AccessMask.FILE_WRITE_EA | AccessMask.READ_CONTROL |
AccessMask.WRITE_DAC | AccessMask.FILE_READ_ATTRIBUTES |
AccessMask.FILE_WRITE_ATTRIBUTES | AccessMask.SYNCHRONIZE,
shareAccess: ShareAccess_Values.NONE,
createDisposition: CreateDisposition_Values.FILE_CREATE);
clientAdmin.Close(treeId, fileId);
clientAdmin.TreeDisconnect(treeId);
clientAdmin.Disconnect();
}
示例8: DirectoryLeasing_BreakHandleCachingByParentDeleted
public void DirectoryLeasing_BreakHandleCachingByParentDeleted()
{
#region Prepare test directory
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Create test directory.");
uncSharePath = Smb2Utility.GetUncPath(TestConfig.SutComputerName, TestConfig.BasicFileShare);
string parentDirectory = "ParentDirectory_" + Guid.NewGuid().ToString();
sutProtocolController.CreateDirectory(uncSharePath, parentDirectory);
testDirectory = CreateTestDirectory(TestConfig.SutComputerName, TestConfig.BasicFileShare + "\\" + parentDirectory);
#endregion
#region Initialize test clients
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Initialize test clients.");
Guid clientGuidRequestingLease = Guid.NewGuid();
Smb2FunctionalClient clientRequestingLease = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
Guid clientGuidTriggeringBreak = Guid.NewGuid();
Smb2FunctionalClient clientTriggeringBreak = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
clientRequestingLease.Smb2Client.LeaseBreakNotificationReceived +=
new Action<Packet_Header, LEASE_BREAK_Notification_Packet>(base.OnLeaseBreakNotificationReceived);
clientRequestingLease.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
clientTriggeringBreak.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
#endregion
#region CREATE an open to request lease
uint treeIdClientRequestingLease;
FILEID fileIdClientRequestingLease;
string targetName = parentDirectory + "\\" + testDirectory;
LeaseStateValues requestedLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING;
// Add expected NewLeaseState
expectedNewLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING;
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client attempts to request lease {0} on directory {1}", requestedLeaseState, testDirectory);
status = CreateOpenFromClient(clientRequestingLease, clientGuidRequestingLease, targetName, true, requestedLeaseState, AccessMask.GENERIC_READ, out treeIdClientRequestingLease, out fileIdClientRequestingLease);
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Create an open to {0} should succeed, actual status is {1}", testDirectory, Smb2Status.GetStatusCode(status));
#endregion
// Create a timer that signals the delegate to invoke CheckBreakNotification
Timer timer = new Timer(base.CheckBreakNotification, treeIdClientRequestingLease, 0, Timeout.Infinite);
base.clientToAckLeaseBreak = clientRequestingLease;
#region Attempt to trigger lease break by deleting parent directory
uint treeIdClientTriggeringBreak;
FILEID fileIdClientTriggeringBreak;
AccessMask accessMaskTrigger = AccessMask.DELETE;
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"A separate client attempts to trigger lease break by deleting its parent directory");
status = CreateOpenFromClient(clientTriggeringBreak, clientGuidTriggeringBreak, parentDirectory, true, LeaseStateValues.SMB2_LEASE_NONE, accessMaskTrigger, out treeIdClientTriggeringBreak, out fileIdClientTriggeringBreak);
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Create an open to {0} should succeed", parentDirectory);
#region set FileDispositionInformation for deletion
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Set FileDispositionInformation for deletion.");
FileDispositionInformation fileDispositionInfo;
fileDispositionInfo.DeletePending = 1; // Set 1 to indicate directory SHOULD be delted when the open closed
byte[] inputBuffer = TypeMarshal.ToBytes<FileDispositionInformation>(fileDispositionInfo);
status = clientTriggeringBreak.SetFileAttributes(
treeIdClientTriggeringBreak,
(byte)FileInformationClasses.FileDispositionInformation,
fileIdClientTriggeringBreak,
inputBuffer,
(header, response) =>
{
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"Setting FileDispositionInformation to the parent directory for deletion when child is opened by others is not expected to SUCCESS. " +
"Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
BaseTestSite.CaptureRequirementIfAreEqual(
Smb2Status.STATUS_DIRECTORY_NOT_EMPTY,
header.Status,
RequirementCategory.STATUS_DIRECTORY_NOT_EMPTY.Id,
RequirementCategory.STATUS_DIRECTORY_NOT_EMPTY.Description);
});
status = clientTriggeringBreak.Close(treeIdClientTriggeringBreak, fileIdClientTriggeringBreak);
#endregion
#region CREATE an open to parent directory again
BaseTestSite.Log.Add(LogEntryKind.TestStep, "CREATE an open to parent directory again.");
// Currently we need an additional CREATE to open the parent directory to trigger the lease break
// which is the same way when Windows attempt to delete the parent directory when child is opened by others
Smb2CreateContextResponse[] serverCreateContexts;
status = clientTriggeringBreak.Create(
treeIdClientTriggeringBreak,
targetName,
CreateOptions_Values.FILE_DIRECTORY_FILE | CreateOptions_Values.FILE_DELETE_ON_CLOSE,
out fileIdClientTriggeringBreak,
//.........这里部分代码省略.........
示例9: AppInstanceIdTest
//.........这里部分代码省略.........
TestConfig.UseServerGssToken);
uint treeIdForReOpen;
clientForReOpen.TreeConnect(sharePath, out treeIdForReOpen);
FILEID fileIdForReOpen;
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"The second client sends CREATE request for exclusive open with the {0} SMB2_CREATE_APP_INSTANCE_ID of the first client.", sameAppInstanceId ? "same" : "different");
Smb2CreateContextRequest[] createContextsRequestForReOpen = null;
if (containCreateDurableContext)
{
BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is also included in the CREATE request.");
createContextsRequestForReOpen = new Smb2CreateContextRequest[] {
new Smb2CreateDurableHandleRequestV2
{
CreateGuid = Guid.NewGuid()
},
new Smb2CreateAppInstanceId
{
AppInstanceId = sameAppInstanceId ? appInstanceId : Guid.NewGuid()
}
};
}
else
{
BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is not included in the CREATE request.");
createContextsRequestForReOpen = new Smb2CreateContextRequest[] {
new Smb2CreateAppInstanceId
{
AppInstanceId = sameAppInstanceId ? appInstanceId : Guid.NewGuid()
}
};
}
clientForReOpen.Create(
treeIdForReOpen,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileIdForReOpen,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
createContextsRequestForReOpen,
shareAccess: ShareAccess_Values.NONE,
checker: (header, response) =>
{
if (sameAppInstanceId)
{
BaseTestSite.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, header.Status, "The second client should create the open successfully.");
}
else
{
BaseTestSite.Assert.AreNotEqual(Smb2Status.STATUS_SUCCESS, header.Status, "The second client should not create the open successfully.");
}
});
BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends another WRITE request.");
if (sameAppInstanceId)
{
clientForInitialOpen.Write(treeIdForInitialOpen, fileIdForInitialOpen, content,
checker: (header, response) =>
{
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"The initial open is closed. Write should not succeed. Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
BaseTestSite.CaptureRequirementIfAreEqual(
Smb2Status.STATUS_FILE_CLOSED,
header.Status,
RequirementCategory.STATUS_FILE_CLOSED.Id,
RequirementCategory.STATUS_FILE_CLOSED.Description);
});
// The first open is closed, no need to do clean up job.
// Clean up the second client.
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF; DISCONNECT");
clientForReOpen.Close(treeIdForReOpen, fileIdForReOpen);
clientForReOpen.TreeDisconnect(treeIdForReOpen);
clientForReOpen.LogOff();
clientForReOpen.Disconnect();
}
else
{
BaseTestSite.Log.Add(LogEntryKind.TestStep, "The initial open is not closed. Write should succeed.");
clientForInitialOpen.Write(treeIdForInitialOpen, fileIdForInitialOpen, content);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF");
clientForInitialOpen.Close(treeIdForInitialOpen, fileIdForInitialOpen);
clientForInitialOpen.TreeDisconnect(treeIdForInitialOpen);
clientForInitialOpen.LogOff();
// The second client doesn't create the open succesfully, so no need to close the open.
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: TREE_DISCONNECT; LOG_OFF; DISCONNECT");
clientForReOpen.TreeDisconnect(treeIdForReOpen);
clientForReOpen.LogOff();
clientForReOpen.Disconnect();
}
#endregion
}
示例10: 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>
private void ValidateByteLockRangeFromAnotherClient(bool isLocked)
{
uint status = 0;
Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress, TestConfig.ClientNic2IPAddress);
status = client.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled);
status = client.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId;
status = client.TreeConnect(uncSharePath, out treeId);
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileId;
status = client.Create(
treeId,
fileName,
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));
}
status = client.Close(treeId, fileId);
status = client.TreeDisconnect(treeId);
status = client.LogOff();
client.Disconnect();
}
示例11: TriggerBreakFromClient
/// <summary>
/// Trigger LeaseBreak from a separate client
/// </summary>
/// <param name="client">Smb2FunctionalClient object that attempt to access file/directory to trigger lease break</param>
/// <param name="requestDialect">Dialect in request</param>
/// <param name="isDirectory">Set true if access a directory, otherwise set false</param>
/// <param name="requestedLeaseState">Lease state that client will request</param>
/// <param name="accessMask">Access mask that client is used to access file/directory</param>
private void TriggerBreakFromClient(
Smb2FunctionalClient client,
DialectRevision[] requestDialect,
bool isDirectory,
LeaseStateValues requestedLeaseState,
AccessMask accessMask)
{
BaseTestSite.Log.Add(
LogEntryKind.Debug,
"Below steps will trigger a lease break by accessing same file/directory 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);
#endregion
#region SESSION_SETUP
status = client.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
#endregion
#region TREE_CONNECT to share
uint treeId;
status = client.TreeConnect(uncSharePath, out treeId);
#endregion
#region CREATE
FILEID fileId;
Smb2CreateContextResponse[] serverCreateContexts;
status = client.Create(
treeId,
isDirectory ? testDirectory : fileName,
isDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : 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);
#endregion
status = client.Close(treeId, fileId);
BaseTestSite.Log.Add(
LogEntryKind.Debug,
"Finish triggering lease break.");
}
示例12: CheckIfOpenClosed
private bool CheckIfOpenClosed(ModelDialectRevision dialect, CreateType createType)
{
if (createType == CreateType.ReconnectDurable)
{
/// prepareClient is disconnected, so
/// Reconnect to the share and try to get the open, if the durable open can be reconnected, then it's not closed.
Smb2FunctionalClient reconnectClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
uint treeId;
ConnectToShare(
dialect,
reconnectClient,
this.connection_ClientGuid,
testConfig.BasicFileShare,
out treeId);
FILEID fileId;
Smb2CreateContextResponse[] createContextResponse;
uint status = reconnectClient.Create(
treeId,
this.fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out createContextResponse,
createContexts: CreateContexts(AppInstanceIdType.NoAppInstanceId, createType, false),
shareAccess:ShareAccess_Values.NONE,
checker: (header, response) => {});
Site.Log.Add(LogEntryKind.Debug, "CheckIfOpenClosed: status of reconnectClient.Create is " + Smb2Status.GetStatusCode(status));
reconnectClient.Close(treeId, fileId, (header, response) => { });
reconnectClient.Disconnect();
return !(status == Smb2Status.STATUS_SUCCESS);
}
else
{
/// Write (using the FileID got from the create response of PrepareOpen) to check if the Open is closed.
uint status = prepareClient.Write(this.treeConnect_TreeId, this.open_FileId, "AppInstanceId", checker: (header, response) => { });
Site.Log.Add(LogEntryKind.Debug, "CheckIfOpenClosed: status of Write is " + Smb2Status.GetStatusCode(status));
prepareClient.Close(this.treeConnect_TreeId, this.open_FileId, (header, response) => { });
return status == Smb2Status.STATUS_FILE_CLOSED;
}
}
示例13: SharePermission_CreateClose_DeleteFile_MaximalAccessNotIncludeDeleteOrGenericAll
public void SharePermission_CreateClose_DeleteFile_MaximalAccessNotIncludeDeleteOrGenericAll()
{
_SID sid = DtypUtility.GetSidFromAccount(TestConfig.DomainName, azUser01Name);
if (!dynamicallyConfigurableShareExist)
{
BaseTestSite.Assert.Inconclusive("Required share: {0} does not exist!", dynamicallyConfigurableShareName);
}
object ace = DtypUtility.CreateAccessAllowedAce(sid, (DtypUtility.ACCESS_MASK_STANDARD_RIGHTS_ALL | DtypUtility.ACCESS_MASK_SPECIFIC_RIGHTS_ALL) & ~DtypUtility.ACCESS_MASK_DELETE, ACE_FLAGS.None);
SetSecurityDescriptorOnDynamicallyConfigurableShare(ace);
string shareName = dynamicallyConfigurableShareName;
string shareUncPath = Smb2Utility.GetUncPath(TestConfig.SutComputerName, shareName);
Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
AccountCredential user = new AccountCredential(TestConfig.DomainName, azUser01Name, TestConfig.UserPassword);
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}.", shareUncPath);
client.TreeConnect(shareUncPath, out treeId, checker: (header, response) =>
{
BaseTestSite.Assert.IsTrue((response.MaximalAccess.ACCESS_MASK & (DtypUtility.ACCESS_MASK_DELETE | DtypUtility.ACCESS_MASK_GENERIC_ALL)) == 0,
"Treeconnect.MaximalAccess does not include DELETE or GENERIC_ALL.");
});
string fileName = string.Format("SharePermission_CreateClose_InvalidMaximalAccess_{0}.txt", Guid.NewGuid());
FILEID fileId;
Smb2CreateContextResponse[] createContexResponse;
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Create the file: {0}", fileName);
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends CREATE request.");
uint status = client.Create(
treeId,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out createContexResponse,
accessMask: AccessMask.FILE_READ_DATA | AccessMask.FILE_WRITE_DATA | AccessMask.FILE_APPEND_DATA |
AccessMask.FILE_READ_ATTRIBUTES | AccessMask.FILE_READ_EA | AccessMask.FILE_WRITE_ATTRIBUTES |
AccessMask.FILE_WRITE_EA | AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.SYNCHRONIZE, // Windows client behavior
shareAccess: ShareAccess_Values.NONE,
createDisposition: CreateDisposition_Values.FILE_CREATE);
client.Close(treeId, fileId);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Delete the file: {0}", fileName);
BaseTestSite.Log.Add(LogEntryKind.Debug, "Client sends CREATE request with FILE_DELETE_ON_CLOSE flag set in CreateOptions .");
status = client.Create(
treeId,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE | CreateOptions_Values.FILE_DELETE_ON_CLOSE,
out fileId,
out createContexResponse,
accessMask: AccessMask.DELETE | AccessMask.FILE_READ_ATTRIBUTES | AccessMask.SYNCHRONIZE, // Windows client behavior
shareAccess: ShareAccess_Values.FILE_SHARE_DELETE,
createDisposition: CreateDisposition_Values.FILE_OPEN,
checker:(header, response) =>
{
if(TestConfig.Platform == Platform.NonWindows)
{
BaseTestSite.Assert.AreNotEqual(Smb2Status.STATUS_SUCCESS, header.Status,
"If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and " +
"Treeconnect.MaximalAccess does not include DELETE or GENERIC_ALL, " +
"the server SHOULD fail the request with STATUS_ACCESS_DENIED");
}
else
{
BaseTestSite.Assert.AreEqual(Smb2Status.STATUS_ACCESS_DENIED, header.Status,
"If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and " +
"Treeconnect.MaximalAccess does not include DELETE or GENERIC_ALL, " +
"the server SHOULD fail the request with STATUS_ACCESS_DENIED");
}
});
client.TreeDisconnect(treeId);
client.LogOff();
}
catch(Exception e)
{
BaseTestSite.Assert.Fail("Case failed due to: {0}", e.Message);
}
finally
{
client.Disconnect();
}
}
示例14: ReadContentAfterFailover
//.........这里部分代码省略.........
Guid createGuid)
{
uint status;
BaseTestSite.Assert.AreNotEqual(
null,
serverAccessIp,
"Access IP to the file server should not be empty");
BaseTestSite.Log.Add(
LogEntryKind.Debug,
"Got IP {0} to access the file server", serverAccessIp.ToString());
Smb2FunctionalClient afterFailover = new Smb2FunctionalClient(TestConfig.FailoverTimeout, TestConfig, BaseTestSite);
DoUntilSucceed(() => afterFailover.ConnectToServer(TestConfig.UnderlyingTransport, server, serverAccessIp), TestConfig.FailoverTimeout,
"Retry to connect to server until succeed within timeout span");
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends NEGOTIATE request with the same clientguid of previous client.");
status = afterFailover.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);
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "Negotiate failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends SESSION_SETUP request with the same SESSION_ID of previous client.");
status = afterFailover.ReconnectSessionSetup(
beforeFailover,
TestConfig.DefaultSecurityPackage,
server,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "ReconnectSessionSetup failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
// Retry TreeConnect because network path may not be available immediately
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client retries TREE_CONNECT to {0} until succeed or timeout in {1} because network path may not be available immediately.", uncSharePath, TestConfig.FailoverTimeout);
uint treeId = 0;
status = afterFailover.TreeConnect(uncSharePath, out treeId, (header, response) => { });
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "TreeConnect failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
// Retry Create because file may not be available immediately
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client retries to send CREATE request with SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 context with PERSISTENT flag set until succeed or timeout in {0}.", TestConfig.FailoverTimeout);
FILEID fileId = new FILEID();
Smb2CreateContextResponse[] serverCreateContexts;
status = DoUntilSucceed(
() => afterFailover.Create(
treeId,
file,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
new Smb2CreateContextRequest[] {
new Smb2CreateDurableHandleReconnectV2
{
FileId = new FILEID { Persistent = fileId.Persistent },
CreateGuid = createGuid,
Flags = CREATE_DURABLE_HANDLE_RECONNECT_V2_Flags.DHANDLE_FLAG_PERSISTENT
},
},
checker: (header, response) => { }),
TestConfig.FailoverTimeout,
"Retry Create until succeed within timeout span");
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "Create failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
string readContent;
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends READ request to read content.");
status = afterFailover.Read(treeId, fileId, 0, (uint)content.Length, out readContent);
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "Read failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
BaseTestSite.Assert.IsTrue(
content.Equals(readContent),
"Content read after failover should be identical to that written before failover");
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF");
status = afterFailover.Close(treeId, fileId);
status = afterFailover.TreeDisconnect(treeId);
status = afterFailover.LogOff();
afterFailover.Disconnect();
return true;
}
示例15: DeleteExistingFile
protected void DeleteExistingFile(string sharePath, string fileName)
{
Smb2FunctionalClient clientAdmin;
clientAdmin = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
clientAdmin.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
uint treeId;
ConnectToShare(clientAdmin, TestConfig.AccountCredential, sharePath, out treeId);
FILEID fileId;
Smb2CreateContextResponse[] createContextResponses;
clientAdmin.Create(
treeId,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE | CreateOptions_Values.FILE_DELETE_ON_CLOSE,
out fileId,
out createContextResponses,
accessMask: AccessMask.FILE_READ_ATTRIBUTES | AccessMask.DELETE,
shareAccess: ShareAccess_Values.FILE_SHARE_DELETE,
createDisposition: CreateDisposition_Values.FILE_OPEN);
clientAdmin.Close(treeId, fileId);
clientAdmin.TreeDisconnect(treeId);
clientAdmin.Disconnect();
}