public void CreateRequest( int messageId, int sessionId, int treeId, int desiredAccess, CreateDisposition createDisposition, [Domain("ImpersonationLevel")] int impersonationLevel, string fileName, ShareType shareType, bool isSigned, bool isOpenByFileId, bool isDirectoryFile, bool isMaximumAllowedSet) { #region Create Packet SmbNtCreateAndxRequestPacket smbPacket = new SmbNtCreateAndxRequestPacket(); ushort uid = (ushort)this.uId[(uint)sessionId]; ushort tid = (ushort)this.tId[(uint)treeId]; string shareName = string.Empty; CreateFlags createFlags; bool isCreateDirectory = false; if (fileName != Site.Properties["SutShareExistFile"].ToString()) { if (createDisposition == CreateDisposition.FileOpenIf) { this.createActionInternal = this.createActionInternal.Add(CreateAction.FileCreated); this.createActionInternal = this.createActionInternal.Add(CreateAction.FileDoesNotExist); } } if (shareType == ShareType.NamedPipe) { if (SmbAdapter.isMessageModePipe) { shareName = Site.Properties["SutShareMessagePipe"]; } else { shareName = Site.Properties["SutShareStreamPipe"]; } isCreateDirectory = false; } else { if (fileName == Site.Properties["SutShareTest1"]) { shareName = Site.Properties["SutShareTest1"]; isCreateDirectory = false; } else if (fileName == Site.Properties["SutShareTest2"]) { shareName = Site.Properties["SutShareTest2"]; isCreateDirectory = false; } else if (fileName == Site.Properties["SutShareExistFile"]) { shareName = Site.Properties["SutShareExistFile"]; isCreateDirectory = false; } else if (fileName.Contains(".")) { shareName = fileName; isCreateDirectory = false; } else { shareName = fileName; isCreateDirectory = true; } } this.openedFileName = shareName; if (isCreateDirectory) { createFlags = CreateFlags.NT_CREATE_OPEN_TARGET_DIR | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE; } else { createFlags = CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE; } NamespaceCifs.NtTransactShareAccess shareAccess = (NamespaceCifs.NtTransactShareAccess)ushort.Parse(Site.Properties["SmbTransportShareAccess"]); NamespaceCifs.SMB_EXT_FILE_ATTR extFileAttributes = NamespaceCifs.SMB_EXT_FILE_ATTR.NONE; NamespaceCifs.NtTransactCreateDisposition ntCreateDisposition = (NamespaceCifs.NtTransactCreateDisposition)createDisposition; NtTransactCreateOptions createOption = NtTransactCreateOptions.FILE_DIRECTORY_FILE; if (isOpenByFileId && isDirectoryFile) { createOption = NtTransactCreateOptions.FILE_OPEN_BY_FILE_ID | NtTransactCreateOptions.FILE_DIRECTORY_FILE; } if (isOpenByFileId && !isDirectoryFile) { createOption = NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE | NtTransactCreateOptions.FILE_OPEN_BY_FILE_ID; } if (!isOpenByFileId && isDirectoryFile) { createOption = NtTransactCreateOptions.FILE_DIRECTORY_FILE; } if (!isOpenByFileId && !isDirectoryFile) { createOption = NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE; } NamespaceCifs.NtTransactDesiredAccess nTDesiredAccess = (NamespaceCifs.NtTransactDesiredAccess)desiredAccess; if (nTDesiredAccess == ( NamespaceCifs.NtTransactDesiredAccess.FILE_READ_DATA | NamespaceCifs.NtTransactDesiredAccess.FILE_WRITE_DATA)) { nTDesiredAccess = NamespaceCifs.NtTransactDesiredAccess.GENERIC_ALL; } if (isCreateDirectory) { nTDesiredAccess = Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Cifs.NtTransactDesiredAccess.FILE_READ_DATA | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Cifs.NtTransactDesiredAccess.FILE_READ_ATTRIBUTES | Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Cifs.NtTransactDesiredAccess.SYNCHRONIZE; shareAccess = NamespaceCifs.NtTransactShareAccess.FILE_SHARE_READ | NamespaceCifs.NtTransactShareAccess.FILE_SHARE_WRITE; } smbPacket = this.smbClientStack.CreateCreateRequest( tid, shareName, nTDesiredAccess, extFileAttributes, shareAccess, ntCreateDisposition, createOption, (NamespaceCifs.NtTransactImpersonationLevel)impersonationLevel, createFlags); if (isSigned) { NamespaceCifs.CifsClientPerConnection connection = this.smbClientStack.Context.GetConnection(ConnectionId); NamespaceCifs.CifsClientPerSession session = this.smbClientStack.Context.GetSession(ConnectionId, uid); smbPacket.Sign(connection.ClientNextSendSequenceNumber, session.SessionKey); } #endregion #region Send and Receive ExpectPacket this.smbClientStack.SendPacket(smbPacket); StackPacket response = this.smbClientStack.ExpectPacket(this.timeout); NamespaceCifs.SmbPacket smbPacketResponse = (NamespaceCifs.SmbPacket)response; this.QueryUidTable(smbPacketResponse); this.QueryTidTable(smbPacketResponse); VerifyTransport(smbPacketResponse); VerifyCommonMessageSyntax(smbPacketResponse); if (response.GetType() == typeof(SmbErrorResponsePacket)) { SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket; NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader; this.ErrorResponse(smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status); } else { SmbNtCreateAndxResponsePacket smbNtCreateAndXPacket = response as SmbNtCreateAndxResponsePacket; NamespaceCifs.SmbHeader ntCreateAndXResponseHeader = smbNtCreateAndXPacket.SmbHeader; SMB_COM_NT_CREATE_ANDX_Response_SMB_Parameters ntCreateAndXResponsePayload = smbNtCreateAndXPacket.SmbParameters; this.smbFileId = ntCreateAndXResponsePayload.FID; int fidValue = (int)uint.MinValue; if (!this.fId.ContainsValue(ntCreateAndXResponsePayload.FID)) { int count = this.fId.Count; this.fId.Add((uint)(count), ntCreateAndXResponsePayload.FID); fidValue = count; } else { foreach (uint key in this.fId.Keys) { if (this.fId[key] == ntCreateAndXResponsePayload.FID) { fidValue = (int)key; break; } } } uint creatAction = ntCreateAndXResponsePayload.CreationAction; Microsoft.Modeling.Set<CreateAction> actionSet = new Microsoft.Modeling.Set<CreateAction>(); if (creatAction == CreateActionSuperseded) { actionSet = actionSet.Add(CreateAction.FileSuperseded); } if ((creatAction & CreateActionExists) == CreateActionExists) { actionSet = actionSet.Add(CreateAction.FileExists); } if ((creatAction & CreateActionOpened) == CreateActionOpened) { actionSet = actionSet.Add(CreateAction.FileOpened); if (!actionSet.Contains(CreateAction.FileExists)) { actionSet = actionSet.Add(CreateAction.FileExists); } } if ((creatAction & CreateActionNotExists) == CreateActionNotExists) { actionSet = actionSet.Add(CreateAction.FileDoesNotExist); } if ((creatAction & CreateActionCreated) == CreateActionCreated) { actionSet = actionSet.Add(CreateAction.FileCreated); if (!actionSet.Contains(CreateAction.FileDoesNotExist)) { actionSet = actionSet.Add(CreateAction.FileDoesNotExist); } } if ((creatAction & CreateActionOverwritten) == CreateActionOverwritten) { actionSet = actionSet.Add(CreateAction.FileOverwritten); } bool isIdZero = false; bool isNoSubStreams = false; if (ntCreateAndXResponsePayload.ResourceType == NamespaceCifs.FileTypeValue.FileTypeDisk) { if (SmbAdapter.FsType == FileSystemType.Ntfs.ToString()) { isNoSubStreams = false; } else { isNoSubStreams = true; } } if (SmbAdapter.ServiceShareType == ShareType.NamedPipe) { isNoSubStreams = true; } bool isVolumnGuidZero = false; if (!this.checkWindowsImplementation) { Site.Log.Add( LogEntryKind.Comment, @"isFileIdZero: {0}; isVolumnGUIDZero: {1}", isIdZero, isVolumnGuidZero); isIdZero = true; isVolumnGuidZero = true; } bool isNotionSupportedForCreate = Boolean.Parse(Site.Properties["IsNotionSupportedForCreate"]); bool isSerWantCliLeverageNewCap = Boolean.Parse(Site.Properties["IsSerWantCliLeverageNewCap"]); VerifyMessageSyntaxSmbComNtCreateAndXResponse( smbNtCreateAndXPacket, isSerWantCliLeverageNewCap); VerifyMessageSyntaxSmbComNtCreateAndXResponseForNotNotionSupported( smbNtCreateAndXPacket, isNotionSupportedForCreate); VerifyMessageSyntaxFileIdGeneration(smbNtCreateAndXPacket.SmbParameters.FileId); VerifyMessageSyntaxVolumeGUIDGeneration(smbNtCreateAndXPacket.SmbParameters.VolumeGUID); if (0x00000003 >= (uint)impersonationLevel) { VerifyMessageSyntaxNtTransactCreateRequest(impersonationLevel); } VerifyMessageSyntaxAccessMasks(smbNtCreateAndXPacket, isDirectoryFile); uint computedMaximalAccessRights = (uint)Int32.Parse(Site.Properties["ComputedMaximalAccessRights"]); uint computedGuestMaximalAccessRights = (uint)Int32.Parse(Site.Properties["ComputedGuestMaximalAccessRights"]); VerifyReceiveSmbComNtCreateAndXRequest( (uint)smbPacket.SmbHeader.Flags, smbNtCreateAndXPacket, computedMaximalAccessRights, computedGuestMaximalAccessRights, impersonationLevel == (int)NamespaceCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS ? true : false); //Workaround temp code (Invalid impersonation level) if ((string.Equals(Site.Properties["SutPlatformOS"], "Win2K8") && impersonationLevel == 4) && !bool.Parse(Site.Properties["IsTDI33006Fixed"])) { this.ErrorResponse(ntCreateAndXResponseHeader.Mid + this.addMidMark, MessageStatus.BadImpersonationLevel); } else { if (this.createActionInternal.Count == uint.MinValue) { this.CreateResponse( ntCreateAndXResponseHeader.Mid + this.addMidMark, this.QueryUidTable(smbPacketResponse), this.QueryTidTable(smbPacketResponse), fidValue, smbPacketResponse.IsSignRequired, actionSet, isIdZero, isVolumnGuidZero, (ntCreateAndXResponsePayload.Directory == uint.MinValue), true, isNoSubStreams, (MessageStatus)ntCreateAndXResponseHeader.Status); } else { this.CreateResponse( ntCreateAndXResponseHeader.Mid + this.addMidMark, this.QueryUidTable(smbPacketResponse), this.QueryTidTable(smbPacketResponse), fidValue, (smbPacketResponse).IsSignRequired, this.createActionInternal, isIdZero, isVolumnGuidZero, (ntCreateAndXResponsePayload.Directory == 0), true, isNoSubStreams, (MessageStatus)ntCreateAndXResponseHeader.Status); } } this.createActionInternal = new Microsoft.Modeling.Set<CreateAction>(); } #endregion }
/// <summary> /// This method is called before each test case runs. User dose not need to call it directly. /// </summary> public override void Reset() { base.Reset(); this.fId.Clear(); this.sId.Clear(); this.uId.Clear(); this.tId.Clear(); this.negReturnedCap = new Microsoft.Modeling.Set<Capabilities>(); this.negResponseCap = new Microsoft.Modeling.Set<Capabilities>(); this.createActionInternal = new Set<CreateAction>(); // Disconnect the connection. if (this.smbClientStack != null) { this.smbClientStack.Disconnect(); this.smbClientStack.Dispose(); this.smbClientStack = null; } }
public void NegotiateRequest( int messageId, bool isSupportExtSecurity, SignState clientSignState, Sequence<Dialect> dialectName) { #region Create SMB Connection TestStarted(); #endregion #region Create Packet SmbNegotiateRequestPacket smbPacket = new SmbNegotiateRequestPacket(); string[] dialectNameArray = new string[dialectName.Count]; int i = (int)UInt16.MinValue; //fsccIsSupportExtSecurity = isSupportExtSecurity; foreach (Dialect name in dialectName) { switch (name) { case Dialect.PcNet1: dialectNameArray[i++] = DialectNameString.PCNET1; break; case Dialect.XenixCore: dialectNameArray[i++] = DialectNameString.XENIXCORE; break; case Dialect.PcLan1: dialectNameArray[i++] = DialectNameString.PCLAN1; break; case Dialect.MsNet103: dialectNameArray[i++] = DialectNameString.MSNET103; break; case Dialect.MsNet30: dialectNameArray[i++] = DialectNameString.MSNET30; break; case Dialect.LanMan10: dialectNameArray[i++] = DialectNameString.LANMAN10; break; case Dialect.Wfw10: dialectNameArray[i++] = DialectNameString.WFW10; break; case Dialect.DosLanMan12: dialectNameArray[i++] = DialectNameString.DOSLANMAN12; break; case Dialect.DosLanMan21: dialectNameArray[i++] = DialectNameString.DOSLANMAN21; break; case Dialect.LanMan12: dialectNameArray[i++] = DialectNameString.LANMAN12; break; case Dialect.LanMan21: dialectNameArray[i++] = DialectNameString.LANMAN21; break; case Dialect.NtLanMan: dialectNameArray[i++] = DialectNameString.NTLANMAN; break; default: dialectNameArray[i++] = string.Empty; break; } } this.smbClientStack.Capability.IsSupportsExtendedSecurity = isSupportExtSecurity; NamespaceSmb.SignState signState = (NamespaceSmb.SignState)Enum.Parse( typeof(NamespaceSmb.SignState), clientSignState.ToString(), true); smbPacket = this.smbClientStack.CreateNegotiateRequest(signState, dialectNameArray); #endregion #region Send and Receive ExpectPacket this.smbClientStack.SendPacket(smbPacket); StackPacket response = this.smbClientStack.ExpectPacket(this.timeout); NamespaceCifs.SmbPacket smbPacketResponse = (NamespaceCifs.SmbPacket)response; this.QueryUidTable(smbPacketResponse); this.QueryTidTable(smbPacketResponse); VerifyTransport(smbPacketResponse); VerifyCommonMessageSyntax(smbPacketResponse); if (response.GetType() == typeof(SmbErrorResponsePacket)) { SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket; NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader; this.ErrorResponse(smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status); } else { if (this.smbClientStack.Capability.IsSupportsExtendedSecurity) { SmbNegotiateResponsePacket smbNegotiateResponse = (SmbNegotiateResponsePacket)response; NamespaceCifs.SmbHeader negotiateResponseHeader = smbNegotiateResponse.SmbHeader; SMB_COM_NEGOTIATE_NtLanManagerResponse_SMB_Parameters negotiateResponsePayload = smbNegotiateResponse.SmbParameters; if (negotiateResponsePayload.DialectIndex == ServerNotSupportDialectIndex) { this.NegotiateResponse( negotiateResponseHeader.Mid + this.addMidMark, false, false, int.MinValue, new Microsoft.Modeling.Set<Capabilities>(Capabilities.None), (MessageStatus)negotiateResponseHeader.Status); } else { byte securityMode = (byte)negotiateResponsePayload.SecurityMode; bool isSignEnabled = false; bool isSignRequired = false; if ((securityMode & SecurityModeNegotiateSecuritySignatureEnabled) == SecurityModeNegotiateSecuritySignatureEnabled) { isSignEnabled = true; } if ((securityMode & SecurityModeNegotiateSecuritySignatureRequired) == SecurityModeNegotiateSecuritySignatureRequired) { isSignRequired = true; } #region Get and Store Capabilities uint capabilities = (uint)negotiateResponsePayload.Capabilities; if ((capabilities & Convert.ToUInt32(Capabilities.CapUnicode.ToString("D"))) == Convert.ToUInt32(Capabilities.CapUnicode.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapUnicode); } if ((capabilities & Convert.ToUInt32(Capabilities.CapStatus32.ToString("D"))) == Convert.ToUInt32(Capabilities.CapStatus32.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapStatus32); } if ((capabilities & Convert.ToUInt32(Capabilities.CapDynamicReauth.ToString("D"))) == Convert.ToUInt32(Capabilities.CapDynamicReauth.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapDynamicReauth); } if ((capabilities & Convert.ToUInt32(Capabilities.CapLevelIIOplocks.ToString("D"))) == Convert.ToUInt32(Capabilities.CapLevelIIOplocks.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapLevelIIOplocks); } if ((capabilities & Convert.ToUInt32(Capabilities.CapNtSmbs.ToString("D"))) == Convert.ToUInt32(Capabilities.CapNtSmbs.ToString("D"))) { this.negResponseCap = this.negResponseCap.Add(Capabilities.CapNtSmbs); } if ((capabilities & Convert.ToUInt32(Capabilities.CapDfs.ToString("D"))) == Convert.ToUInt32(Capabilities.CapDfs.ToString("D"))) { this.negResponseCap = this.negResponseCap.Add(Capabilities.CapDfs); } if ((capabilities & Convert.ToUInt32(Capabilities.CapInfoLevelPassThru.ToString("D"))) == Convert.ToUInt32(Capabilities.CapInfoLevelPassThru.ToString("D"))) { this.negResponseCap = this.negResponseCap.Add(Capabilities.CapInfoLevelPassThru); } if ((capabilities & Convert.ToUInt32(Capabilities.CapExtendedSecurity.ToString("D"))) == Convert.ToUInt32(Capabilities.CapExtendedSecurity.ToString("D"))) { this.negResponseCap = this.negResponseCap.Add(Capabilities.CapExtendedSecurity); } #endregion bool isTokenConfiguredToUsed = Boolean.Parse(Site.Properties["IsTokenConfiguredToUsed"]); bool isReAuthentSupported = Boolean.Parse(Site.Properties["IsReAuthentSupported"]); VerifyMessageSyntaxSmbComNegotiateExtendedSecurityServerResponse( smbNegotiateResponse, isTokenConfiguredToUsed, isReAuthentSupported); bool isNTManagerNegotiated = false; if (smbNegotiateResponse.SmbParameters.DialectIndex == NtManagerNegotiated) { isNTManagerNegotiated = true; } bool isExtendedSecuritySupported = false; if (((int)negotiateResponseHeader.Flags2 & (int)SmbHeader_Flags2_Values.SMB_FLAGS2_EXTENDED_SECURITY) == (int)SmbHeader_Flags2_Values.SMB_FLAGS2_EXTENDED_SECURITY) { isExtendedSecuritySupported = true; } bool isPathContainsLongNames = Boolean.Parse(Site.Properties["IsPathContainsLongNames"]); VerifyMessageSyntaxSMBHeaderExtension( negotiateResponseHeader, isNTManagerNegotiated, isExtendedSecuritySupported, isPathContainsLongNames); this.NegotiateResponse( negotiateResponseHeader.Mid + this.addMidMark, isSignRequired, isSignEnabled, negotiateResponsePayload.DialectIndex, this.negResponseCap, (MessageStatus)negotiateResponseHeader.Status); } } else { SmbNegotiateImplicitNtlmResponsePacket smbNegotiateImplicitNtlmPacket = response as SmbNegotiateImplicitNtlmResponsePacket; NamespaceCifs.SmbHeader negotiateImplicitNtlmResponseHeader = smbNegotiateImplicitNtlmPacket.SmbHeader; NamespaceCifs.SMB_COM_NEGOTIATE_NtLanManagerResponse_SMB_Parameters negotiateImplicitNtlmResponsePayload = smbNegotiateImplicitNtlmPacket.SmbParameters; if (negotiateImplicitNtlmResponsePayload.DialectIndex == ServerNotSupportDialectIndex) { this.NonExtendedNegotiateResponse( negotiateImplicitNtlmResponseHeader.Mid + this.addMidMark, false, false, int.MinValue, new Microsoft.Modeling.Set<Capabilities>(Capabilities.None), (MessageStatus)negotiateImplicitNtlmResponseHeader.Status); } else { byte securityMode = (byte)negotiateImplicitNtlmResponsePayload.SecurityMode; bool isSignEnabled = false; bool isSignRequired = false; if ((securityMode & SecurityModeNegotiateSecuritySignatureEnabled) == SecurityModeNegotiateSecuritySignatureEnabled) { isSignEnabled = true; } if ((securityMode & SecurityModeNegotiateSecuritySignatureRequired) == SecurityModeNegotiateSecuritySignatureRequired) { isSignRequired = true; } this.dialectIndex = negotiateImplicitNtlmResponsePayload.DialectIndex; uint capabilities = (uint)negotiateImplicitNtlmResponsePayload.Capabilities; if ((capabilities & Convert.ToUInt32(Capabilities.CapUnicode.ToString("D"))) == Convert.ToUInt32(Capabilities.CapUnicode.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapUnicode); } if ((capabilities & Convert.ToUInt32(Capabilities.CapStatus32.ToString("D"))) == Convert.ToUInt32(Capabilities.CapStatus32.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapStatus32); } if ((capabilities & Convert.ToUInt32(Capabilities.CapDynamicReauth.ToString("D"))) == Convert.ToUInt32(Capabilities.CapDynamicReauth.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapDynamicReauth); } if ((capabilities & Convert.ToUInt32(Capabilities.CapLevelIIOplocks.ToString("D"))) == Convert.ToUInt32(Capabilities.CapLevelIIOplocks.ToString("D"))) { this.negReturnedCap = this.negReturnedCap.Add(Capabilities.CapLevelIIOplocks); } if ((capabilities & Convert.ToUInt32(Capabilities.CapNtSmbs.ToString("D"))) == Convert.ToUInt32(Capabilities.CapNtSmbs.ToString("D"))) { this.negResponseCap = this.negResponseCap.Add(Capabilities.CapNtSmbs); } if ((capabilities & Convert.ToUInt32(Capabilities.CapDfs.ToString("D"))) == Convert.ToUInt32(Capabilities.CapDfs.ToString("D"))) { this.negResponseCap = this.negResponseCap.Add(Capabilities.CapDfs); } if ((capabilities & Convert.ToUInt32(Capabilities.CapInfoLevelPassThru.ToString("D"))) == Convert.ToUInt32(Capabilities.CapInfoLevelPassThru.ToString("D"))) { this.negResponseCap = this.negResponseCap.Add(Capabilities.CapInfoLevelPassThru); } bool isAuthenticationSupported = Boolean.Parse(Site.Properties["IsAuthenticationSupported"]); VerifyMessageSyntaxSmbComNegotiateNonExtendedSecurityServerResponse( smbNegotiateImplicitNtlmPacket, isAuthenticationSupported); this.NonExtendedNegotiateResponse( negotiateImplicitNtlmResponseHeader.Mid + this.addMidMark, isSignRequired, isSignEnabled, this.dialectIndex, this.negResponseCap, (MessageStatus)negotiateImplicitNtlmResponseHeader.Status); } } } #endregion }
public void NtTransactCreateRequest( int messageId, int sessionId, int treeId, [Domain("ImpersonationLevel")] int impersonationLevel, [Domain("FileDomain")] string fileName, ShareType shareType, bool isSigned) { #region Create Packet SmbNtCreateAndxRequestPacket smbPacket = new SmbNtCreateAndxRequestPacket(); ushort uid = (ushort)this.uId[(uint)sessionId]; ushort tid = (ushort)this.tId[(uint)treeId]; string shareName = string.Empty; if (shareType == ShareType.NamedPipe) { if (SmbAdapter.isMessageModePipe) { shareName = Site.Properties["SutShareMessagePipe"]; } else { shareName = Site.Properties["SutShareStreamPipe"]; } } else { if (fileName == Site.Properties["SutShareTest1"]) { shareName = Site.Properties["SutShareTest1"]; } else if (fileName == Site.Properties["SutShareTest2"]) { shareName = Site.Properties["SutShareTest2"]; } else if (fileName == Site.Properties["SutShareExistFile"]) { shareName = Site.Properties["SutShareExistFile"]; } else if (fileName.Contains(".")) { shareName = fileName; } else { shareName = fileName; } } this.openedFileName = shareName; uint nTDesiredAccess = (uint)NamespaceCifs.NtTransactDesiredAccess.GENERIC_ALL; NamespaceCifs.SMB_EXT_FILE_ATTR extFileAttributes = NamespaceCifs.SMB_EXT_FILE_ATTR.NONE; NtTransactCreateOptions createOption = NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE; smbPacket = this.smbClientStack.CreateCreateRequest( tid, shareName, (NamespaceCifs.NtTransactDesiredAccess)nTDesiredAccess, extFileAttributes, NamespaceCifs.NtTransactShareAccess.NONE, NamespaceCifs.NtTransactCreateDisposition.FILE_OPEN_IF, createOption, (NamespaceCifs.NtTransactImpersonationLevel)impersonationLevel, CreateFlags.NT_CREATE_REQUEST_OPLOCK); if (isSigned) { NamespaceCifs.CifsClientPerConnection connection = this.smbClientStack.Context.GetConnection(ConnectionId); NamespaceCifs.CifsClientPerSession session = this.smbClientStack.Context.GetSession(ConnectionId, uid); smbPacket.Sign(connection.ClientNextSendSequenceNumber, session.SessionKey); } #endregion #region Send and Receive ExpectPacket this.smbClientStack.SendPacket(smbPacket); StackPacket response = this.smbClientStack.ExpectPacket(this.timeout); NamespaceCifs.SmbPacket smbPacketResponse = (NamespaceCifs.SmbPacket)response; this.QueryUidTable(smbPacketResponse); this.QueryTidTable(smbPacketResponse); VerifyTransport(smbPacketResponse); VerifyCommonMessageSyntax(smbPacketResponse); if (response.GetType() == typeof(SmbErrorResponsePacket)) { SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket; NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader; this.ErrorResponse(smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status); } else { SmbNtCreateAndxResponsePacket smbNtCreateAndXPacket = response as SmbNtCreateAndxResponsePacket; NamespaceCifs.SmbHeader ntCreateAndXResponseHeader = smbNtCreateAndXPacket.SmbHeader; SMB_COM_NT_CREATE_ANDX_Response_SMB_Parameters ntCreateAndXResponsePayload = smbNtCreateAndXPacket.SmbParameters; this.smbFileId = ntCreateAndXResponsePayload.FID; if (!this.fId.ContainsValue(ntCreateAndXResponsePayload.FID)) { int count = this.fId.Count; this.fId.Add((uint)(count), ntCreateAndXResponsePayload.FID); } else { foreach (uint key in this.fId.Keys) { if (this.fId[key] == ntCreateAndXResponsePayload.FID) { break; } } } uint creatAction = ntCreateAndXResponsePayload.CreationAction; Microsoft.Modeling.Set<CreateAction> actionSet = new Microsoft.Modeling.Set<CreateAction>(); if (creatAction == CreateActionSuperseded) { actionSet = actionSet.Add(CreateAction.FileSuperseded); } if ((creatAction & CreateActionExists) == CreateActionExists) { actionSet = actionSet.Add(CreateAction.FileExists); } if ((creatAction & CreateActionOpened) == CreateActionOpened) { actionSet = actionSet.Add(CreateAction.FileOpened); if (!actionSet.Contains(CreateAction.FileExists)) { actionSet = actionSet.Add(CreateAction.FileExists); } } if ((creatAction & CreateActionNotExists) == CreateActionNotExists) { actionSet = actionSet.Add(CreateAction.FileDoesNotExist); } if ((creatAction & CreateActionCreated) == CreateActionCreated) { actionSet = actionSet.Add(CreateAction.FileCreated); if (!actionSet.Contains(CreateAction.FileDoesNotExist)) { actionSet = actionSet.Add(CreateAction.FileDoesNotExist); } } if ((creatAction & CreateActionOverwritten) == CreateActionOverwritten) { actionSet = actionSet.Add(CreateAction.FileOverwritten); } bool isIDZero = false; bool isVolumnGuidZero = false; if (!this.checkWindowsImplementation) { Site.Log.Add( LogEntryKind.Comment, @"isFileIdZero: {0}; isVolumnGUIDZero: {1}", isIDZero, isVolumnGuidZero); isIDZero = true; isVolumnGuidZero = true; } //Workaround temp code (Invalid impersonation level) if ((string.Equals(Site.Properties["SutPlatformOS"], "Win2K8") && impersonationLevel == 4) && !bool.Parse(Site.Properties["IsTDI33006Fixed"])) { this.ErrorResponse(ntCreateAndXResponseHeader.Mid + this.addMidMark, MessageStatus.BadImpersonationLevel); } else { this.NtTransactCreateResponse( ntCreateAndXResponseHeader.Mid + this.addMidMark, QueryUidTable(smbPacketResponse), QueryTidTable(smbPacketResponse), isSigned, (MessageStatus)ntCreateAndXResponseHeader.Status); } } #endregion }
/// <summary> /// Create the connection for the first test case. /// </summary> /// <param name="testSite"> /// An ITestSite interface which provides logging and assertions for test code in its execution context. /// </param> public override void Initialize(ITestSite testSite) { base.Initialize(testSite); this.maxDataCount = ushort.Parse(Site.Properties["TransportMaxDataCount"]); this.checkWindowsImplementation = bool.Parse(Site.Properties["SmbIsFileIdZeroAndIsVolumnGuidZero"]); testSite.DefaultProtocolDocShortName = Site.Properties["ProtocolShortName"]; this.IsClosePacket = false; this.transport = TransportType.DirectTcp; this.informationLevelBytes = new ushort[16]; this.informationLevelBytes[0] = InformationLevelStanderd; this.informationLevelBytes[1] = InformationLevelQueryFsAttribute; this.informationLevelBytes[2] = InformationLevelQueryFileStreamInfo; this.informationLevelBytes[3] = InformationLevelSetFileBasicInfo; this.informationLevelBytes[4] = InformationLevelQueryFileAllocationInfo; this.informationLevelBytes[5] = InformationLevelQueryFileEndOfFileInfo; this.informationLevelBytes[6] = InformationLevelFindFileBothDirInfo; this.informationLevelBytes[7] = InformationLevelFindFileIDFullDirInfo; this.informationLevelBytes[8] = InformationLevelFindFileIDBothDirInfo; this.informationLevelBytes[9] = InformationLevelFileAccessInfo; this.informationLevelBytes[10] = InformationLevelFileLinkInfo; this.informationLevelBytes[11] = InformationLevelFileRenameInfo; this.informationLevelBytes[12] = InformationLevelFileAllocationInfo; this.informationLevelBytes[13] = InformationLevelFileFsSizeInfo; this.informationLevelBytes[14] = InformationLevelFileFsControlInfo; this.informationLevelBytes[15] = InformationLevelInvalid; #region FSCC properties // Fscc information level for query path this.FSCCInformationLevelBytesQueryPath = new ushort[14]; this.FSCCInformationLevelBytesQueryPath[0] = FSCCInformationLevelQueryPathBasic; this.FSCCInformationLevelBytesQueryPath[1] = FSCCInformationLevelQueryPathStandard; this.FSCCInformationLevelBytesQueryPath[2] = FSCCInformationLevelQueryPathInternal; this.FSCCInformationLevelBytesQueryPath[3] = FSCCInformationLevelQueryPathEa; this.FSCCInformationLevelBytesQueryPath[4] = FSCCInformationLevelQueryPathAccess; this.FSCCInformationLevelBytesQueryPath[5] = FSCCInformationLevelQueryPathName; this.FSCCInformationLevelBytesQueryPath[6] = FSCCInformationLevelQueryPathMode; this.FSCCInformationLevelBytesQueryPath[7] = FSCCInformationLevelQueryPathAlignment; this.FSCCInformationLevelBytesQueryPath[8] = FSCCInformationLevelQueryPathAlternateName; this.FSCCInformationLevelBytesQueryPath[9] = FSCCInformationLevelQueryPathStream; this.FSCCInformationLevelBytesQueryPath[10] = FSCCInformationLevelQueryPathCompression; this.FSCCInformationLevelBytesQueryPath[11] = FSCCInformationLevelQueryPathNetworkOpen; this.FSCCInformationLevelBytesQueryPath[12] = FSCCInformationLevelQueryPathAttributeTag; this.FSCCInformationLevelBytesQueryPath[13] = FSCCInformationLevelQueryPathPosition; // Fscc information level for query fs this.FSCCInformationLevelBytesQueryFS = new ushort[7]; this.FSCCInformationLevelBytesQueryFS[0] = FSCCInformationLevelQueryFSVolume; this.FSCCInformationLevelBytesQueryFS[1] = FSCCInformationLevelQueryFSSize; this.FSCCInformationLevelBytesQueryFS[2] = FSCCInformationLevelQueryFSDevice; this.FSCCInformationLevelBytesQueryFS[3] = FSCCInformationLevelQueryFSAttribute; #endregion this.createActionInternal = new Microsoft.Modeling.Set<CreateAction>(); this.negReturnedCap = new Microsoft.Modeling.Set<Capabilities>(); this.negResponseCap = new Microsoft.Modeling.Set<Capabilities>(); this.fId = new Dictionary<uint, uint>(); this.sId = new Dictionary<uint, uint>(); this.uId = new Dictionary<uint, uint>(); this.tId = new Dictionary<uint, uint>(); this.gmtTokens = new Dictionary<int, string>(); this.timeout = TimeSpan.FromMilliseconds(int.Parse(Site.Properties["SmbTimeoutMillisec"])); #region FSCC Properties this.fsccFSCTLName = string.Empty; this.fsccQueryPathLevel = -1; this.fsccQueryFSLevel = -1; #endregion }