smb_types.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_types.h
  20. * @brief liBDSM types and structures
  21. */
  22. #ifndef __BDSM_SMB_TYPES_H_
  23. #define __BDSM_SMB_TYPES_H_
  24. /**
  25. * @struct smb_tid
  26. * @brief The id of a connection to a share within a session.
  27. */
  28. typedef uint16_t smb_tid;
  29. /**
  30. * @struct smb_fid
  31. * @brief The id of a file within a share within a session.
  32. */
  33. typedef uint16_t smb_fid;
  34. // Concatenation of the two above, representing a file inside of a session
  35. // First 4 bytes are the TreeID (smb_tid), last 4 are the File ID (FUID)
  36. // A map between smb_fd and smb_file_t is maintained inside each session
  37. /** @struct smb_fd
  38. * @brief SMB File descriptor, represents a file within a session.
  39. */
  40. typedef uint32_t smb_fd;
  41. /**
  42. * @struct smb_file_t
  43. * @brief An opaque data structure to represent file
  44. */
  45. typedef struct smb_file_s
  46. {
  47. struct smb_file_s *next; // Next file in this share
  48. char *name;
  49. smb_fid fid;
  50. smb_tid tid;
  51. size_t name_len;
  52. uint64_t created;
  53. uint64_t accessed;
  54. uint64_t written;
  55. uint64_t changed;
  56. uint64_t alloc_size;
  57. uint64_t size;
  58. uint32_t attr;
  59. uint32_t readp; // Current read pointer (position);
  60. int is_dir; // 0 -> file, 1 -> directory
  61. } smb_file_t;
  62. typedef struct smb_share_s
  63. {
  64. struct smb_share_s *next; // Next share in this session
  65. struct smb_file_s *files; // List of all open files for this share
  66. smb_tid tid;
  67. uint16_t opts; // Optionnal support opts
  68. uint16_t rights; // Maximum rights field
  69. uint16_t guest_rights;
  70. } smb_share_t;
  71. /**
  72. * @brief An opaque data structure to represent a SMB Session.
  73. */
  74. typedef struct
  75. {
  76. int state;
  77. int guest; // boolean, are we logged as guest ?
  78. uint16_t uid; // uid attributed by the server
  79. netbios_session_t *nb_session;
  80. // Informations about the smb server we are connected to.
  81. struct {
  82. char name[16]; // The server name
  83. uint16_t dialect; // The selected dialect
  84. uint16_t security_mode; // Security mode
  85. uint32_t caps; // Server caps replyed during negotiate
  86. uint32_t session_key; // XXX Is this really usefull?
  87. uint64_t challenge; // For challenge response security
  88. uint64_t ts; // It seems Win7 requires it :-/
  89. } srv;
  90. struct smb_share_s *shares; // shares->files | Map fd <-> smb_file_t
  91. } smb_session_t;
  92. /**
  93. * @struct smb_share_list_t
  94. * @brief An opaque object representing the list of share of a SMB file server.
  95. */
  96. typedef char **smb_share_list_t;
  97. /**
  98. * @struct smb_stat_list_t
  99. * @brief An opaque structure containing a list of file status
  100. */
  101. typedef smb_file_t *smb_stat_list_t;
  102. /**
  103. * @struct smb_stat_t
  104. * @brief An opaque structure containing info about a file
  105. */
  106. typedef smb_file_t *smb_stat_t;
  107. /**
  108. * @internal
  109. * @struct smb_message_t
  110. * @brief A convenience structure used to build smb messages
  111. */
  112. typedef struct
  113. {
  114. size_t payload_size; // Size of the allocated payload
  115. size_t cursor; // Write cursor in the payload
  116. smb_packet_t *packet; // Yummy yummy, Fruity fruity !
  117. } smb_message_t;
  118. #endif