smb_defs.h 11 KB

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