Smb4K – Samba (SMB) share advanced browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

307 lines
9.6KB

  1. /***************************************************************************
  2. smb4kpasswordhandler - This class handles the passwords for Smb4K.
  3. -------------------
  4. begin : So Jan 16 2005
  5. copyright : (C) 2005-2007 by Alexander Reinholdt
  6. email : dustpuppy@users.berlios.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. * This program is distributed in the hope that it will be useful, but *
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  17. * General Public License for more details. *
  18. * *
  19. * You should have received a copy of the GNU General Public License *
  20. * along with this program; if not, write to the *
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
  22. * MA 02110-1301 USA *
  23. ***************************************************************************/
  24. #ifndef SMB4KPASSWORDHANDLER_H
  25. #define SMB4KPASSWORDHANDLER_H
  26. #ifdef HAVE_CONFIG_H
  27. #include <config.h>
  28. #endif
  29. // TQt includes
  30. #include <tqobject.h>
  31. #include <tqcheckbox.h>
  32. // KDE includes
  33. #include <tdewallet.h>
  34. #include <kdialogbase.h>
  35. #include <kprocess.h>
  36. // forward declarations
  37. #ifndef __FreeBSD__
  38. class Smb4KAuthInfo;
  39. #endif
  40. // application specific includes
  41. #include "smb4khomesshareshandler.h"
  42. #ifdef __FreeBSD__
  43. #include "smb4ksambaoptionshandler.h"
  44. #include "smb4kauthinfo.h"
  45. #endif
  46. /**
  47. * This class handles the passwords used by Smb4K to authenticate to
  48. * the network shares.
  49. *
  50. * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
  51. */
  52. class Smb4KPasswordHandler : public TQObject
  53. {
  54. Q_OBJECT
  55. public:
  56. #ifndef __FreeBSD__
  57. /**
  58. * The constructor.
  59. *
  60. * @param config The TDEConfig object that should be used
  61. *
  62. * @param handler The Smb4KHomesSharesHandler object that is needed to retrieve
  63. * infos in case we need to look up authentication information for
  64. * 'homes' shares.
  65. *
  66. * @param parent The parent object.
  67. *
  68. * @param name The name this class should carry.
  69. */
  70. Smb4KPasswordHandler( Smb4KHomesSharesHandler *handler,
  71. TQObject *parent = 0,
  72. const char *name = 0 );
  73. #else
  74. /**
  75. * The constructor (FreeBSD).
  76. *
  77. * @param s_handler The Smb4KHomesSharesHandler object that is needed to retrieve
  78. * infos in case we need to look up authentication information for
  79. * 'homes' shares.
  80. *
  81. * @param o_handler The Smb4KSambaOptionsHandler object. It is needed to write the
  82. * ~/.nsmbrc file correctly.
  83. *
  84. * @param parent The parent object.
  85. *
  86. * @param name The name this class should carry.
  87. */
  88. Smb4KPasswordHandler( Smb4KHomesSharesHandler *s_handler,
  89. Smb4KSambaOptionsHandler *o_handler,
  90. TQObject *parent = 0,
  91. const char *name = 0 );
  92. #endif
  93. /**
  94. * The destructor.
  95. */
  96. ~Smb4KPasswordHandler();
  97. /**
  98. * Opens the askpass dialog.
  99. *
  100. * @param workgroup The workgroup where the share is located in (may be empty).
  101. *
  102. * @param host The host the share belongs to.
  103. *
  104. * @param name The name of the share.
  105. *
  106. * @param desc Determines which descriptive label the askpass dialog should carry.
  107. * Values are taken from the Smb4KPasswordHandler::AskPass::Description
  108. * enumeration.
  109. *
  110. * @param parent The parent of this dialog.
  111. *
  112. * @param name The name of this dialog.
  113. *
  114. * @returns TRUE if a new password has been supplied and FALSE otherwise.
  115. */
  116. bool askpass( const TQString &workgroup, const TQString &host, const TQString &share, int desc, TQWidget *parent = 0, const char *name = 0 );
  117. /**
  118. * Returns the authentication data that was found for the defined share. You need to
  119. * provide the workgroup, host name, and share name with @p authInfo.
  120. *
  121. * @param authInfo The authentication information object.
  122. *
  123. * @returns a pointer to @p authInfo. This may be NULL if @p authInfo was
  124. * also NULL.
  125. */
  126. Smb4KAuthInfo *readAuth( Smb4KAuthInfo *authInfo );
  127. /**
  128. * Write the provided authentication data to the wallet.
  129. *
  130. * @param authInfo The Smb4KAuthInfo object that holds the authentication information.
  131. */
  132. void writeAuth( Smb4KAuthInfo *authInfo );
  133. /**
  134. * Read the default authentication from the wallet.
  135. *
  136. * @param authInfo The authentication information object.
  137. *
  138. * @returns pointer to the authentication data object if a wallet is used or NULL otherwise
  139. */
  140. Smb4KAuthInfo *readDefaultAuth( Smb4KAuthInfo *authInfo );
  141. /**
  142. * Writes the default authentication data to the wallet. This function seems only to
  143. * be useful for the configuration dialog.
  144. *
  145. * @param authInfo The authentication data for the default login if a wallet is
  146. * used or NULL otherwise.
  147. */
  148. void writeDefaultAuth( Smb4KAuthInfo *authInfo );
  149. /**
  150. * This enumeration destermines which destriptive label the askpass
  151. * dialog should carry.
  152. */
  153. enum Description{ NewData, AccessDenied, BadPassword, PermDenied, AuthError, LogonFailure, None };
  154. /**
  155. * This function returns TRUE if the wallet it open at the moment and FALSE
  156. * if it is closed or not used.
  157. *
  158. * @returns TRUE if the wallet is open.
  159. */
  160. bool walletIsOpen() { return (m_wallet && m_wallet->isOpen()); }
  161. /**
  162. * This function returns TRUE if the digital wallet support has been
  163. * disabled. This happens when the wallet could not be opened.
  164. *
  165. * @returns TRUE if the digital wallet support has been disabled.
  166. */
  167. bool walletSupportIsDisabled() { return m_wallet_support_disabled; }
  168. protected slots:
  169. /**
  170. * Get the password for a specific share and user name.
  171. */
  172. void slotGetPassword( const TQString &username );
  173. /**
  174. * This slot is used to enable the OK button of the askpass
  175. * dialog when text has been entered in the text boxes and/or the
  176. * combo box.
  177. *
  178. * @param text The text that has been entered.
  179. */
  180. void slotEnableOKButton( const TQString &text );
  181. /**
  182. * FreeBSD specific: This slot receives output from the process that encrypts
  183. * the passwords.
  184. *
  185. * @param proc The process that sends the output
  186. *
  187. * @param buffer The buffer that contains the output
  188. *
  189. * @param buflen The length of the buffer
  190. */
  191. void slotReceivePassword( TDEProcess *proc, char *buffer, int buflen );
  192. /**
  193. * FreeBSD specific: This slot is invoked if the process exited.
  194. *
  195. * @param proc The process that exited
  196. */
  197. void slotWritePassword( TDEProcess *proc );
  198. private:
  199. /**
  200. * This function opens the wallet in which the passwords should be
  201. * stored.
  202. */
  203. void open_close_wallet();
  204. /**
  205. * This function is used to convert old wallet entries to the new
  206. * map based ones.
  207. */
  208. void convert_old_entries();
  209. /**
  210. * The TDEWallet object.
  211. */
  212. TDEWallet::Wallet *m_wallet;
  213. /**
  214. * The Smb4KAuthInfo object. For use with the askpass dialog.
  215. */
  216. Smb4KAuthInfo *m_auth;
  217. /**
  218. * The askpass dialog.
  219. */
  220. KDialogBase *m_dlg;
  221. /**
  222. * This list holds the authentication data the user supplied if he/she
  223. * does not want to use TDEWallet.
  224. */
  225. TQValueList<Smb4KAuthInfo *> m_auth_list;
  226. /**
  227. * If the user neither wants to store the passwords in a wallet nor in a
  228. * temporary list, the authentication data received from the askpass dialog
  229. * will the stored in this object.
  230. */
  231. Smb4KAuthInfo *m_temp_auth;
  232. /**
  233. * The Smb4KHomesSharesHandler object
  234. */
  235. Smb4KHomesSharesHandler *m_handler;
  236. /**
  237. * Is the wallet support disabled?
  238. */
  239. bool m_wallet_support_disabled;
  240. #ifdef __FreeBSD__
  241. /**
  242. * FreeBSD specific: This function writes authentication information
  243. * to the ~/.nsmbrc file, which is used by mount_smbfs.
  244. *
  245. * @param authInfo The authentication information that should be written
  246. * to ~/.nsmbrc file.
  247. */
  248. void writeToSMBConfFile( Smb4KAuthInfo *authInfo );
  249. /**
  250. * FreeBSD specific: Holds the authentication information that should
  251. * be written to ~/.nsmbrc.
  252. */
  253. Smb4KAuthInfo m_nsmbrc_auth;
  254. /**
  255. * The buffer for the process that encrypts the password.
  256. */
  257. TQString m_buffer;
  258. /**
  259. * The Smb4KSambaOptionsHandler object.
  260. */
  261. Smb4KSambaOptionsHandler *m_options_handler;
  262. #endif
  263. };
  264. #endif