smb_types.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*****************************************************************************
  2. * __________________ _________ _____ _____ .__ ._.
  3. * \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. * | | \| ` \/ / Y \ / | | \ ___/ \|
  6. * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. * \/ \/ \/ \/ )/ \/ \/ \/
  8. *
  9. * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS
  10. *
  11. * Author: Julien 'Lta' BALLET <contact@lta.io>
  12. *
  13. * liBDSM is released under LGPLv2.1 (or later) and is also available
  14. * under a commercial license.
  15. *****************************************************************************
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU Lesser General Public License as published by
  18. * the Free Software Foundation; either version 2.1 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public License
  27. * along with this program; if not, write to the Free Software Foundation,
  28. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  29. *****************************************************************************/
  30. /**
  31. * @file smb_types.h
  32. * @brief liBDSM types and structures
  33. */
  34. #ifndef _SMB_TYPES_H_
  35. #define _SMB_TYPES_H_
  36. #include <netinet/ip.h>
  37. #include <stddef.h>
  38. #include <libtasn1.h>
  39. #include <stdbool.h>
  40. #include "bdsm/smb_types.h"
  41. #include "smb_buffer.h"
  42. #include "smb_packets.h"
  43. /**
  44. * @internal
  45. * @struct smb_file
  46. * @brief An opaque data structure to represent file
  47. */
  48. struct smb_file
  49. {
  50. smb_file *next; // Next file in this share
  51. char *name;
  52. smb_fid fid;
  53. smb_tid tid;
  54. size_t name_len;
  55. uint64_t created;
  56. uint64_t accessed;
  57. uint64_t written;
  58. uint64_t changed;
  59. uint64_t alloc_size;
  60. uint64_t size;
  61. uint32_t attr;
  62. uint64_t offset; // Current position pointer
  63. int is_dir; // 0 -> file, 1 -> directory
  64. };
  65. typedef struct smb_share smb_share;
  66. struct smb_share
  67. {
  68. smb_share *next; // Next share in this session
  69. smb_file *files; // List of all open files for this share
  70. smb_tid tid;
  71. uint16_t opts; // Optionnal support opts
  72. uint16_t rights; // Maximum rights field
  73. uint16_t guest_rights;
  74. };
  75. typedef struct smb_transport smb_transport;
  76. struct smb_transport
  77. {
  78. void *session;
  79. void *(*new)(size_t buf_size);
  80. int (*connect)(struct in_addr *addr, void *s, const char *name);
  81. void (*destroy)(void *s);
  82. void (*pkt_init)(void *s);
  83. int (*pkt_append)(void *s, void *data, size_t size);
  84. int (*send)(void *s);
  85. ssize_t (*recv)(void *s, void **data);
  86. };
  87. typedef struct smb_srv_info smb_srv_info;
  88. struct smb_srv_info
  89. {
  90. char name[16]; // The server name
  91. uint16_t dialect; // The selected dialect
  92. uint16_t security_mode; // Security mode
  93. uint16_t uid; // uid attributed by the server.
  94. uint32_t session_key; // The session key sent by the server on protocol negotiate
  95. uint32_t caps; // Server caps replyed during negotiate
  96. uint64_t challenge; // For challenge response security
  97. uint64_t ts; // It seems Win7 requires it :-/
  98. };
  99. /**
  100. * @brief An opaque data structure to represent a SMB Session.
  101. */
  102. struct smb_session
  103. {
  104. int state;
  105. bool guest; // Are we logged as guest ?
  106. // Informations about the smb server we are connected to.
  107. smb_srv_info srv;
  108. ASN1_TYPE spnego_asn1;
  109. smb_buffer xsec_target;
  110. smb_creds creds;
  111. smb_transport transport;
  112. smb_share *shares; // shares->files | Map fd <-> smb_file
  113. };
  114. typedef struct smb_message smb_message;
  115. struct smb_message
  116. {
  117. size_t payload_size; // Size of the allocated payload
  118. size_t cursor; // Write cursor in the payload
  119. smb_packet *packet; // Yummy yummy, Fruity fruity !
  120. };
  121. #endif