Trans2QueryPathInformationResponse.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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["
  52. + "createTime=" + Extensions.CreateDate(CreateTime)
  53. + ",lastAccessTime=" + Extensions.CreateDate(LastAccessTime)
  54. + ",lastWriteTime=" + Extensions.CreateDate(LastWriteTime)
  55. + ",changeTime=" + Extensions.CreateDate(ChangeTime)
  56. + ",attributes=0x" + Hexdump.ToHexString(Attributes, 4) + "]";
  57. }
  58. internal SmbQueryFileBasicInfo(Trans2QueryPathInformationResponse enclosing)
  59. {
  60. this._enclosing = enclosing;
  61. }
  62. private readonly Trans2QueryPathInformationResponse _enclosing;
  63. }
  64. internal class SmbQueryFileStandardInfo : IInfo
  65. {
  66. internal long AllocationSize;
  67. internal long EndOfFile;
  68. internal int NumberOfLinks;
  69. internal bool DeletePending;
  70. internal bool Directory;
  71. public virtual int GetAttributes()
  72. {
  73. return 0;
  74. }
  75. public virtual long GetCreateTime()
  76. {
  77. return 0L;
  78. }
  79. public virtual long GetLastWriteTime()
  80. {
  81. return 0L;
  82. }
  83. public virtual long GetSize()
  84. {
  85. return EndOfFile;
  86. }
  87. public override string ToString()
  88. {
  89. return "SmbQueryInfoStandard["
  90. + "allocationSize=" + AllocationSize
  91. + ",endOfFile=" + EndOfFile
  92. + ",numberOfLinks=" + NumberOfLinks
  93. + ",deletePending=" + DeletePending
  94. + ",directory=" + Directory + "]";
  95. }
  96. internal SmbQueryFileStandardInfo(Trans2QueryPathInformationResponse enclosing)
  97. {
  98. this._enclosing = enclosing;
  99. }
  100. private readonly Trans2QueryPathInformationResponse _enclosing;
  101. }
  102. private int _informationLevel;
  103. internal IInfo Info;
  104. internal Trans2QueryPathInformationResponse(int informationLevel)
  105. {
  106. this._informationLevel = informationLevel;
  107. SubCommand = Smb.SmbComTransaction.Trans2QueryPathInformation;
  108. }
  109. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  110. {
  111. return 0;
  112. }
  113. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  114. {
  115. return 0;
  116. }
  117. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  118. {
  119. return 0;
  120. }
  121. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len)
  122. {
  123. return 0;
  124. }
  125. internal override int ReadParametersWireFormat(byte[] buffer,
  126. int bufferIndex,
  127. int len)
  128. {
  129. // observed two zero bytes here with at least win98
  130. return 2;
  131. }
  132. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  133. {
  134. switch (_informationLevel)
  135. {
  136. case SMB_QUERY_FILE_BASIC_INFO:
  137. {
  138. return ReadSmbQueryFileBasicInfoWireFormat(buffer, bufferIndex);
  139. }
  140. case SMB_QUERY_FILE_STANDARD_INFO:
  141. {
  142. return ReadSmbQueryFileStandardInfoWireFormat(buffer, bufferIndex);
  143. }
  144. default:
  145. {
  146. return 0;
  147. }
  148. }
  149. }
  150. internal virtual int ReadSmbQueryFileStandardInfoWireFormat(byte[] buffer,
  151. int bufferIndex)
  152. {
  153. int start = bufferIndex;
  154. SmbQueryFileStandardInfo info = new SmbQueryFileStandardInfo(this);
  155. info.AllocationSize = ReadInt8(buffer, bufferIndex);
  156. bufferIndex += 8;
  157. info.EndOfFile = ReadInt8(buffer, bufferIndex);
  158. bufferIndex += 8;
  159. info.NumberOfLinks = ReadInt4(buffer, bufferIndex);
  160. bufferIndex += 4;
  161. info.DeletePending = (buffer[bufferIndex++] & unchecked(0xFF)) > 0;
  162. info.Directory = (buffer[bufferIndex++] & unchecked(0xFF)) > 0;
  163. this.Info = info;
  164. return bufferIndex - start;
  165. }
  166. internal virtual int ReadSmbQueryFileBasicInfoWireFormat(byte[] buffer,
  167. int bufferIndex)
  168. {
  169. int start = bufferIndex;
  170. SmbQueryFileBasicInfo info = new SmbQueryFileBasicInfo(this);
  171. info.CreateTime = ReadTime(buffer, bufferIndex);
  172. bufferIndex += 8;
  173. info.LastAccessTime = ReadTime(buffer, bufferIndex);
  174. bufferIndex += 8;
  175. info.LastWriteTime = ReadTime(buffer, bufferIndex);
  176. bufferIndex += 8;
  177. info.ChangeTime = ReadTime(buffer, bufferIndex);
  178. bufferIndex += 8;
  179. info.Attributes = ReadInt2(buffer, bufferIndex);
  180. bufferIndex += 2;
  181. this.Info = info;
  182. return bufferIndex - start;
  183. }
  184. public override string ToString()
  185. {
  186. return "Trans2QueryPathInformationResponse[" + base.ToString() + "]";
  187. }
  188. }
  189. }