Trans2QueryPathInformationResponse.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using SharpCifs.Util;
  18. using SharpCifs.Util.Sharpen;
  19. namespace SharpCifs.Smb
  20. {
  21. internal class Trans2QueryPathInformationResponse : SmbComTransactionResponse
  22. {
  23. internal const int SMB_QUERY_FILE_BASIC_INFO = unchecked(0x101);
  24. internal const int SMB_QUERY_FILE_STANDARD_INFO = unchecked(0x102);
  25. internal class SmbQueryFileBasicInfo : IInfo
  26. {
  27. internal long CreateTime;
  28. internal long LastAccessTime;
  29. internal long LastWriteTime;
  30. internal long ChangeTime;
  31. internal int Attributes;
  32. // information levels
  33. public virtual int GetAttributes()
  34. {
  35. return Attributes;
  36. }
  37. public virtual long GetCreateTime()
  38. {
  39. return CreateTime;
  40. }
  41. public virtual long GetLastWriteTime()
  42. {
  43. return LastWriteTime;
  44. }
  45. public virtual long GetSize()
  46. {
  47. return 0L;
  48. }
  49. public override string ToString()
  50. {
  51. return "SmbQueryFileBasicInfo[" + "createTime=" + Extensions.CreateDate
  52. (CreateTime) + ",lastAccessTime=" + Extensions.CreateDate(LastAccessTime
  53. ) + ",lastWriteTime=" + Extensions.CreateDate(LastWriteTime) + ",changeTime="
  54. + Extensions.CreateDate(ChangeTime) + ",attributes=0x" + Hexdump.ToHexString
  55. (Attributes, 4) + "]";
  56. }
  57. internal SmbQueryFileBasicInfo(Trans2QueryPathInformationResponse enclosing)
  58. {
  59. this._enclosing = enclosing;
  60. }
  61. private readonly Trans2QueryPathInformationResponse _enclosing;
  62. }
  63. internal class SmbQueryFileStandardInfo : IInfo
  64. {
  65. internal long AllocationSize;
  66. internal long EndOfFile;
  67. internal int NumberOfLinks;
  68. internal bool DeletePending;
  69. internal bool Directory;
  70. public virtual int GetAttributes()
  71. {
  72. return 0;
  73. }
  74. public virtual long GetCreateTime()
  75. {
  76. return 0L;
  77. }
  78. public virtual long GetLastWriteTime()
  79. {
  80. return 0L;
  81. }
  82. public virtual long GetSize()
  83. {
  84. return EndOfFile;
  85. }
  86. public override string ToString()
  87. {
  88. return "SmbQueryInfoStandard[" + "allocationSize=" + AllocationSize
  89. + ",endOfFile=" + EndOfFile + ",numberOfLinks=" + NumberOfLinks + ",deletePending="
  90. + DeletePending + ",directory=" + Directory + "]";
  91. }
  92. internal SmbQueryFileStandardInfo(Trans2QueryPathInformationResponse enclosing)
  93. {
  94. this._enclosing = enclosing;
  95. }
  96. private readonly Trans2QueryPathInformationResponse _enclosing;
  97. }
  98. private int _informationLevel;
  99. internal IInfo Info;
  100. internal Trans2QueryPathInformationResponse(int informationLevel)
  101. {
  102. this._informationLevel = informationLevel;
  103. SubCommand = Smb.SmbComTransaction.Trans2QueryPathInformation;
  104. }
  105. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  106. {
  107. return 0;
  108. }
  109. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  110. {
  111. return 0;
  112. }
  113. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  114. {
  115. return 0;
  116. }
  117. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
  118. )
  119. {
  120. return 0;
  121. }
  122. internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
  123. len)
  124. {
  125. // observed two zero bytes here with at least win98
  126. return 2;
  127. }
  128. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  129. {
  130. switch (_informationLevel)
  131. {
  132. case SMB_QUERY_FILE_BASIC_INFO:
  133. {
  134. return ReadSmbQueryFileBasicInfoWireFormat(buffer, bufferIndex);
  135. }
  136. case SMB_QUERY_FILE_STANDARD_INFO:
  137. {
  138. return ReadSmbQueryFileStandardInfoWireFormat(buffer, bufferIndex);
  139. }
  140. default:
  141. {
  142. return 0;
  143. }
  144. }
  145. }
  146. internal virtual int ReadSmbQueryFileStandardInfoWireFormat(byte[] buffer, int bufferIndex
  147. )
  148. {
  149. int start = bufferIndex;
  150. SmbQueryFileStandardInfo info = new SmbQueryFileStandardInfo
  151. (this);
  152. info.AllocationSize = ReadInt8(buffer, bufferIndex);
  153. bufferIndex += 8;
  154. info.EndOfFile = ReadInt8(buffer, bufferIndex);
  155. bufferIndex += 8;
  156. info.NumberOfLinks = ReadInt4(buffer, bufferIndex);
  157. bufferIndex += 4;
  158. info.DeletePending = (buffer[bufferIndex++] & unchecked(0xFF)) > 0;
  159. info.Directory = (buffer[bufferIndex++] & unchecked(0xFF)) > 0;
  160. this.Info = info;
  161. return bufferIndex - start;
  162. }
  163. internal virtual int ReadSmbQueryFileBasicInfoWireFormat(byte[] buffer, int bufferIndex
  164. )
  165. {
  166. int start = bufferIndex;
  167. SmbQueryFileBasicInfo info = new SmbQueryFileBasicInfo
  168. (this);
  169. info.CreateTime = ReadTime(buffer, bufferIndex);
  170. bufferIndex += 8;
  171. info.LastAccessTime = ReadTime(buffer, bufferIndex);
  172. bufferIndex += 8;
  173. info.LastWriteTime = ReadTime(buffer, bufferIndex);
  174. bufferIndex += 8;
  175. info.ChangeTime = ReadTime(buffer, bufferIndex);
  176. bufferIndex += 8;
  177. info.Attributes = ReadInt2(buffer, bufferIndex);
  178. bufferIndex += 2;
  179. this.Info = info;
  180. return bufferIndex - start;
  181. }
  182. public override string ToString()
  183. {
  184. return "Trans2QueryPathInformationResponse[" + base.ToString() + "]";
  185. }
  186. }
  187. }