smb_types.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #include <netinet/ip.h>
  25. #include <stddef.h>
  26. #include <libtasn1.h>
  27. #include <stdbool.h>
  28. #include "bdsm/smb_buffer.h"
  29. #include "bdsm/smb_packets.h"
  30. /**
  31. * @struct smb_tid
  32. * @brief The id of a connection to a share within a session.
  33. */
  34. typedef uint16_t smb_tid;
  35. /**
  36. * @struct smb_fid
  37. * @brief The id of a file within a share within a session.
  38. */
  39. typedef uint16_t smb_fid;
  40. // Concatenation of the two above, representing a file inside of a session
  41. // First 4 bytes are the TreeID (smb_tid), last 4 are the File ID (FUID)
  42. // A map between smb_fd and smb_file is maintained inside each session
  43. /** @struct smb_fd
  44. * @brief SMB File descriptor, represents a file within a session.
  45. */
  46. typedef uint32_t smb_fd;
  47. /**
  48. * @internal
  49. * @struct smb_file
  50. * @brief An opaque data structure to represent file
  51. */
  52. typedef struct smb_file_s
  53. {
  54. struct smb_file_s *next; // Next file in this share
  55. char *name;
  56. smb_fid fid;
  57. smb_tid tid;
  58. size_t name_len;
  59. uint64_t created;
  60. uint64_t accessed;
  61. uint64_t written;
  62. uint64_t changed;
  63. uint64_t alloc_size;
  64. uint64_t size;
  65. uint32_t attr;
  66. uint32_t readp; // Current read pointer (position);
  67. int is_dir; // 0 -> file, 1 -> directory
  68. } smb_file;
  69. typedef struct smb_share_s
  70. {
  71. struct smb_share_s *next; // Next share in this session
  72. struct smb_file_s *files; // List of all open files for this share
  73. smb_tid tid;
  74. uint16_t opts; // Optionnal support opts
  75. uint16_t rights; // Maximum rights field
  76. uint16_t guest_rights;
  77. } smb_share;
  78. typedef struct smb_transport_s
  79. {
  80. void *session;
  81. void *(*new)(size_t buf_size);
  82. int (*connect)(struct in_addr *addr, void *s, const char *name);
  83. void (*destroy)(void *s);
  84. void (*pkt_init)(void *s);
  85. int (*pkt_append)(void *s, void *data, size_t size);
  86. int (*send)(void *s);
  87. ssize_t (*recv)(void *s, void **data);
  88. } smb_transport;
  89. // An structure to store user credentials;
  90. // login:password@domain (also DOMAIN\login)
  91. typedef struct
  92. {
  93. char *domain;
  94. char *login;
  95. char *password;
  96. } smb_creds;
  97. typedef struct
  98. {
  99. char name[16]; // The server name
  100. uint16_t dialect; // The selected dialect
  101. uint16_t security_mode; // Security mode
  102. uint16_t uid; // uid attributed by the server.
  103. uint32_t session_key; // The session key sent by the server on protocol negotiate
  104. uint32_t caps; // Server caps replyed during negotiate
  105. uint64_t challenge; // For challenge response security
  106. uint64_t ts; // It seems Win7 requires it :-/
  107. } smb_srv_info;
  108. /**
  109. * @brief An opaque data structure to represent a SMB Session.
  110. */
  111. typedef struct
  112. {
  113. int state;
  114. bool guest; // Are we logged as guest ?
  115. // Informations about the smb server we are connected to.
  116. smb_srv_info srv;
  117. ASN1_TYPE spnego_asn1;
  118. smb_buffer xsec_target;
  119. smb_creds creds;
  120. smb_transport transport;
  121. struct smb_share_s *shares; // shares->files | Map fd <-> smb_file
  122. } smb_session;
  123. /**
  124. * @struct smb_share_list
  125. * @brief An opaque object representing the list of share of a SMB file server.
  126. */
  127. typedef char **smb_share_list;
  128. /**
  129. * @struct smb_stat_list
  130. * @brief An opaque structure containing a list of file status
  131. */
  132. typedef smb_file *smb_stat_list;
  133. /**
  134. * @struct smb_stat
  135. * @brief An opaque structure containing info about a file
  136. */
  137. typedef smb_file *smb_stat;
  138. /**
  139. * @internal
  140. * @struct smb_message
  141. * @brief A convenience structure used to build smb messages
  142. */
  143. typedef struct
  144. {
  145. size_t payload_size; // Size of the allocated payload
  146. size_t cursor; // Write cursor in the payload
  147. smb_packet *packet; // Yummy yummy, Fruity fruity !
  148. } smb_message;
  149. #endif