SmbConstants.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 System;
  18. using System.Collections.Generic;
  19. using System.Net;
  20. using SharpCifs.Util.Sharpen;
  21. namespace SharpCifs.Smb
  22. {
  23. internal static class SmbConstants
  24. {
  25. internal static void ApplyConfig()
  26. {
  27. SmbConstants.Laddr = Config.GetLocalHost();
  28. SmbConstants.Lport = Config.GetInt("jcifs.smb.client.lport", 0);
  29. SmbConstants.MaxMpxCount = Config.GetInt("jcifs.smb.client.maxMpxCount", SmbConstants.DefaultMaxMpxCount);
  30. SmbConstants.SndBufSize = Config.GetInt("jcifs.smb.client.snd_buf_size", SmbConstants.DefaultSndBufSize);
  31. SmbConstants.RcvBufSize = Config.GetInt("jcifs.smb.client.rcv_buf_size", SmbConstants.DefaultRcvBufSize);
  32. SmbConstants.UseUnicode = Config.GetBoolean("jcifs.smb.client.useUnicode", true);
  33. SmbConstants.ForceUnicode = Config.GetBoolean("jcifs.smb.client.useUnicode", false);
  34. SmbConstants.UseNtstatus = Config.GetBoolean("jcifs.smb.client.useNtStatus", true);
  35. SmbConstants.Signpref = Config.GetBoolean("jcifs.smb.client.signingPreferred", false);
  36. SmbConstants.UseNtsmbs = Config.GetBoolean("jcifs.smb.client.useNTSmbs", true);
  37. SmbConstants.UseExtsec = Config.GetBoolean("jcifs.smb.client.useExtendedSecurity", true);
  38. SmbConstants.NetbiosHostname = Config.GetProperty("jcifs.netbios.hostname", null);
  39. SmbConstants.LmCompatibility = Config.GetInt("jcifs.smb.lmCompatibility", 3);
  40. SmbConstants.UseBatching = Config.GetBoolean("jcifs.smb.client.useBatching", true);
  41. SmbConstants.OemEncoding = Config.GetProperty("jcifs.encoding", Config.DefaultOemEncoding);
  42. SmbConstants.DefaultFlags2 =
  43. SmbConstants.Flags2LongFilenames
  44. | SmbConstants.Flags2ExtendedAttributes
  45. | (SmbConstants.UseExtsec
  46. ? SmbConstants.Flags2ExtendedSecurityNegotiation
  47. : 0)
  48. | (SmbConstants.Signpref
  49. ? SmbConstants.Flags2SecuritySignatures
  50. : 0)
  51. | (SmbConstants.UseNtstatus
  52. ? SmbConstants.Flags2Status32
  53. : 0)
  54. | (SmbConstants.UseUnicode
  55. ? SmbConstants.Flags2Unicode
  56. : 0);
  57. SmbConstants.DefaultCapabilities =
  58. (SmbConstants.UseNtsmbs
  59. ? SmbConstants.CapNtSmbs
  60. : 0)
  61. | (SmbConstants.UseNtstatus
  62. ? SmbConstants.CapStatus32
  63. : 0)
  64. | (SmbConstants.UseUnicode
  65. ? SmbConstants.CapUnicode
  66. : 0)
  67. | SmbConstants.CapDfs;
  68. SmbConstants.Flags2 = Config.GetInt("jcifs.smb.client.flags2", SmbConstants.DefaultFlags2);
  69. SmbConstants.Capabilities = Config.GetInt("jcifs.smb.client.capabilities", SmbConstants.DefaultCapabilities);
  70. SmbConstants.TcpNodelay = Config.GetBoolean("jcifs.smb.client.tcpNoDelay", false);
  71. SmbConstants.ResponseTimeout = Config.GetInt("jcifs.smb.client.responseTimeout", SmbConstants.DefaultResponseTimeout);
  72. SmbConstants.SsnLimit = Config.GetInt("jcifs.smb.client.ssnLimit", SmbConstants.DefaultSsnLimit);
  73. SmbConstants.SoTimeout = Config.GetInt("jcifs.smb.client.soTimeout", SmbConstants.DefaultSoTimeout);
  74. SmbConstants.ConnTimeout = Config.GetInt("jcifs.smb.client.connTimeout", SmbConstants.DefaultConnTimeout);
  75. SmbConstants.NativeOs = Config.GetProperty("jcifs.smb.client.nativeOs", Runtime.GetProperty("os.name"));
  76. SmbConstants.NativeLanman = Config.GetProperty("jcifs.smb.client.nativeLanMan", "jCIFS");
  77. }
  78. public static readonly int DefaultPort = 445;
  79. public static readonly int DefaultMaxMpxCount = 10;
  80. public static readonly int DefaultResponseTimeout = 30000;
  81. public static readonly int DefaultSoTimeout = 35000;
  82. public static readonly int DefaultRcvBufSize = 60416;
  83. public static readonly int DefaultSndBufSize = 16644;
  84. public static readonly int DefaultSsnLimit = 250;
  85. public static readonly int DefaultConnTimeout = 35000;
  86. public static IPAddress Laddr { get; internal set; }
  87. = Config.GetLocalHost();
  88. public static int Lport { get; internal set; }
  89. = Config.GetInt("jcifs.smb.client.lport", 0);
  90. public static int MaxMpxCount { get; internal set; }
  91. = Config.GetInt("jcifs.smb.client.maxMpxCount", DefaultMaxMpxCount);
  92. public static int SndBufSize { get; internal set; }
  93. = Config.GetInt("jcifs.smb.client.snd_buf_size", DefaultSndBufSize);
  94. public static int RcvBufSize { get; internal set; }
  95. = Config.GetInt("jcifs.smb.client.rcv_buf_size", DefaultRcvBufSize);
  96. public static bool UseUnicode { get; internal set; }
  97. = Config.GetBoolean("jcifs.smb.client.useUnicode", true);
  98. public static bool ForceUnicode { get; internal set; }
  99. = Config.GetBoolean("jcifs.smb.client.useUnicode", false);
  100. public static bool UseNtstatus { get; internal set; }
  101. = Config.GetBoolean("jcifs.smb.client.useNtStatus", true);
  102. public static bool Signpref { get; internal set; }
  103. = Config.GetBoolean("jcifs.smb.client.signingPreferred", false);
  104. public static bool UseNtsmbs { get; internal set; }
  105. = Config.GetBoolean("jcifs.smb.client.useNTSmbs", true);
  106. public static bool UseExtsec { get; internal set; }
  107. = Config.GetBoolean("jcifs.smb.client.useExtendedSecurity", true);
  108. public static string NetbiosHostname { get; internal set; }
  109. = Config.GetProperty("jcifs.netbios.hostname", null);
  110. public static int LmCompatibility { get; internal set; }
  111. = Config.GetInt("jcifs.smb.lmCompatibility", 3);
  112. public static readonly int FlagsNone = unchecked(0x00);
  113. public static readonly int FlagsLockAndReadWriteAndUnlock = unchecked(0x01);
  114. public static readonly int FlagsReceiveBufferPosted = unchecked(0x02);
  115. public static readonly int FlagsPathNamesCaseless = unchecked(0x08);
  116. public static readonly int FlagsPathNamesCanonicalized = unchecked(0x10);
  117. public static readonly int FlagsOplockRequestedOrGranted = unchecked(0x20);
  118. public static readonly int FlagsNotifyOfModifyAction = unchecked(0x40);
  119. public static readonly int FlagsResponse = unchecked(0x80);
  120. public static readonly int Flags2None = unchecked(0x0000);
  121. public static readonly int Flags2LongFilenames = unchecked(0x0001);
  122. public static readonly int Flags2ExtendedAttributes = unchecked(0x0002);
  123. public static readonly int Flags2SecuritySignatures = unchecked(0x0004);
  124. public static readonly int Flags2ExtendedSecurityNegotiation = unchecked(0x0800);
  125. public static readonly int Flags2ResolvePathsInDfs = unchecked(0x1000);
  126. public static readonly int Flags2PermitReadIfExecutePerm = unchecked(0x2000);
  127. public static readonly int Flags2Status32 = unchecked(0x4000);
  128. public static readonly int Flags2Unicode = unchecked(0x8000);
  129. public static readonly int CapNone = unchecked(0x0000);
  130. public static readonly int CapRawMode = unchecked(0x0001);
  131. public static readonly int CapMpxMode = unchecked(0x0002);
  132. public static readonly int CapUnicode = unchecked(0x0004);
  133. public static readonly int CapLargeFiles = unchecked(0x0008);
  134. public static readonly int CapNtSmbs = unchecked(0x0010);
  135. public static readonly int CapRpcRemoteApis = unchecked(0x0020);
  136. public static readonly int CapStatus32 = unchecked(0x0040);
  137. public static readonly int CapLevelIiOplocks = unchecked(0x0080);
  138. public static readonly int CapLockAndRead = unchecked(0x0100);
  139. public static readonly int CapNtFind = unchecked(0x0200);
  140. public static readonly int CapDfs = unchecked(0x1000);
  141. public static readonly int CapExtendedSecurity = unchecked((int)(0x80000000));
  142. public static readonly int AttrReadonly = unchecked(0x01);
  143. public static readonly int AttrHidden = unchecked(0x02);
  144. public static readonly int AttrSystem = unchecked(0x04);
  145. public static readonly int AttrVolume = unchecked(0x08);
  146. public static readonly int AttrDirectory = unchecked(0x10);
  147. public static readonly int AttrArchive = unchecked(0x20);
  148. public static readonly int AttrCompressed = unchecked(0x800);
  149. public static readonly int AttrNormal = unchecked(0x080);
  150. public static readonly int AttrTemporary = unchecked(0x100);
  151. public static readonly int FileReadData = unchecked(0x00000001);
  152. public static readonly int FileWriteData = unchecked(0x00000002);
  153. public static readonly int FileAppendData = unchecked(0x00000004);
  154. public static readonly int FileReadEa = unchecked(0x00000008);
  155. public static readonly int FileWriteEa = unchecked(0x00000010);
  156. public static readonly int FileExecute = unchecked(0x00000020);
  157. public static readonly int FileDelete = unchecked(0x00000040);
  158. public static readonly int FileReadAttributes = unchecked(0x00000080);
  159. public static readonly int FileWriteAttributes = unchecked(0x00000100);
  160. public static readonly int Delete = unchecked(0x00010000);
  161. public static readonly int ReadControl = unchecked(0x00020000);
  162. public static readonly int WriteDac = unchecked(0x00040000);
  163. public static readonly int WriteOwner = unchecked(0x00080000);
  164. public static readonly int Synchronize = unchecked(0x00100000);
  165. public static readonly int GenericAll = unchecked(0x10000000);
  166. public static readonly int GenericExecute = unchecked(0x20000000);
  167. public static readonly int GenericWrite = unchecked(0x40000000);
  168. public static readonly int GenericRead = unchecked((int)(0x80000000));
  169. public static readonly int FlagsTargetMustBeFile = unchecked(0x0001);
  170. public static readonly int FlagsTargetMustBeDirectory = unchecked(0x0002);
  171. public static readonly int FlagsCopyTargetModeAscii = unchecked(0x0004);
  172. public static readonly int FlagsCopySourceModeAscii = unchecked(0x0008);
  173. public static readonly int FlagsVerifyAllWrites = unchecked(0x0010);
  174. public static readonly int FlagsTreeCopy = unchecked(0x0020);
  175. public static readonly int OpenFunctionFailIfExists = unchecked(0x0000);
  176. public static readonly int OpenFunctionOverwriteIfExists = unchecked(0x0020);
  177. public static readonly int Pid = (int)(new Random().NextDouble() * 65536d);
  178. public static readonly int SecurityShare = unchecked(0x00);
  179. public static readonly int SecurityUser = unchecked(0x01);
  180. public static readonly int CmdOffset = 4;
  181. public static readonly int ErrorCodeOffset = 5;
  182. public static readonly int FlagsOffset = 9;
  183. public static readonly int SignatureOffset = 14;
  184. public static readonly int TidOffset = 24;
  185. public static readonly int HeaderLength = 32;
  186. public static readonly long MillisecondsBetween1970And1601 = 11644473600000L;
  187. public static readonly TimeZoneInfo Tz = TimeZoneInfo.Local;
  188. public static bool UseBatching { get; internal set; }
  189. = Config.GetBoolean("jcifs.smb.client.useBatching", true);
  190. public static string OemEncoding { get; internal set; }
  191. = Config.GetProperty("jcifs.encoding", Config.DefaultOemEncoding);
  192. public static string UniEncoding = "UTF-16LE";
  193. public static int DefaultFlags2 { get; internal set; }
  194. = Flags2LongFilenames
  195. | Flags2ExtendedAttributes
  196. | (UseExtsec
  197. ? Flags2ExtendedSecurityNegotiation
  198. : 0)
  199. | (Signpref
  200. ? Flags2SecuritySignatures
  201. : 0)
  202. | (UseNtstatus
  203. ? Flags2Status32
  204. : 0)
  205. | (UseUnicode
  206. ? Flags2Unicode
  207. : 0);
  208. public static int DefaultCapabilities { get; internal set; }
  209. = (UseNtsmbs
  210. ? CapNtSmbs
  211. : 0)
  212. | (UseNtstatus
  213. ? CapStatus32
  214. : 0)
  215. | (UseUnicode
  216. ? CapUnicode
  217. : 0)
  218. | CapDfs;
  219. public static int Flags2 { get; internal set; }
  220. = Config.GetInt("jcifs.smb.client.flags2", DefaultFlags2);
  221. public static int Capabilities { get; internal set; }
  222. = Config.GetInt("jcifs.smb.client.capabilities", DefaultCapabilities);
  223. public static bool TcpNodelay { get; internal set; }
  224. = Config.GetBoolean("jcifs.smb.client.tcpNoDelay", false);
  225. public static int ResponseTimeout { get; internal set; }
  226. = Config.GetInt("jcifs.smb.client.responseTimeout", DefaultResponseTimeout);
  227. public static readonly List<SmbTransport> Connections = new List<SmbTransport>();
  228. public static int SsnLimit { get; internal set; }
  229. = Config.GetInt("jcifs.smb.client.ssnLimit", DefaultSsnLimit);
  230. public static int SoTimeout { get; internal set; }
  231. = Config.GetInt("jcifs.smb.client.soTimeout", DefaultSoTimeout);
  232. public static int ConnTimeout { get; internal set; }
  233. = Config.GetInt("jcifs.smb.client.connTimeout", DefaultConnTimeout);
  234. public static string NativeOs { get; internal set; }
  235. = Config.GetProperty("jcifs.smb.client.nativeOs", Runtime.GetProperty("os.name"));
  236. public static string NativeLanman { get; internal set; }
  237. = Config.GetProperty("jcifs.smb.client.nativeLanMan", "jCIFS");
  238. public static readonly int VcNumber = 1;
  239. public static SmbTransport NullTransport = new SmbTransport(null, 0, null, 0);
  240. // file attribute encoding
  241. // extended file attribute encoding(others same as above)
  242. // access mask encoding
  243. // 1
  244. // 2
  245. // 3
  246. // 4
  247. // 5
  248. // 6
  249. // 7
  250. // 8
  251. // 9
  252. // 16
  253. // 17
  254. // 18
  255. // 19
  256. // 20
  257. // 28
  258. // 29
  259. // 30
  260. // 31
  261. // flags for move and copy
  262. // open function
  263. }
  264. }