/// <summary> /// find the nt transaction packets /// </summary> /// <param name="command">the command of nt transaction</param> /// <param name="setup">the setup contains the sub command</param> /// <returns>the target nt transaction packet</returns> private static SmbPacket FindTheNtTransPacket(NtTransSubCommand command, byte[] setup) { SmbPacket smbPacket = null; switch (command) { case NtTransSubCommand.NT_TRANSACT_CREATE: smbPacket = new SmbNtTransactCreateRequestPacket(); break; case NtTransSubCommand.NT_TRANSACT_RENAME: smbPacket = new SmbNtTransRenameRequestPacket(); break; case NtTransSubCommand.NT_TRANSACT_IOCTL: NT_TRANSACT_IOCTL_SETUP subCommand = CifsMessageUtils.ToStuct <NT_TRANSACT_IOCTL_SETUP>(setup); switch ((NtTransFunctionCode)subCommand.FunctionCode) { case NtTransFunctionCode.FSCTL_SRV_ENUMERATE_SNAPSHOTS: smbPacket = new SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket(); break; case NtTransFunctionCode.FSCTL_SRV_REQUEST_RESUME_KEY: smbPacket = new SmbNtTransFsctlSrvRequestResumeKeyRequestPacket(); break; case NtTransFunctionCode.FSCTL_SRV_COPYCHUNK: smbPacket = new SmbNtTransFsctlSrvCopyChunkRequestPacket(); break; default: smbPacket = new SmbNtTransactIoctlRequestPacket(); break; } break; default: switch ((SmbNtTransSubCommand)command) { case SmbNtTransSubCommand.NT_TRANSACT_QUERY_QUOTA: smbPacket = new SmbNtTransQueryQuotaRequestPacket(); break; case SmbNtTransSubCommand.NT_TRANSACT_SET_QUOTA: smbPacket = new SmbNtTransSetQuotaRequestPacket(); break; } break; } return(smbPacket); }
/// <summary> /// Deep copy constructor. /// </summary> public SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket( SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket packet) : base(packet) { }
/// <summary> /// FSCTL_SRV_ENUMERATE_SNAPSHOTS Request. /// </summary> /// <param name="messageId">This is used to associate a response with a request.</param> /// <param name="sessionId"> /// Set this value to 0 to request a new session setup, or set this value to a previously established session /// identifier to request reauthenticate to an existing session. /// </param> /// <param name="treeId"> /// This field identifies the subdirectory (or tree) (also referred as a share in this document) on the /// server that the client is accessing. /// </param> /// <param name="isSigned"> /// Indicate whether the SUT has message signing enabled or required. /// </param> /// <param name="fid">The file identifier.</param> /// <param name="fsctlMaxDataCount">used to control the MaxDataCount in FSCTL_SRV_ENUMERATE_SNAPSHOTS.</param> public void FsctlSrvEnumSnapshotsRequest( int messageId, int sessionId, int treeId, bool isSigned, int fid, MaxDataCount fsctlMaxDataCount) { #region Create Packet SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket smbPacket = new SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket(); ushort uid = (ushort)this.uId[(uint)sessionId]; int maxDataCountSize = (int)uint.MinValue; int maxLevel = (int)fsctlMaxDataCount; if (maxLevel == (int)MaxDataCount.VerySmall) { maxDataCountSize = VerySmall; } else if (maxLevel == (int)MaxDataCount.Mid) { maxDataCountSize = Mid; } else if (maxLevel == (int)MaxDataCount.VeryLarge) { maxDataCountSize = VeryLarge; } byte isFlags = byte.MinValue; smbPacket = this.smbClientStack.CreateNTTransIOCtlEnumerateSnapShotsRequest( (ushort)this.fId[(uint)fid], true, isFlags, maxDataCountSize); 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 { SmbNtTransFsctlSrvEnumerateSnapshotsResponsePacket smbFsctlSrvEnumerateSnapshotPacket = response as SmbNtTransFsctlSrvEnumerateSnapshotsResponsePacket; NamespaceCifs.SmbHeader ntTransFsctlSrvEnumerateSnapshotsResponseHeader = smbFsctlSrvEnumerateSnapshotPacket.SmbHeader; NT_TRANSACT_ENUMERATE_SNAPSHOTS_Response_NT_Trans_Data ntTransFsctlSrvEnumerateSnapshotsResponsePayloadHeader = smbFsctlSrvEnumerateSnapshotPacket.NtTransData; messageId = ntTransFsctlSrvEnumerateSnapshotsResponseHeader.Mid; MessageStatus messageStatus = (MessageStatus)ntTransFsctlSrvEnumerateSnapshotsResponseHeader.Status; int numberOfSnapShots = (int)ntTransFsctlSrvEnumerateSnapshotsResponsePayloadHeader.NumberOfSnapShots; int numberOfSnapShotsReturned = (int)ntTransFsctlSrvEnumerateSnapshotsResponsePayloadHeader.NumberOfSnapShotsReturned; IntegerCompare numberOfSnapShotsCompared; if (numberOfSnapShotsReturned < numberOfSnapShots) { numberOfSnapShotsCompared = IntegerCompare.Smaller; } else if (numberOfSnapShotsReturned > numberOfSnapShots) { numberOfSnapShotsCompared = IntegerCompare.Larger; } else { numberOfSnapShotsCompared = IntegerCompare.Equal; } VerifyMessageSyntaxFsctlSrvEnumerateSnapshotsRequest(smbFsctlSrvEnumerateSnapshotPacket); int expectedSnapShotsCount = Int32.Parse(Site.Properties["ExpectedSnapShotsCount"]); int expectedSnapshotsReturnedCount = Int32.Parse(Site.Properties["ExpectedSnapshotsReturnedCount"]); bool isMaxDataCountLargeEnough = false; if (fsctlMaxDataCount == MaxDataCount.Mid) { isMaxDataCountLargeEnough = false; } else { isMaxDataCountLargeEnough = true; } VerifyReceiveFsctlSrvEnumerateSnapshotsFunctionCode( smbFsctlSrvEnumerateSnapshotPacket, expectedSnapShotsCount, expectedSnapshotsReturnedCount, isMaxDataCountLargeEnough); isMaxDataCountLargeEnough = false; this.FsctlSrvEnumSnapshotsResponse( messageId + this.addMidMark, this.QueryUidTable(smbPacketResponse), this.QueryTidTable(smbPacketResponse), (smbPacketResponse).IsSignRequired, messageStatus, numberOfSnapShotsCompared); } #endregion }
/// <summary> /// find the nt transaction packets /// </summary> /// <param name="command">the command of nt transaction</param> /// <param name="setup">the setup contains the sub command</param> /// <returns>the target nt transaction packet</returns> private static SmbPacket FindTheNtTransPacket(NtTransSubCommand command, byte[] setup) { SmbPacket smbPacket = null; switch (command) { case NtTransSubCommand.NT_TRANSACT_CREATE: smbPacket = new SmbNtTransactCreateRequestPacket(); break; case NtTransSubCommand.NT_TRANSACT_RENAME: smbPacket = new SmbNtTransRenameRequestPacket(); break; case NtTransSubCommand.NT_TRANSACT_IOCTL: NT_TRANSACT_IOCTL_SETUP subCommand = CifsMessageUtils.ToStuct<NT_TRANSACT_IOCTL_SETUP>(setup); switch ((NtTransFunctionCode)subCommand.FunctionCode) { case NtTransFunctionCode.FSCTL_SRV_ENUMERATE_SNAPSHOTS: smbPacket = new SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket(); break; case NtTransFunctionCode.FSCTL_SRV_REQUEST_RESUME_KEY: smbPacket = new SmbNtTransFsctlSrvRequestResumeKeyRequestPacket(); break; case NtTransFunctionCode.FSCTL_SRV_COPYCHUNK: smbPacket = new SmbNtTransFsctlSrvCopyChunkRequestPacket(); break; default: smbPacket = new SmbNtTransactIoctlRequestPacket(); break; } break; default: switch ((SmbNtTransSubCommand)command) { case SmbNtTransSubCommand.NT_TRANSACT_QUERY_QUOTA: smbPacket = new SmbNtTransQueryQuotaRequestPacket(); break; case SmbNtTransSubCommand.NT_TRANSACT_SET_QUOTA: smbPacket = new SmbNtTransSetQuotaRequestPacket(); break; } break; } return smbPacket; }