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