/// <summary> /// Tree multiple connect request /// </summary> /// <param name="messageId">This is used to associate a response with a request.</param> /// <param name="sessionId">The current session ID for this connection.</param> /// <param name="isTidDisconnectionSet">Indicate whether the client sets the tid disconnection.</param> /// <param name="isRequestExtSignature">Indicate whether the client requests the extended signature.</param> /// <param name="isRequestExtResponse"> /// Indicate whether the client requests the extended information on Tree connection response. /// </param> /// <param name="share">The share method.</param> /// <param name="shareType">The share type client intends to access.</param> /// <param name="isSigned">Indicate whether the message is signed or not for this request.</param> public void TreeMultipleConnectRequest( int messageId, int sessionId, bool isTidDisconnectionSet, bool isRequestExtSignature, bool isRequestExtResponse, string share, ShareType shareType, bool isSigned) { #region Create Packet ushort sessionUid = ushort.MinValue; if (!this.uId.ContainsKey((uint)sessionId)) { sessionUid = (ushort)sessionId; } else { sessionUid = (ushort)this.uId[(uint)sessionId]; } SmbAdapter.ServiceShareType = shareType; string shareName = string.Empty; switch (shareType) { case ShareType.NamedPipe: shareName = Site.Properties["SutNamedPipeFullName"]; break; case ShareType.Printer: shareName = Site.Properties["SutSharePrinterFullName"]; break; case ShareType.Disk: if (SmbAdapter.FsType == FileSystemType.Ntfs.ToString()) { if (share == ShareName.Share1.ToString()) { shareName = Site.Properties["SutNtfsShare1FullName"]; } else { if (share == ShareName.Share2.ToString()) { shareName = Site.Properties["SutNtfsShare2FullName"]; } else if (share == ShareName.DfsShare.ToString()) { shareName = Site.Properties["SutShareDfsTreeConnect"]; } } } else { if (share == ShareName.Share1.ToString()) { shareName = Site.Properties["SutFatShare1FullName"]; } else { if (share == ShareName.Share2.ToString()) { shareName = Site.Properties["SutFatShare2FullName"]; } else if (share == ShareName.DfsShare.ToString()) shareName = Site.Properties["SutShareDfsTreeConnect"]; } } break; default: shareName = string.Empty; break; } SmbTreeConnectAndxRequestPacket smbPacket = new SmbTreeConnectAndxRequestPacket(); // Create TreeConnect Request. smbPacket = this.smbClientStack.CreateTreeConnectRequest(sessionUid, shareName); if (isSigned) { NamespaceCifs.CifsClientPerConnection connection = this.smbClientStack.Context.GetConnection(ConnectionId); NamespaceCifs.CifsClientPerSession session = this.smbClientStack.Context.GetSession(ConnectionId, sessionUid); 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; isSigned = smbPacket.IsSignRequired; ushort uid = this.QueryUidTable(smbPacketResponse); ushort tid = this.QueryTidTable(smbPacketResponse); VerifyTransport(smbPacketResponse); VerifyCommonMessageSyntax(smbPacketResponse); if (response.GetType() == typeof(SmbErrorResponsePacket)) { SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket; NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader; this.ErrorTreeConnectResponse( smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status, Boolean.Parse(this.Site.Properties["SHOULDMAYR357Implementation"])); } else { SmbTreeConnectAndxResponsePacket smbTreeConnectAndXPacket = response as SmbTreeConnectAndxResponsePacket; NamespaceCifs.SmbHeader treeConnectAndXResponseHeader = smbTreeConnectAndXPacket.SmbHeader; SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Parameters treeConnectAndXResponsePayload = smbTreeConnectAndXPacket.SmbParameters; NamespaceCifs.SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Data treeConnectAndXResponseData = smbTreeConnectAndXPacket.SmbData; ShareType serviceShareType = ShareType.CommunicationDevice; string shareTypesString = Encoding.ASCII.GetString(treeConnectAndXResponseData.Service); if (shareTypesString == Disk) { serviceShareType = ShareType.Disk; } else if (shareTypesString == Printer) { serviceShareType = ShareType.Printer; } else if (shareTypesString == NamePipe) { serviceShareType = ShareType.NamedPipe; } else if (shareTypesString == CommunicationsDevice) { serviceShareType = ShareType.CommunicationDevice; } bool isSignSignatureZero = (treeConnectAndXResponseHeader.SecurityFeatures == uint.MinValue); bool isInDFS = ((treeConnectAndXResponsePayload.OptionalSupport & SmbShareIsInDfs) == SmbShareIsInDfs); this.TreeConnectResponse( treeConnectAndXResponseHeader.Mid + this.addMidMark, uid, tid, isSignSignatureZero, serviceShareType, (MessageStatus)treeConnectAndXResponseHeader.Status, isSigned, isInDFS, isRequestExtSignature); } #endregion }
/// <summary> /// Tree connect request. /// </summary> /// <param name="messageId">This is used to associate a response with a request.</param> /// <param name="sessionId">Session id. </param> /// <param name="isTidDisconnectionSet">Indicate whether the client sets the tid disconnection.</param> /// <param name="isRequestExtSignature">Indicate whether the client requests extended signature.</param> /// <param name="isRequestExtResponse"> /// Indicate whether the client requests extended information on Tree connection response. /// </param> /// <param name="share">The share method.</param> /// <param name="shareType">The type of resource the client intends to access.</param> /// <param name="isSigned" > /// Indicate whether the SUT has message signing enabled or required. /// </param> public void TreeConnectRequest( int messageId, int sessionId, bool isTidDisconnectionSet, bool isRequestExtSignature, bool isRequestExtResponse, string share, ShareType shareType, bool isSigned) { #region Create Packet ushort sessionUid = ushort.MinValue; if (!this.uId.ContainsKey((uint)sessionId)) { sessionUid = (ushort)sessionId; } else { sessionUid = (ushort)this.uId[(uint)sessionId]; } SmbAdapter.ServiceShareType = shareType; string shareName = string.Empty; switch (shareType) { case ShareType.NamedPipe: shareName = Site.Properties["SutNamedPipeFullName"]; break; case ShareType.Printer: shareName = Site.Properties["SutSharePrinterFullName"]; break; case ShareType.Disk: if (SmbAdapter.FsType == FileSystemType.Ntfs.ToString()) { if (share == ShareName.Share1.ToString()) { shareName = Site.Properties["SutNtfsShare1FullName"]; } else { if (share == ShareName.Share2.ToString()) { shareName = Site.Properties["SutNtfsShare2FullName"]; } else if (share == ShareName.DfsShare.ToString()) { shareName = Site.Properties["SutShareDfsTreeConnect"]; } else if (share == ShareName.QuotaShare.ToString()) { shareName = Site.Properties["SutNtfsQuotaShareFullName"]; } } } else { if (share == ShareName.Share1.ToString()) { shareName = Site.Properties["SutFatShare1FullName"]; } else { if (share == ShareName.Share2.ToString()) { shareName = Site.Properties["SutFatShare2FullName"]; } else if (share == ShareName.DfsShare.ToString()) shareName = Site.Properties["SutShareDfsTreeConnect"]; } } break; default: shareName = string.Empty; break; } SmbTreeConnectAndxRequestPacket smbPacket = new SmbTreeConnectAndxRequestPacket(); // Create TreeConnect Request. smbPacket = this.smbClientStack.CreateTreeConnectRequest(sessionUid, shareName); if (isSigned) { NamespaceCifs.CifsClientPerConnection connection = this.smbClientStack.Context.GetConnection(ConnectionId); NamespaceCifs.CifsClientPerSession session = this.smbClientStack.Context.GetSession(ConnectionId, sessionUid); 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; isSigned = smbPacket.IsSignRequired; ushort uid = this.QueryUidTable(smbPacketResponse); ushort tid = this.QueryTidTable(smbPacketResponse); VerifyTransport(smbPacketResponse); VerifyCommonMessageSyntax(smbPacketResponse); if (response.GetType() == typeof(SmbErrorResponsePacket)) { SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket; NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader; this.ErrorTreeConnectResponse( smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status, Boolean.Parse(this.Site.Properties["SHOULDMAYR357Implementation"])); } else { SmbTreeConnectAndxResponsePacket smbTreeConnectAndXPacket = response as SmbTreeConnectAndxResponsePacket; NamespaceCifs.SmbHeader treeConnectAndXResponseHeader = smbTreeConnectAndXPacket.SmbHeader; SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Parameters treeConnectAndXResponsePayload = smbTreeConnectAndXPacket.SmbParameters; NamespaceCifs.SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Data treeConnectAndXResponseData = smbTreeConnectAndXPacket.SmbData; ShareType serviceShareType = ShareType.CommunicationDevice; string shareTypesString = Encoding.ASCII.GetString(treeConnectAndXResponseData.Service); if (shareTypesString == Disk) { serviceShareType = ShareType.Disk; } else if (shareTypesString == Printer) { serviceShareType = ShareType.Printer; } else if (shareTypesString == NamePipe) { serviceShareType = ShareType.NamedPipe; } else if (shareTypesString == CommunicationsDevice) { serviceShareType = ShareType.CommunicationDevice; } bool isNotionSupported = Boolean.Parse(Site.Properties["IsNotionSupported"]); bool isSHI1005Set = Boolean.Parse(Site.Properties["IsShi1005Set"]); bool isNoAliasingSet = Boolean.Parse(Site.Properties["IsNoAliasingSet"]); bool isShortFileNameDisabled = Boolean.Parse(Site.Properties["IsShortFileNameDisabled"]); int allowedGuestAccess = Int32.Parse(Site.Properties["AllowedGuestAccess"]); // If the Flags contains SMB_FLAGS2_EXTENDED_SECURITY (0x0800), // means the server supports extended security if ((smbPacket.SmbParameters.Flags & 0x0800) == 0x0800) { VerifyMessageSystaxAccessMasksForPrinter( smbTreeConnectAndXPacket, shareType); } VerifyMessageSyntaxSmbComTreeConnectResponse( smbTreeConnectAndXPacket, isNotionSupported, isSHI1005Set, isNoAliasingSet, isShortFileNameDisabled, allowedGuestAccess, ((smbPacket.SmbParameters.Flags & 0x0008) == 0x0008)); uint computedMaxRights = (uint)Int32.Parse(Site.Properties["ComputedMaxRights"]); ushort computedOptionalSupport = (ushort)Int32.Parse(Site.Properties["ComputedOptionalSupport"]); bool isGuestAccountSupported = Boolean.Parse(Site.Properties["IsGuestAccountSupported"]); VerifyReceiveSmbComTreeConnectAndXRequest( smbTreeConnectAndXPacket, ((smbPacket.SmbParameters.Flags & 0x0008) == 0x0008), computedMaxRights, computedOptionalSupport, isGuestAccountSupported, isRequestExtSignature); bool isSignSignatureZero = (treeConnectAndXResponseHeader.SecurityFeatures == uint.MinValue); bool isInDFS = ((treeConnectAndXResponsePayload.OptionalSupport & SmbShareIsInDfs) == SmbShareIsInDfs); this.TreeConnectResponse( treeConnectAndXResponseHeader.Mid + this.addMidMark, uid, tid, isSignSignatureZero, serviceShareType, (MessageStatus)treeConnectAndXResponseHeader.Status, isSigned, isInDFS, isRequestExtSignature); } #endregion }