smb_defs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // This file is part of libdsm
  2. // Author: Julien 'Lta' BALLET <contact@lta.io>
  3. // Copyright VideoLabs 2014
  4. // License: MIT License
  5. #ifndef __BSDM_SMB_DEFS_H_
  6. #define __BSDM_SMB_DEFS_H_
  7. #include <stdint.h>
  8. #define SMB_MAGIC { 0xff, 0x53, 0x4d, 0x42 } // aka "\xffSMB"
  9. #define SMB_DIALECTS { \
  10. "\2Samba", \
  11. "\2NT LM 0.12", \
  12. NULL \
  13. }
  14. // Dialect values must match position on SMB_DIALECTS array
  15. #define SMB_DIALECT_SAMBA 0
  16. #define SMB_DIALECT_NTLM 1
  17. #define SMB_CMD_CLOSE 0x04
  18. #define SMB_CMD_TRANS2 0x32
  19. #define SMD_CMD_TREE_DISCONNECT 0x71
  20. #define SMB_CMD_NEGOTIATE 0x72
  21. #define SMB_CMD_SETUP 0x73 // Session Setup AndX
  22. #define SMB_CMD_TREE_CONNECT 0x75 // Tree Connect AndX
  23. #define SMB_CMD_ECHO 0x2b
  24. #define SMB_CMD_READ 0x2e // Read AndX
  25. #define SMB_CMD_CREATE 0xa2 // NT Create AndX
  26. #define SMB_SET_FLAG 0
  27. #define SMB_SET_FLAG2 0
  28. #define SMB_FLAG_RESPONSE (1 << 7)
  29. #define SMB_FLAG_NOTIFY (1 << 6)
  30. #define SMB_FLAG_OPLOCK (1 << 5)
  31. #define SMB_FLAG_CANONIC (1 << 4)
  32. #define SMB_FLAG_CASELESS (1 << 3)
  33. #define SMB_FLAG_BUFFER_POSTED (1 << 1)
  34. #define SMB_FLAG_LOCK_AND_READ (1 << 0)
  35. #define SMB_FLAG_UNICODE (1 << (15 + 8))
  36. #define SMB_FLAG_NT_ERRORS (1 << (14 + 8))
  37. #define SMB_FLAG_EXECUTE_ONLY (1 << (13 + 8))
  38. #define SMB_FLAG_DFS (1 << (12 + 8))
  39. #define SMB_FLAG_EXT_SEC (1 << (11 + 8))
  40. #define SMB_FLAG_REPARSE_PATH (1 << (10 + 8))
  41. #define SMB_FLAG_LONG_NAMES (1 << (6 + 8))
  42. #define SMB_FLAG_SIGN_REQUIRED (1 << (4 + 8))
  43. #define SMB_FLAG_COMPRESSED (1 << (3 + 8))
  44. #define SMB_FLAG_SIGN_SUPPORT (1 << (2 + 8))
  45. #define SMB_FLAG_EXT_ATTR (1 << (1 + 8))
  46. #define SMB_FLAG_LONG_NAMES_OK (1 << (0 + 8))
  47. #define NT_STATUS_SUCCESS 0x00000000
  48. #define NT_STATUS_MORE_PROCESSING_REQUIRED 0xc0000016
  49. typedef struct
  50. {
  51. uint8_t wct; // zero
  52. uint16_t bct;
  53. char dialects[];
  54. } __attribute__((packed)) smb_negotiate_req_t;
  55. typedef struct
  56. {
  57. uint8_t wct; // +-17 :)
  58. uint8_t payload[];
  59. } __attribute__((packed)) smb_negotiate_resp_t;
  60. typedef struct
  61. {
  62. uint8_t wct; // +-12 :)
  63. uint8_t andx; // 0xff when no other command (recommended :)
  64. uint8_t reserved; // 0x00
  65. uint16_t andx_offset; // 0x00 when no other command
  66. uint16_t max_buffer; // Maximum size we can receive
  67. uint16_t mpx_count; // maximum multiplexed session
  68. uint16_t vc_count; // Virtual ciruits -> 1!
  69. uint32_t session_key; // 0x00000000
  70. uint16_t blob_length; // Length of Security Blob
  71. uint32_t reserved2; // 0x00000000
  72. uint32_t caps; // Capabilities
  73. uint16_t payload_size;
  74. uint8_t payload[];
  75. } __attribute__((packed)) smb_session_req_t;
  76. typedef struct
  77. {
  78. } __attribute__((packed)) smb_session_resp_t;
  79. typedef struct
  80. {
  81. uint8_t magic[4]; // { 0xff, 0x53, 0x4d, 0x42 } "\xffSMB"
  82. uint8_t command; // The actual SMB command
  83. uint32_t status; // 'NT Status'
  84. uint8_t flags; // Packet flags
  85. uint16_t flags2; // More flags ? (lol)
  86. uint16_t pid_high; // Unused ?
  87. uint64_t signature; // Unused ?
  88. uint16_t reserved; // More usuned bit (we have so much BW :)
  89. uint16_t tree_id; // SMB's file descriptor or service id ?
  90. uint16_t pid; // Process ID.
  91. uint16_t uid; // User ID.
  92. uint16_t mux_id; // Multiplex ID. Increment it sometimes.
  93. } __attribute__((packed)) smb_header_t;
  94. typedef struct
  95. {
  96. smb_header_t header; // A packet header full of gorgeous goodness.
  97. uint8_t payload[]; // Ze yummy data inside. Eat 5 fruits/day !
  98. } __attribute__((packed)) smb_packet_t;
  99. #endif