/// <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> /// Create NTTransQueryQuota request for client to query quota on server. /// </summary> /// <param name = "messageId">the id of message, used to identity the request and the server response. </param> /// <param name = "sessionUid">the valid session id, must be response by server of the session setup request. </param> /// <param name = "treeId">the valid tree connect id, must be response by server of the tree connect. </param> /// <param name = "flags"> /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. /// </param> /// <param name = "flags2"> /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate /// various client and server capabilities. /// </param> /// <param name = "fileId">the valid file id to operation on, response by server. </param> /// <param name = "isReturnSingleEntry"> /// Indicates only a single entry is to be returned instead of filling the entire buffer. /// </param> /// <param name = "isRestartScan">Indicates that the scan of the quota information is to be restarted. </param> /// <param name = "sidListLength"> /// Supplies the length in bytes of the SidList (see below), or 0 if there is no SidList. /// </param> /// <param name = "startSidLength"> /// Supplies the length in bytes of the StartSid (see below), or 0 if there is no StartSid. MUST be ignored by /// the receiver if SidListLength is non-zero. /// </param> /// <param name = "startSidOffset"> /// Supplies the offset, in bytes, to the StartSid in the Parameter buffer /// </param> /// <returns>a nt transaction query quota request packet </returns> private SmbNtTransQueryQuotaRequestPacket CreateNTTransQueryQuotaRequest( ushort messageId, ushort sessionUid, ushort treeId, SmbHeader_Flags_Values flags, SmbHeader_Flags2_Values flags2, ushort fileId, bool isReturnSingleEntry, bool isRestartScan, int sidListLength, int startSidLength, int startSidOffset) { SmbNtTransQueryQuotaRequestPacket packet = new SmbNtTransQueryQuotaRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_NT_TRANSACT, messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2); // Set Smb_Parameters SMB_COM_NT_TRANSACT_Request_SMB_Parameters smbParameters = new SMB_COM_NT_TRANSACT_Request_SMB_Parameters(); smbParameters.MaxSetupCount = this.capability.MaxSetupCount; smbParameters.MaxParameterCount = this.capability.MaxParameterCount; smbParameters.MaxDataCount = this.capability.MaxDataCount; smbParameters.SetupCount = 0; // the correct count in word of the Setup is always 0. smbParameters.Function = (NtTransSubCommand)SmbNtTransSubCommand.NT_TRANSACT_QUERY_QUOTA; smbParameters.Setup = new ushort[0]; smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_NT_TRANSACT_Request_SMB_Parameters>( smbParameters) / SmbCapability.NUM_BYTES_OF_WORD); // Set Smb_Data SMB_COM_NT_TRANSACT_Request_SMB_Data smbData = new SMB_COM_NT_TRANSACT_Request_SMB_Data(); // Set Nt Transaction Parameters NT_TRANSACT_QUERY_QUOTA_Request_NT_Trans_Parameters ntTransParameters = new NT_TRANSACT_QUERY_QUOTA_Request_NT_Trans_Parameters(); ntTransParameters.Fid = fileId; if (isReturnSingleEntry) { ntTransParameters.ReturnSingleEntry = 0x01; } if (isRestartScan) { ntTransParameters.RestartScan = 0x01; } ntTransParameters.SidListLength = (uint)sidListLength; ntTransParameters.StartSidLength = (uint)startSidLength; ntTransParameters.StartSidOffset = (uint)startSidOffset; packet.SmbParameters = smbParameters; packet.SmbData = smbData; packet.NtTransParameters = ntTransParameters; packet.UpdateCountAndOffset(); return packet; }
/// <summary> /// Deep copy constructor. /// </summary> public SmbNtTransQueryQuotaRequestPacket(SmbNtTransQueryQuotaRequestPacket packet) : base(packet) { }
/// <summary> /// NT_TRANSACT_QUERY_QUOTA Client 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="isReturnSingle"> /// A bool variable, if set, which indicates only a single entry is to be returned instead of filling the /// entire buffer. /// </param> /// <param name="isRestartScan"> /// A bool variable, if set, which indicates that the scan of the quota information is to be restarted. /// </param> /// <param name="sidListLength">Supplies the length in bytes of the SidList.</param> /// <param name="startSidLength">Supplies the length in bytes of the StartSid.</param> /// <param name="startSidOffset"> /// Supplies the offset, in bytes, to the StartSid in the Parameter buffer. /// </param> public void NtTransQueryQuotaRequest( int messageId, int sessionId, int treeId, bool isSigned, int fid, bool isReturnSingle, bool isRestartScan, int sidListLength, int startSidLength, int startSidOffset) { #region Create Pcaket SmbNtTransQueryQuotaRequestPacket smbPacket = new SmbNtTransQueryQuotaRequestPacket(); ushort uid = (ushort)this.uId[(uint)sessionId]; ushort fileId = (ushort)this.fId[(uint)fid]; this.IsReturnSingleEntry = isReturnSingle; smbPacket = this.smbClientStack.CreateNTTransQueryQuotaRequest( fileId, this.IsReturnSingleEntry, isRestartScan, sidListLength, startSidLength, startSidOffset); 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 { SmbNtTransQueryQuotaResponsePacket smbNtTransQueryQuotaPacket = response as SmbNtTransQueryQuotaResponsePacket; NamespaceCifs.SmbHeader ntTransQueryQuotaResponseHeader = smbNtTransQueryQuotaPacket.SmbHeader; int quotaUsed = (int)uint.MinValue; if (IsQueryQuotaFirstResponse) { this.NtTransQueryQuotaResponse( ntTransQueryQuotaResponseHeader.Mid + this.addMidMark, this.QueryUidTable(smbPacketResponse), this.QueryTidTable(smbPacketResponse), (smbPacketResponse).IsSignRequired, quotaUsed, (MessageStatus)ntTransQueryQuotaResponseHeader.Status); IsQueryQuotaFirstResponse = false; } VerifyNtTransQueryQuotaRequestAndResponse(this.IsReturnSingleEntry, smbNtTransQueryQuotaPacket); int quotaInfoCount = Convert.ToInt32(Site.Properties["QuotaInfoCount"]); VerifyMessageSyntaxNtTransactQueryQuotaResponse( smbNtTransQueryQuotaPacket, sidListLength, startSidLength, quotaInfoCount, smbPacket.SmbParameters.MaxDataCount); this.IsReturnSingleEntry = false; } #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; }