smb_session.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifndef __BDSM_SMB_SESSION_H_
  31. #define __BDSM_SMB_SESSION_H_
  32. #include "bdsm/smb_defs.h"
  33. #include "bdsm/smb_types.h"
  34. /**
  35. * @file smb_session.h
  36. * @brief Functions to connect and authenticate to an SMB server
  37. */
  38. /**
  39. * @brief Allocates a new Session object
  40. * @details To be able to perform actions on shares and file, you'll need to
  41. * call smb_session_connect, then authenticate with smb_authenticate.
  42. * @return A new Session object.
  43. */
  44. smb_session *smb_session_new();
  45. /**
  46. * @brief Close a session and deallocate its ressources
  47. * @details After destroying a session, all the smb_tid, smb_fid and smb_fd
  48. * associated with this session becomes invalid.
  49. *
  50. * @param s The session to destroy
  51. */
  52. void smb_session_destroy(smb_session *s);
  53. /**
  54. * @brief Set the credentials for this session.
  55. * @details Any of the params except s can be NULL.
  56. *
  57. * @param s The session object.
  58. * @param domain Domain to authenticate on. Often it's the same as netbios host.
  59. * @param login The user to login as.
  60. * @param password the user's password.
  61. */
  62. void smb_session_set_creds(smb_session *s, const char *domain,
  63. const char *login, const char *password);
  64. #define SMB_CREDS_MAXLEN 128
  65. /**
  66. * @brief Establish a connection and negotiate a session protocol with a remote
  67. * host
  68. * @details You have to provide both the ip and the name. This is a constraint
  69. * of Netbios, which requires you to know its name before he accepts to speak
  70. * with you.
  71. *
  72. * @param s A session object.
  73. * @param hostname The ASCII netbios name, the name type will be coerced to <20>
  74. * since libdsm is about reading files
  75. * @param ip The ip of the machine to connect to (in network byte order)
  76. * @param transport The type of transport used, it could be SMB_TRANSPORT_TCP
  77. * or SMB_TRANSPORT_NBT (Netbios over TCP, ie legacy)
  78. * @return 0 on success or a DSM error code in case of error
  79. */
  80. int smb_session_connect(smb_session *s, const char *hostname,
  81. uint32_t ip, int transport);
  82. /**
  83. * @brief Authenticate on the remote host with the provided credentials
  84. * @details Can be called if session state is SMB_STATE_DIALECT_OK.
  85. * If successfull, session state transition to SMB_STATE_SESSION_OK
  86. * Provides the credentials with smb_session_set_creds.
  87. *
  88. * @param s The session object.
  89. *
  90. * @return 0 on success or a DSM error code in case of error. Success doesn't
  91. * mean you are logged in with the user you requested. If guest are activated
  92. * on the remote host, when login fails, you are logged in as 'Guest'. Failure
  93. * might also indicate you didn't supplied all the credentials
  94. */
  95. int smb_session_login(smb_session *s);
  96. int smb_session_logoff(smb_session *s);
  97. /**
  98. * @brief Am i logged in as Guest ?
  99. *
  100. * @param s The session object
  101. * @return 1 -> Logged in as guest
  102. * 0 -> Logged in as regular user
  103. * -1 -> Error (not logged in, invalid session, etc.)
  104. */
  105. int smb_session_is_guest(smb_session *s);
  106. /**
  107. * @brief Returns the server name with the <XX> type
  108. *
  109. * @param s The session object
  110. * @return The server name or NULL. The memory is owned by the session object.
  111. */
  112. const char *smb_session_server_name(smb_session *s);
  113. /**
  114. * @brief Check if a feature is supported/has been negociated with the server
  115. *
  116. * @param s The session object
  117. * @param what Which features to check ? @see smb_session_supports_what
  118. *
  119. * @return 0 if the feature is not supported, something else otherwise
  120. */
  121. int smb_session_supports(smb_session *s, int what);
  122. /**
  123. * @brief Get the last NT_STATUS
  124. * @details Valid only if a smb_ function returned the DSM_ERROR_NT error.
  125. *
  126. * @param s The session object
  127. */
  128. uint32_t smb_session_get_nt_status(smb_session *s);
  129. #endif