smb_types.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 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. * @internal
  43. * @struct smb_file
  44. * @brief An opaque data structure to represent file
  45. */
  46. typedef struct smb_file_s
  47. {
  48. struct smb_file_s *next; // Next file in this share
  49. char *name;
  50. smb_fid fid;
  51. smb_tid tid;
  52. size_t name_len;
  53. uint64_t created;
  54. uint64_t accessed;
  55. uint64_t written;
  56. uint64_t changed;
  57. uint64_t alloc_size;
  58. uint64_t size;
  59. uint32_t attr;
  60. uint32_t readp; // Current read pointer (position);
  61. int is_dir; // 0 -> file, 1 -> directory
  62. } smb_file;
  63. typedef struct smb_share_s
  64. {
  65. struct smb_share_s *next; // Next share in this session
  66. struct smb_file_s *files; // List of all open files for this share
  67. smb_tid tid;
  68. uint16_t opts; // Optionnal support opts
  69. uint16_t rights; // Maximum rights field
  70. uint16_t guest_rights;
  71. } smb_share;
  72. /**
  73. * @brief An opaque data structure to represent a SMB Session.
  74. */
  75. typedef struct
  76. {
  77. int state;
  78. int guest; // boolean, are we logged as guest ?
  79. uint16_t uid; // uid attributed by the server
  80. netbios_session *nb_session;
  81. // Informations about the smb server we are connected to.
  82. struct {
  83. char name[16]; // The server name
  84. uint16_t dialect; // The selected dialect
  85. uint16_t security_mode; // Security mode
  86. uint32_t caps; // Server caps replyed during negotiate
  87. uint32_t session_key; // XXX Is this really usefull?
  88. uint64_t challenge; // For challenge response security
  89. uint64_t ts; // It seems Win7 requires it :-/
  90. } srv;
  91. struct smb_share_s *shares; // shares->files | Map fd <-> smb_file
  92. } smb_session;
  93. /**
  94. * @struct smb_share_list
  95. * @brief An opaque object representing the list of share of a SMB file server.
  96. */
  97. typedef char **smb_share_list;
  98. /**
  99. * @struct smb_stat_list
  100. * @brief An opaque structure containing a list of file status
  101. */
  102. typedef smb_file *smb_stat_list;
  103. /**
  104. * @struct smb_stat
  105. * @brief An opaque structure containing info about a file
  106. */
  107. typedef smb_file *smb_stat;
  108. /**
  109. * @internal
  110. * @struct smb_message
  111. * @brief A convenience structure used to build smb messages
  112. */
  113. typedef struct
  114. {
  115. size_t payload_size; // Size of the allocated payload
  116. size_t cursor; // Write cursor in the payload
  117. smb_packet *packet; // Yummy yummy, Fruity fruity !
  118. } smb_message;
  119. #endif