smb_defs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. //---------------------------------------------------------------------------
  2. // __________________ _________ _____ _____ .__ ._.
  3. // \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. // | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. // | | \| ` \/ / Y \ / | | \ ___/ \|
  6. // |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. // \/ \/ \/ \/ )/ \/ \/ \/
  8. //
  9. // This file is part of libdsm. Copyright © 2014 VideoLabs SAS
  10. //
  11. // Author: Julien 'Lta' BALLET <contact@lta.io>
  12. //
  13. // This program is free software. It comes without any warranty, to the extent
  14. // permitted by applicable law. You can redistribute it and/or modify it under
  15. // the terms of the Do What The Fuck You Want To Public License, Version 2, as
  16. // published by Sam Hocevar. See the COPYING file for more details.
  17. //----------------------------------------------------------------------------
  18. /**
  19. * @file smb_defs.h
  20. * @brief SMB usefull constants
  21. */
  22. #ifndef __BSDM_SMB_DEFS_H_
  23. #define __BSDM_SMB_DEFS_H_
  24. #define SMB_DEFAULT_BUFSIZE (8192)
  25. enum
  26. {
  27. /// SMB with Direct-TCP connection (OSX supports only this)
  28. SMB_TRANSPORT_TCP = 1,
  29. /// SMB with Netbios over TCP (older mechanism)
  30. SMB_TRANSPORT_NBT = 2
  31. };
  32. //-----------------------------------------------------------------------------/
  33. // SMB Session states
  34. //-----------------------------------------------------------------------------/
  35. enum
  36. {
  37. /// Error state, there was an error somewhere
  38. SMB_STATE_ERROR = -1,
  39. /// The SMB session has just been created
  40. SMB_STATE_NEW = 0,
  41. /// A Netbios session has been successfully established.
  42. SMB_STATE_NETBIOS_OK = 1,
  43. /// Dialect was successfully negotiated
  44. SMB_STATE_DIALECT_OK = 2,
  45. /// Session Authentication was successfull, you can become nasty
  46. SMB_STATE_SESSION_OK = 3
  47. };
  48. //-----------------------------------------------------------------------------/
  49. // smb_fseek() operations
  50. //-----------------------------------------------------------------------------/
  51. // smb_fseek operations
  52. enum
  53. {
  54. /// Set the read pointer at the given position
  55. SMB_SEEK_SET = 0,
  56. /// Adjusts the read pointer relatively to the actual position
  57. SMB_SEEK_CUR = 1
  58. };
  59. enum smb_session_supports_what
  60. {
  61. SMB_SESSION_XSEC = 0,
  62. };
  63. //-----------------------------------------------------------------------------/
  64. // File access rights (used when smb_open() files)
  65. //-----------------------------------------------------------------------------/
  66. /// Flag for smb_file_open. Request right for reading
  67. #define SMB_MOD_READ (1 << 0)
  68. /// Flag for smb_file_open. Request right for writing
  69. #define SMB_MOD_WRITE (1 << 1)
  70. /// Flag for smb_file_open. Request right for appending
  71. #define SMB_MOD_APPEND (1 << 2)
  72. /// Flag for smb_file_open. Request right for extended read (?)
  73. #define SMB_MOD_READ_EXT (1 << 3)
  74. /// Flag for smb_file_open. Request right for extended write (?)
  75. #define SMB_MOD_WRITE_EXT (1 << 4)
  76. /// Flag for smb_file_open. Request right for execution (?)
  77. #define SMB_MOD_EXEC (1 << 5)
  78. /// Flag for smb_file_open. Request right for child removal (?)
  79. #define SMB_MOD_RMCHILD (1 << 6)
  80. /// Flag for smb_file_open. Request right for reading file attributes
  81. #define SMB_MOD_READ_ATTR (1 << 7)
  82. /// Flag for smb_file_open. Request right for writing file attributes
  83. #define SMB_MOD_WRITE_ATTR (1 << 8)
  84. /// Flag for smb_file_open. Request right for removing file
  85. #define SMB_MOD_RM (1 << 16)
  86. /// Flag for smb_file_open. Request right for reading ACL
  87. #define SMB_MOD_READ_CTL (1 << 17)
  88. /// Flag for smb_file_open. Request right for writing ACL
  89. #define SMB_MOD_WRITE_DAC (1 << 18)
  90. /// Flag for smb_file_open. Request right for changing owner
  91. #define SMB_MOD_CHOWN (1 << 19)
  92. /// Flag for smb_file_open. (??)
  93. #define SMB_MOD_SYNC (1 << 20)
  94. /// Flag for smb_file_open. (??)
  95. #define SMB_MOD_SYS (1 << 24)
  96. /// Flag for smb_file_open. (??)
  97. #define SMB_MOD_MAX_ALLOWED (1 << 25)
  98. /// Flag for smb_file_open. Request all generic rights (??)
  99. #define SMB_MOD_GENERIC_ALL (1 << 28)
  100. /// Flag for smb_file_open. Request generic exec right (??)
  101. #define SMB_MOD_GENERIC_EXEC (1 << 29)
  102. /// Flag for smb_file_open. Request generic read right (??)
  103. #define SMB_MOD_GENERIC_READ (1 << 30)
  104. /// Flag for smb_file_open. Request generic write right (??)
  105. #define SMB_MOD_GENERIC_WRITE (1 << 31)
  106. /**
  107. * @brief Flag for smb_file_open. Default R/W mode
  108. * @details A few flags OR'ed
  109. */
  110. #define SMB_MOD_RW (SMB_MOD_READ | SMB_MOD_WRITE | SMB_MOD_APPEND \
  111. | SMB_MOD_READ_EXT | SMB_MOD_WRITE_EXT \
  112. | SMB_MOD_READ_ATTR | SMB_MOD_WRITE_ATTR \
  113. | SMB_MOD_READ_CTL )
  114. /**
  115. * @brief Flag for smb_file_open. Default R/O mode
  116. * @details A few flags OR'ed
  117. */
  118. #define SMB_MOD_RO (SMB_MOD_READ | SMB_MOD_READ_EXT \
  119. | SMB_MOD_READ_ATTR | SMB_MOD_READ_CTL )
  120. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/
  121. //!! PRIVATE stuff below !!/
  122. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/
  123. //-----------------------------------------------------------------------------/
  124. // Our own identity
  125. //-----------------------------------------------------------------------------/
  126. #define SMB_OS "Unix"
  127. #define SMB_LANMAN "liBDSM"
  128. //-----------------------------------------------------------------------------/
  129. // A few magic stuffs (SMB magic // our dialect support)
  130. //-----------------------------------------------------------------------------/
  131. #define SMB_MAGIC { 0xff, 0x53, 0x4d, 0x42 } // aka "\xffSMB"
  132. #define SMB_DIALECTS { \
  133. "\2Samba", \
  134. "\2NT LM 0.12", \
  135. NULL \
  136. }
  137. // Dialect values must match position on SMB_DIALECTS array
  138. #define SMB_DIALECT_SAMBA 0
  139. #define SMB_DIALECT_NTLM 1
  140. //-----------------------------------------------------------------------------/
  141. // SMB Operations/Commands
  142. //-----------------------------------------------------------------------------/
  143. #define SMB_CMD_CLOSE 0x04
  144. #define SMD_CMD_TRANS 0x25
  145. #define SMB_CMD_TRANS2 0x32
  146. #define SMB_CMD_TREE_DISCONNECT 0x71
  147. #define SMB_CMD_NEGOTIATE 0x72
  148. #define SMB_CMD_SETUP 0x73 // Session Setup AndX
  149. #define SMB_CMD_TREE_CONNECT 0x75 // Tree Connect AndX
  150. #define SMB_CMD_ECHO 0x2b
  151. #define SMB_CMD_READ 0x2e // Read AndX
  152. #define SMB_CMD_CREATE 0xa2 // NT Create AndX
  153. //-----------------------------------------------------------------------------/
  154. // SMB TRANS2 SubCommands
  155. //-----------------------------------------------------------------------------/
  156. #define SMB_TR2_FIND_FIRST 0x0001
  157. #define SMB_TR2_QUERY_PATH 0x0005
  158. //-----------------------------------------------------------------------------/
  159. // NTSTATUS Codes
  160. //-----------------------------------------------------------------------------/
  161. #define NT_STATUS_SUCCESS 0x00000000
  162. #define NT_STATUS_MORE_PROCESSING_REQUIRED 0xc0000016
  163. #define NT_STATUS_ACCESS_DENIED 0xc0000022
  164. ///////////////////////////////////////////////////////////////////////////////
  165. //// Flags definitions
  166. //// Many aren't use in libdsm but are here for possible later use
  167. // Protocol negotiation flags (flags field in spec)
  168. #define SMB_FLAG_RESPONSE (1 << 7)
  169. #define SMB_FLAG_NOTIFY (1 << 6)
  170. #define SMB_FLAG_OPLOCK (1 << 5)
  171. #define SMB_FLAG_CANONIC (1 << 4)
  172. #define SMB_FLAG_CASELESS (1 << 3)
  173. #define SMB_FLAG_BUFFER_POSTED (1 << 1)
  174. #define SMB_FLAG_LOCK_AND_READ (1 << 0)
  175. // More Protocol negotiation flags (flags2 field in spec)
  176. #define SMB_FLAG_UNICODE (1 << (15 + 8))
  177. #define SMB_FLAG_NT_ERRORS (1 << (14 + 8))
  178. #define SMB_FLAG_EXECUTE_ONLY (1 << (13 + 8))
  179. #define SMB_FLAG_DFS (1 << (12 + 8))
  180. #define SMB_FLAG_XSEC (1 << (11 + 8))
  181. #define SMB_FLAG_REPARSE_PATH (1 << (10 + 8))
  182. #define SMB_FLAG_LONG_NAMES (1 << (6 + 8))
  183. #define SMB_FLAG_SIGN_REQUIRED (1 << (4 + 8))
  184. #define SMB_FLAG_COMPRESSED (1 << (3 + 8))
  185. #define SMB_FLAG_SIGN_SUPPORT (1 << (2 + 8))
  186. #define SMB_FLAG_EXT_ATTR (1 << (1 + 8))
  187. #define SMB_FLAG_LONG_NAMES_OK (1 << (0 + 8))
  188. // Negotiated server capabilities
  189. #define SMB_CAPS_RAW (1 << 0)
  190. #define SMB_CAPS_MPX (1 << 1)
  191. #define SMB_CAPS_UNICODE (1 << 2)
  192. #define SMB_CAPS_LARGE (1 << 3)
  193. #define SMB_CAPS_NTSMB (1 << 4)
  194. #define SMB_CAPS_RPC (1 << 5)
  195. #define SMB_CAPS_NTFIND (1 << 9)
  196. #define SMB_CAPS_XSEC (1 << 31)
  197. // File creation/open flags
  198. #define SMB_CREATE_OPLOCK (1 << 1)
  199. #define SMB_CREATE_BATCH_OPLOCK (1 << 2)
  200. #define SMB_CREATE_MKDIR (1 << 3)
  201. #define SMB_CREATE_EXT_RESP (1 << 4)
  202. #define SMB_CREATE_DEFAULTS (0)
  203. // File attributes
  204. #define SMB_ATTR_RO (1 << 0)
  205. #define SMB_ATTR_HIDDEN (1 << 1)
  206. #define SMB_ATTR_SYS (1 << 2)
  207. #define SMB_ATTR_VOLID (1 << 3) // Volume ID
  208. #define SMB_ATTR_DIR (1 << 4)
  209. #define SMB_ATTR_ARCHIVE (1 << 5) // Modified since last archive (!?)
  210. #define SMB_ATTR_DEVICE (1 << 6)
  211. #define SMB_ATTR_NORMAL (1 << 7)
  212. #define SMB_ATTR_TEMP (1 << 8)
  213. #define SMB_ATTR_SPARSE (1 << 9)
  214. #define SMB_ATTR_REPARSE_PT (1 << 10)
  215. #define SMB_ATTR_COMPRESSED (1 << 11)
  216. #define SMB_ATTR_OFFLINE (1 << 12)
  217. #define SMB_ATTR_INDEXED (1 << 13) // Not set = May be indexed
  218. #define SMB_ATTR_ENCRYPTED (1 << 14)
  219. // Share access flags
  220. #define SMB_SHARE_READ (1 << 0)
  221. #define SMB_SHARE_WRITE (1 << 1)
  222. #define SMB_SHARE_DELETE (1 << 2)
  223. // Trans 2 flags
  224. //// Find First 2
  225. #define SMB_FIND2_ATTR_RO (1 << 0) // Include RO files in result
  226. #define SMB_FIND2_ATTR_HIDDEN (1 << 1) // Include hidden files
  227. #define SMB_FIND2_ATTR_SYSTEM (1 << 2) // Include system files
  228. #define SMB_FIND2_ATTR_VOLUME (1 << 3) // Include volume ID ?
  229. #define SMB_FIND2_ATTR_DIR (1 << 4) // Include directory ?
  230. #define SMB_FIND2_ATTR_ARCHIVE (1 << 5) // Include archive ?
  231. #define SMB_FIND2_ATTR_DEFAULT (SMB_FIND2_ATTR_RO | SMB_FIND2_ATTR_HIDDEN | \
  232. SMB_FIND2_ATTR_SYSTEM | SMB_FIND2_ATTR_DIR)
  233. #define SMB_FIND2_FLAG_CLOSE (1 << 0) // Close search after request ?
  234. #define SMB_FIND2_FLAG_CLOSE_EOS (1 << 1) // Close after End Of Search ?
  235. #define SMB_FIND2_FLAG_RESUME (1 << 2) // Send resume keys ?
  236. #define SMB_FIND2_FLAG_CONTINUE (1 << 3) // not set == new search
  237. #define SMB_FIND2_FLAG_BACKUP (1 << 3) // Backup intent ?
  238. #define SMB_FIND2_FLAG_DEFAULT (SMB_FIND2_FLAG_CLOSE_EOS | \
  239. SMB_FIND2_FLAG_RESUME)
  240. #endif