From 472156a41b1348c714986c772759ad950fffbe75 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 27 Jan 2013 15:11:21 -0600 Subject: Rename kioslaves --- tdeioslave/smb/CMakeLists.txt | 8 +- tdeioslave/smb/Makefile.am | 24 +- tdeioslave/smb/kio_smb.cpp | 77 ------ tdeioslave/smb/kio_smb.h | 301 --------------------- tdeioslave/smb/kio_smb_auth.cpp | 207 --------------- tdeioslave/smb/kio_smb_browse.cpp | 476 ---------------------------------- tdeioslave/smb/kio_smb_config.cpp | 66 ----- tdeioslave/smb/kio_smb_dir.cpp | 345 ------------------------ tdeioslave/smb/kio_smb_file.cpp | 279 -------------------- tdeioslave/smb/kio_smb_internal.cpp | 135 ---------- tdeioslave/smb/kio_smb_internal.h | 118 --------- tdeioslave/smb/kio_smb_mount.cpp | 211 --------------- tdeioslave/smb/smb.protocol | 2 +- tdeioslave/smb/tdeio_smb.cpp | 77 ++++++ tdeioslave/smb/tdeio_smb.h | 301 +++++++++++++++++++++ tdeioslave/smb/tdeio_smb_auth.cpp | 207 +++++++++++++++ tdeioslave/smb/tdeio_smb_browse.cpp | 476 ++++++++++++++++++++++++++++++++++ tdeioslave/smb/tdeio_smb_config.cpp | 66 +++++ tdeioslave/smb/tdeio_smb_dir.cpp | 345 ++++++++++++++++++++++++ tdeioslave/smb/tdeio_smb_file.cpp | 279 ++++++++++++++++++++ tdeioslave/smb/tdeio_smb_internal.cpp | 135 ++++++++++ tdeioslave/smb/tdeio_smb_internal.h | 118 +++++++++ tdeioslave/smb/tdeio_smb_mount.cpp | 211 +++++++++++++++ 23 files changed, 2232 insertions(+), 2232 deletions(-) delete mode 100644 tdeioslave/smb/kio_smb.cpp delete mode 100644 tdeioslave/smb/kio_smb.h delete mode 100644 tdeioslave/smb/kio_smb_auth.cpp delete mode 100644 tdeioslave/smb/kio_smb_browse.cpp delete mode 100644 tdeioslave/smb/kio_smb_config.cpp delete mode 100644 tdeioslave/smb/kio_smb_dir.cpp delete mode 100644 tdeioslave/smb/kio_smb_file.cpp delete mode 100644 tdeioslave/smb/kio_smb_internal.cpp delete mode 100644 tdeioslave/smb/kio_smb_internal.h delete mode 100644 tdeioslave/smb/kio_smb_mount.cpp create mode 100644 tdeioslave/smb/tdeio_smb.cpp create mode 100644 tdeioslave/smb/tdeio_smb.h create mode 100644 tdeioslave/smb/tdeio_smb_auth.cpp create mode 100644 tdeioslave/smb/tdeio_smb_browse.cpp create mode 100644 tdeioslave/smb/tdeio_smb_config.cpp create mode 100644 tdeioslave/smb/tdeio_smb_dir.cpp create mode 100644 tdeioslave/smb/tdeio_smb_file.cpp create mode 100644 tdeioslave/smb/tdeio_smb_internal.cpp create mode 100644 tdeioslave/smb/tdeio_smb_internal.h create mode 100644 tdeioslave/smb/tdeio_smb_mount.cpp (limited to 'tdeioslave/smb') diff --git a/tdeioslave/smb/CMakeLists.txt b/tdeioslave/smb/CMakeLists.txt index 2493c2a85..23cc1f000 100644 --- a/tdeioslave/smb/CMakeLists.txt +++ b/tdeioslave/smb/CMakeLists.txt @@ -32,12 +32,12 @@ install( FILES smb-network.desktop DESTINATION ${DATA_INSTALL_DIR}/remoteview ) install( FILES x-smb-workgroup.desktop x-smb-server.desktop DESTINATION ${MIME_INSTALL_DIR}/application ) -##### kio_smb (module) ########################## +##### tdeio_smb (module) ########################## -tde_add_kpart( kio_smb AUTOMOC +tde_add_kpart( tdeio_smb AUTOMOC SOURCES - kio_smb.cpp kio_smb_auth.cpp kio_smb_browse.cpp kio_smb_config.cpp - kio_smb_dir.cpp kio_smb_file.cpp kio_smb_internal.cpp kio_smb_mount.cpp + tdeio_smb.cpp tdeio_smb_auth.cpp tdeio_smb_browse.cpp tdeio_smb_config.cpp + tdeio_smb_dir.cpp tdeio_smb_file.cpp tdeio_smb_internal.cpp tdeio_smb_mount.cpp LINK tdeio-shared ${SMBCLIENT_LIBRARIES} DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/tdeioslave/smb/Makefile.am b/tdeioslave/smb/Makefile.am index 97a4034da..ed3ef6d46 100644 --- a/tdeioslave/smb/Makefile.am +++ b/tdeioslave/smb/Makefile.am @@ -2,21 +2,21 @@ INCLUDES=$(all_includes) -kde_module_LTLIBRARIES = kio_smb.la -kio_smb_la_SOURCES = kio_smb.cpp \ - kio_smb_auth.cpp \ - kio_smb_browse.cpp \ - kio_smb_config.cpp \ - kio_smb_dir.cpp \ - kio_smb_file.cpp \ - kio_smb_internal.cpp \ - kio_smb_mount.cpp +kde_module_LTLIBRARIES = tdeio_smb.la +tdeio_smb_la_SOURCES = tdeio_smb.cpp \ + tdeio_smb_auth.cpp \ + tdeio_smb_browse.cpp \ + tdeio_smb_config.cpp \ + tdeio_smb_dir.cpp \ + tdeio_smb_file.cpp \ + tdeio_smb_internal.cpp \ + tdeio_smb_mount.cpp -kio_smb_la_LIBADD = -lkio -lsmbclient $(SMBCLIENT_EXTRA_LIBS) +tdeio_smb_la_LIBADD = -ltdeio -lsmbclient $(SMBCLIENT_EXTRA_LIBS) -kio_smb_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdeio_smb_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -noinst_HEADERS = kio_smb.h kio_smb_internal.h +noinst_HEADERS = tdeio_smb.h tdeio_smb_internal.h kdelnk_DATA = smb.protocol diff --git a/tdeioslave/smb/kio_smb.cpp b/tdeioslave/smb/kio_smb.cpp deleted file mode 100644 index 193df965f..000000000 --- a/tdeioslave/smb/kio_smb.cpp +++ /dev/null @@ -1,77 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: Top level implementation file for kio_smb.cpp -// -// Abstract: member function implementations for SMBSlave -// -// Author(s): Matthew Peterson -// -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - -#include "kio_smb.h" -#include "kio_smb_internal.h" - -//=========================================================================== -SMBSlave::SMBSlave(const TQCString& pool, const TQCString& app) - : SlaveBase( "smb", pool, app ) -{ - m_initialized_smbc = false; - - //read in the default workgroup info... - reparseConfiguration(); - - //initialize the library... - auth_initialize_smbc(); -} - - -//=========================================================================== -SMBSlave::~SMBSlave() -{ -} - - -//=========================================================================== -// pointer to the slave created in kdemain -SMBSlave* G_TheSlave; - -//=========================================================================== -int KDE_EXPORT kdemain( int argc, char **argv ) -{ - - TDEInstance instance( "kio_smb" ); - if( argc != 4 ) - { - kdDebug(KIO_SMB) << "Usage: kio_smb protocol domain-socket1 domain-socket2" - << endl; - return -1; - } - - SMBSlave slave( argv[2], argv[3] ); - - G_TheSlave = &slave; - slave.dispatchLoop(); - - return 0; -} - diff --git a/tdeioslave/smb/kio_smb.h b/tdeioslave/smb/kio_smb.h deleted file mode 100644 index 34ad0200a..000000000 --- a/tdeioslave/smb/kio_smb.h +++ /dev/null @@ -1,301 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: kio_smb.h -// -// Abstract: The main kio slave class declaration. For convenience, -// in concurrent devlopment, the implementation for this class -// is separated into several .cpp files -- the file containing -// the implementation should be noted in the comments for each -// member function. -// -// Author(s): Matthew Peterson -// -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - - -#ifndef KIO_SMB_H_INCLUDED -#define KIO_SMB_H_INCLUDED - -//------------- -// QT includes -//------------- -#include -#include -#include -#include -#include - -//-------------- -// KDE includes -//-------------- -#include -#include -#include -#include -#include -#include - -//----------------------------- -// Standard C library includes -//----------------------------- -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//------------------------------- -// Samba client library includes -//------------------------------- -extern "C" -{ -#include -} - -//--------------------------- -// kio_smb internal includes -//--------------------------- -#include "kio_smb_internal.h" - -#define MAX_XFER_BUF_SIZE 16348 -#define KIO_SMB 7106 - -using namespace TDEIO; -class TDEProcess; - -//=========================================================================== - - -class SMBSlave : public TQObject, public TDEIO::SlaveBase -{ - Q_OBJECT - -private: - //--------------------------------------------------------------------- - // please make sure your private data does not duplicate existing data - //--------------------------------------------------------------------- - bool m_initialized_smbc; - - /** - * From Controlcenter - */ - TQString m_default_user; -// TQString m_default_workgroup; //currently unused, Alex - TQString m_default_password; - TQString m_default_encoding; - - /** - * we store the current url, it's needed for - * callback authorisation method - */ - SMBUrl m_current_url; - - /** - * From Controlcenter, show SHARE$ or not - */ -// bool m_showHiddenShares; //currently unused, Alex - - /** - * libsmbclient need global variables to store in, - * else it crashes on exit next method after use cache_stat, - * looks like gcc (C/C++) failure - */ - struct stat st; -protected: - //--------------------------------------------- - // Authentication functions (kio_smb_auth.cpp) - //--------------------------------------------- - // (please prefix functions with auth) - - - /** - * Description : Initilizes the libsmbclient - * Return : true on success false with errno set on error - */ - bool auth_initialize_smbc(); - - bool checkPassword(SMBUrl &url); - - - //--------------------------------------------- - // Cache functions (kio_smb_auth.cpp) - //--------------------------------------------- - - //Stat methods - - //----------------------------------------- - // Browsing functions (kio_smb_browse.cpp) - //----------------------------------------- - // (please prefix functions with browse) - - /** - * Description : Return a stat of given SMBUrl. Calls cache_stat and - * pack it in UDSEntry. UDSEntry will not be cleared - * Parameter : SMBUrl the url to stat - * ignore_errors do not call error(), but warning() - * Return : false if any error occoured (errno), else true - */ - bool browse_stat_path(const SMBUrl& url, UDSEntry& udsentry, bool ignore_errors); - - /** - * Description : call smbc_stat and return stats of the url - * Parameter : SMBUrl the url to stat - * Return : stat* of the url - * Note : it has some problems with stat in method, looks like - * something leave(or removed) on the stack. If your - * method segfault on returning try to change the stat* - * variable - */ - int cache_stat( const SMBUrl& url, struct stat* st ); - - //--------------------------------------------- - // Configuration functions (kio_smb_config.cpp) - //--------------------------------------------- - // (please prefix functions with config) - - - //--------------------------------------- - // Directory functions (kio_smb_dir.cpp) - //--------------------------------------- - // (please prefix functions with dir) - - - //-------------------------------------- - // File IO functions (kio_smb_file.cpp) - //-------------------------------------- - // (please prefix functions with file) - - //---------------------------- - // Misc functions (this file) - //---------------------------- - - - /** - * Description : correct a given URL - * valid URL's are - * - * smb://[[domain;]user[:password]@]server[:port][/share[/path[/file]]] - * smb:/[[domain;]user[:password]@][group/[server[/share[/path[/file]]]]] - * domain = workgroup(domain) of the user - * user = username - * password = password of useraccount - * group = workgroup(domain) of server - * server = host to connect - * share = a share of the server (host) - * path = a path of the share - * Parameter : KURL the url to check - * Return : new KURL if its corrected. else the same KURL - */ - KURL checkURL(const KURL& kurl) const; - - void reportError(const SMBUrl &kurl); - -public: - - //----------------------------------------------------------------------- - // smbclient authentication callback (note that this is called by the - // global ::auth_smbc_get_data() call. - void auth_smbc_get_data(const char *server,const char *share, - char *workgroup, int wgmaxlen, - char *username, int unmaxlen, - char *password, int pwmaxlen); - - - //----------------------------------------------------------------------- - // Overwritten functions from the base class that define the operation of - // this slave. (See the base class headerfile slavebase.h for more - // details) - //----------------------------------------------------------------------- - - // Functions overwritten in kio_smb.cpp - SMBSlave(const TQCString& pool, const TQCString& app); - virtual ~SMBSlave(); - - // Functions overwritten in kio_smb_browse.cpp - virtual void listDir( const KURL& url ); - virtual void stat( const KURL& url ); - - // Functions overwritten in kio_smb_config.cpp - virtual void reparseConfiguration(); - - // Functions overwritten in kio_smb_dir.cpp - virtual void copy( const KURL& src, const KURL &dest, int permissions, bool overwrite ); - virtual void del( const KURL& kurl, bool isfile); - virtual void mkdir( const KURL& kurl, int permissions ); - virtual void rename( const KURL& src, const KURL& dest, bool overwrite ); - - // Functions overwritten in kio_smb_file.cpp - virtual void get( const KURL& kurl ); - virtual void put( const KURL& kurl, int permissions, bool overwrite, bool resume ); - - // Functions not implemented (yet) - //virtual void setHost(const TQString& host, int port, const TQString& user, const TQString& pass); - //virtual void openConnection(); - //virtual void closeConnection(); - //virtual void slave_status(); - virtual void special( const TQByteArray & ); - -private slots: - void readOutput(TDEProcess *proc, char *buffer, int buflen); - void readStdErr(TDEProcess *proc, char *buffer, int buflen); - -private: - TQString mybuf, mystderr; - -}; - -//=========================================================================== -// pointer to the slave created in kdemain -extern SMBSlave* G_TheSlave; - - -//========================================================================== -// the global libsmbclient authentication callback function -extern "C" -{ - -void auth_smbc_get_data(const char *server,const char *share, - char *workgroup, int wgmaxlen, - char *username, int unmaxlen, - char *password, int pwmaxlen); - -} - - -//=========================================================================== -// Main slave entrypoint (see kio_smb.cpp) -extern "C" -{ - -int kdemain( int argc, char **argv ); - -} - - -#endif //#endif KIO_SMB_H_INCLUDED diff --git a/tdeioslave/smb/kio_smb_auth.cpp b/tdeioslave/smb/kio_smb_auth.cpp deleted file mode 100644 index f11d80b3a..000000000 --- a/tdeioslave/smb/kio_smb_auth.cpp +++ /dev/null @@ -1,207 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: kio_smb_auth.cpp -// -// Abstract: member function implementations for SMBSlave that deal with -// SMB directory access -// -// Author(s): Matthew Peterson -// -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - -#include "kio_smb.h" -#include "kio_smb_internal.h" - -#include -#include -#include - -// call for libsmbclient -//========================================================================== -void auth_smbc_get_data(const char *server,const char *share, - char *workgroup, int wgmaxlen, - char *username, int unmaxlen, - char *password, int pwmaxlen) -//========================================================================== -{ - G_TheSlave->auth_smbc_get_data(server, share, - workgroup,wgmaxlen, - username, unmaxlen, - password, pwmaxlen); -} - -//-------------------------------------------------------------------------- -void SMBSlave::auth_smbc_get_data(const char *server,const char *share, - char *workgroup, int wgmaxlen, - char *username, int unmaxlen, - char *password, int pwmaxlen) -//-------------------------------------------------------------------------- -{ - //check this to see if we "really" need to authenticate... - SMBUrlType t = m_current_url.getType(); - if( t == SMBURLTYPE_ENTIRE_NETWORK ) - { - kdDebug(KIO_SMB) << "we don't really need to authenticate for this top level url, returning" << endl; - return; - } - kdDebug(KIO_SMB) << "AAAAAAAAAAAAAA auth_smbc_get_dat: set user=" << username << ", workgroup=" << workgroup - << " server=" << server << ", share=" << share << endl; - - TQString s_server = TQString::fromUtf8(server); - TQString s_share = TQString::fromUtf8(share); - workgroup[wgmaxlen - 1] = 0; - TQString s_workgroup = TQString::fromUtf8(workgroup); - username[unmaxlen - 1] = 0; - TQString s_username = TQString::fromUtf8(username); - password[pwmaxlen - 1] = 0; - TQString s_password = TQString::fromUtf8(password); - - TDEIO::AuthInfo info; - info.url = KURL("smb:///"); - info.url.setHost(s_server); - info.url.setPath("/" + s_share); - - info.username = s_username; - info.password = s_password; - info.verifyPath = true; - - kdDebug(KIO_SMB) << "libsmb-auth-callback URL:" << info.url << endl; - - if ( !checkCachedAuthentication( info ) ) - { - if ( m_default_user.isEmpty() ) - { - // ok, we do not know the password. Let's try anonymous before we try for real - info.username = "anonymous"; - info.password = TQString::null; - } - else - { - // user defined a default username/password in kcontrol; try this - info.username = m_default_user; - info.password = m_default_password; - } - - } else - kdDebug(KIO_SMB) << "got password through cache" << endl; - - strncpy(username, info.username.utf8(), unmaxlen - 1); - strncpy(password, info.password.utf8(), pwmaxlen - 1); -} - -bool SMBSlave::checkPassword(SMBUrl &url) -{ - kdDebug(KIO_SMB) << "checkPassword for " << url << endl; - - TDEIO::AuthInfo info; - info.url = KURL("smb:///"); - info.url.setHost(url.host()); - - TQString share = url.path(); - int index = share.find('/', 1); - if (index > 1) - share = share.left(index); - if (share.at(0) == '/') - share = share.mid(1); - info.url.setPath("/" + share); - info.verifyPath = true; - - if ( share.isEmpty() ) - info.prompt = i18n( - "Please enter authentication information for %1" ) - .arg( url.host() ); - else - info.prompt = i18n( - "Please enter authentication information for:\n" - "Server = %1\n" - "Share = %2" ) - .arg( url.host() ) - .arg( share ); - - info.username = url.user(); - kdDebug(KIO_SMB) << "call openPassDlg for " << info.url << endl; - - if ( openPassDlg(info) ) { - kdDebug(KIO_SMB) << "openPassDlg returned " << info.username << endl; - url.setUser(info.username); - url.setPass(info.password); - return true; - } - kdDebug(KIO_SMB) << "no value from openPassDlg\n"; - return false; -} - -//-------------------------------------------------------------------------- -// Initalizes the smbclient library -// -// Returns: 0 on success -1 with errno set on error -bool SMBSlave::auth_initialize_smbc() -{ - SMBCCTX *smb_context = NULL; - - kdDebug(KIO_SMB) << "auth_initialize_smbc " << endl; - if(m_initialized_smbc == false) - { - kdDebug(KIO_SMB) << "smbc_init call" << endl; - KSimpleConfig cfg( "tdeioslaverc", true ); - - cfg.setGroup( "SMB" ); - int debug_level = cfg.readNumEntry( "DebugLevel", 0 ); - -#if 0 - /* old API initialisation routine does not allow to set flags */ - - if(smbc_init(::auth_smbc_get_data,debug_level) == -1) - { - SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to initialize")); - return false; - } -#endif - smb_context = smbc_new_context(); - if (smb_context == NULL) { - SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to create context")); - return false; - } - - smb_context->debug = debug_level; - smb_context->callbacks.auth_fn = ::auth_smbc_get_data; - - if (!smbc_init_context(smb_context)) { - smbc_free_context(smb_context, false); - smb_context = NULL; - SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to initialize context")); - return false; - } - -#if defined(SMB_CTX_FLAG_USE_KERBEROS) && defined(SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS) - smb_context->flags |= SMB_CTX_FLAG_USE_KERBEROS | SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS; -#endif - - smbc_set_context(smb_context); - - m_initialized_smbc = true; - } - - return true; -} - diff --git a/tdeioslave/smb/kio_smb_browse.cpp b/tdeioslave/smb/kio_smb_browse.cpp deleted file mode 100644 index 26c379bde..000000000 --- a/tdeioslave/smb/kio_smb_browse.cpp +++ /dev/null @@ -1,476 +0,0 @@ - -///////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: kio_smb_browse.cpp -// -// Abstract: member function implementations for SMBSlave that deal with -// SMB browsing -// -// Author(s): Matthew Peterson -// -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - -#include -#include -#include - -#include - -#include - -#include "kio_smb.h" -#include "kio_smb_internal.h" - -using namespace TDEIO; - -int SMBSlave::cache_stat(const SMBUrl &url, struct stat* st ) -{ - int result = smbc_stat( url.toSmbcUrl(), st); - kdDebug(KIO_SMB) << "smbc_stat " << url << " " << errno << " " << result << endl; - kdDebug(KIO_SMB) << "size " << (TDEIO::filesize_t)st->st_size << endl; - return result; -} - -//--------------------------------------------------------------------------- -bool SMBSlave::browse_stat_path(const SMBUrl& _url, UDSEntry& udsentry, bool ignore_errors) - // Returns: true on success, false on failure -{ - UDSAtom udsatom; - - SMBUrl url = _url; - - if(cache_stat(url, &st) == 0) - { - if(!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) - { - kdDebug(KIO_SMB)<<"SMBSlave::browse_stat_path mode: "<pw_name; - else - udsatom.m_str = TQString::number( uid ); - udsentry.append(udsatom); - - udsatom.m_uds = TDEIO::UDS_GROUP; - gid_t gid = st.st_gid; - struct group *grp = getgrgid( gid ); - if ( grp ) - udsatom.m_str = grp->gr_name; - else - udsatom.m_str = TQString::number( gid ); - udsentry.append(udsatom); - - udsatom.m_uds = TDEIO::UDS_ACCESS; - udsatom.m_long = st.st_mode & 07777; - udsentry.append(udsatom); - - udsatom.m_uds = UDS_MODIFICATION_TIME; - udsatom.m_long = st.st_mtime; - udsentry.append(udsatom); - - udsatom.m_uds = UDS_ACCESS_TIME; - udsatom.m_long = st.st_atime; - udsentry.append(udsatom); - - udsatom.m_uds = UDS_CREATION_TIME; - udsatom.m_long = st.st_ctime; - udsentry.append(udsatom); - - } - else - { - if (!ignore_errors) { - if (errno == EPERM || errno == EACCES) - if (checkPassword(url)) { - redirection( url ); - return false; - } - - reportError(url); - } else if (errno == ENOENT || errno == ENOTDIR) { - warning(i18n("File does not exist: %1").arg(url.url())); - } - kdDebug(KIO_SMB) << "SMBSlave::browse_stat_path ERROR!!"<< endl; - return false; - } - - return true; -} - -//=========================================================================== -void SMBSlave::stat( const KURL& kurl ) -{ - kdDebug(KIO_SMB) << "SMBSlave::stat on "<< kurl << endl; - // make a valid URL - KURL url = checkURL(kurl); - - // if URL is not valid we have to redirect to correct URL - if (url != kurl) - { - kdDebug() << "redirection " << url << endl; - redirection(url); - finished(); - return; - } - - m_current_url = url; - - UDSAtom udsatom; - UDSEntry udsentry; - // Set name - udsatom.m_uds = TDEIO::UDS_NAME; - udsatom.m_str = kurl.fileName(); - udsentry.append( udsatom ); - - switch(m_current_url.getType()) - { - case SMBURLTYPE_UNKNOWN: - error(ERR_MALFORMED_URL,m_current_url.prettyURL()); - finished(); - return; - - case SMBURLTYPE_ENTIRE_NETWORK: - case SMBURLTYPE_WORKGROUP_OR_SERVER: - udsatom.m_uds = TDEIO::UDS_FILE_TYPE; - udsatom.m_long = S_IFDIR; - udsentry.append(udsatom); - break; - - case SMBURLTYPE_SHARE_OR_PATH: - if (browse_stat_path(m_current_url, udsentry, false)) - break; - else { - kdDebug(KIO_SMB) << "SMBSlave::stat ERROR!!"<< endl; - finished(); - return; - } - default: - kdDebug(KIO_SMB) << "SMBSlave::stat UNKNOWN " << url << endl; - finished(); - return; - } - - statEntry(udsentry); - finished(); -} - -//=========================================================================== -// TODO: complete checking -KURL SMBSlave::checkURL(const KURL& kurl) const -{ - kdDebug(KIO_SMB) << "checkURL " << kurl << endl; - TQString surl = kurl.url(); - if (surl.startsWith("smb:/")) { - if (surl.length() == 5) // just the above - return kurl; // unchanged - - if (surl.at(5) != '/') { - surl = "smb://" + surl.mid(5); - kdDebug(KIO_SMB) << "checkURL return1 " << surl << " " << KURL(surl) << endl; - return KURL(surl); - } - } - - // smb:/ normaly have no userinfo - // we must redirect ourself to remove the username and password - if (surl.contains('@') && !surl.contains("smb://")) { - KURL url(kurl); - url.setPath("/"+kurl.url().right( kurl.url().length()-kurl.url().find('@') -1)); - TQString userinfo = kurl.url().mid(5, kurl.url().find('@')-5); - if(userinfo.contains(':')) { - url.setUser(userinfo.left(userinfo.find(':'))); - url.setPass(userinfo.right(userinfo.length()-userinfo.find(':')-1)); - } else { - url.setUser(userinfo); - } - kdDebug(KIO_SMB) << "checkURL return2 " << url << endl; - return url; - } - - // no emtpy path - KURL url(kurl); - - if (url.path().isEmpty()) - url.setPath("/"); - - kdDebug(KIO_SMB) << "checkURL return3 " << url << endl; - return url; -} - -void SMBSlave::reportError(const SMBUrl &url) -{ - kdDebug(KIO_SMB) << "reportError " << url << " " << perror << endl; - switch(errno) - { - case ENOENT: - if (url.getType() == SMBURLTYPE_ENTIRE_NETWORK) - error( ERR_SLAVE_DEFINED, i18n("Unable to find any workgroups in your local network. This might be caused by an enabled firewall.")); - else - error( ERR_DOES_NOT_EXIST, url.prettyURL()); - break; -#ifdef ENOMEDIUM - case ENOMEDIUM: - error( ERR_SLAVE_DEFINED, - i18n( "No media in device for %1" ).arg( url.prettyURL() ) ); - break; -#endif -#ifdef EHOSTDOWN - case EHOSTDOWN: -#endif - case ECONNREFUSED: - error( ERR_SLAVE_DEFINED, - i18n( "Could not connect to host for %1" ).arg( url.prettyURL() ) ); - break; - case ENOTDIR: - error( ERR_CANNOT_ENTER_DIRECTORY, url.prettyURL()); - break; - case EFAULT: - case EINVAL: - error( ERR_DOES_NOT_EXIST, url.prettyURL()); - break; - case EPERM: - case EACCES: - error( ERR_ACCESS_DENIED, url.prettyURL() ); - break; - case EIO: - case ENETUNREACH: - if ( url.getType() == SMBURLTYPE_ENTIRE_NETWORK || url.getType() == SMBURLTYPE_WORKGROUP_OR_SERVER ) - error( ERR_SLAVE_DEFINED, i18n( "Error while connecting to server responsible for %1" ).arg( url.prettyURL() ) ); - else - error( ERR_CONNECTION_BROKEN, url.prettyURL()); - break; - case ENOMEM: - error( ERR_OUT_OF_MEMORY, url.prettyURL() ); - break; - case ENODEV: - error( ERR_SLAVE_DEFINED, i18n("Share could not be found on given server")); - break; - case EBADF: - error( ERR_INTERNAL, i18n("BAD File descriptor")); - break; - case ETIMEDOUT: - error( ERR_SERVER_TIMEOUT, url.host() ); - break; -#ifdef ENOTUNIQ - case ENOTUNIQ: - error( ERR_SLAVE_DEFINED, i18n( "The given name could not be resolved to a unique server. " - "Make sure your network is setup without any name conflicts " - "between names used by Windows and by UNIX name resolution." ) ); - break; -#endif - case 0: // success - error( ERR_INTERNAL, i18n("libsmbclient reported an error, but did not specify " - "what the problem is. This might indicate a severe problem " - "with your network - but also might indicate a problem with " - "libsmbclient.\n" - "If you want to help us, please provide a tcpdump of the " - "network interface while you try to browse (be aware that " - "it might contain private data, so do not post it if you are " - "unsure about that - you can send it privately to the developers " - "if they ask for it)") ); - break; - default: - error( ERR_INTERNAL, i18n("Unknown error condition in stat: %1").arg(TQString::fromLocal8Bit( strerror(errno))) ); - } -} - -//=========================================================================== -void SMBSlave::listDir( const KURL& kurl ) -{ - kdDebug(KIO_SMB) << "SMBSlave::listDir on " << kurl << endl; - - // check (correct) URL - KURL url = checkURL(kurl); - // if URL is not valid we have to redirect to correct URL - if (url != kurl) - { - redirection(url); - finished(); - return; - } - - m_current_url = kurl; - - int dirfd; - struct smbc_dirent *dirp = NULL; - UDSEntry udsentry; - UDSAtom atom; - - dirfd = smbc_opendir( m_current_url.toSmbcUrl() ); - kdDebug(KIO_SMB) << "SMBSlave::listDir open " << m_current_url.toSmbcUrl() << " " << m_current_url.getType() << " " << dirfd << endl; - if(dirfd >= 0) - { - do { - kdDebug(KIO_SMB) << "smbc_readdir " << endl; - dirp = smbc_readdir(dirfd); - if(dirp == 0) - break; - - // Set name - atom.m_uds = TDEIO::UDS_NAME; - TQString dirpName = TQString::fromUtf8( dirp->name ); - // We cannot trust dirp->commentlen has it might be with or without the NUL character - // See KDE bug #111430 and Samba bug #3030 - TQString comment = TQString::fromUtf8( dirp->comment ); - if ( dirp->smbc_type == SMBC_SERVER || dirp->smbc_type == SMBC_WORKGROUP ) { - atom.m_str = dirpName.lower(); - atom.m_str.at( 0 ) = dirpName.at( 0 ).upper(); - if ( !comment.isEmpty() && dirp->smbc_type == SMBC_SERVER ) - atom.m_str += " (" + comment + ")"; - } else - atom.m_str = dirpName; - - kdDebug(KIO_SMB) << "dirp->name " << dirp->name << " " << dirpName << " '" << comment << "'" << " " << dirp->smbc_type << endl; - - udsentry.append( atom ); - if (atom.m_str.upper()=="IPC$" || atom.m_str=="." || atom.m_str == ".." || - atom.m_str.upper() == "ADMIN$" || atom.m_str.lower() == "printer$" || atom.m_str.lower() == "print$" ) - { -// fprintf(stderr,"----------- hide: -%s-\n",dirp->name); - // do nothing and hide the hidden shares - } - else if(dirp->smbc_type == SMBC_FILE) - { - // Set stat information - m_current_url.addPath(dirpName); - browse_stat_path(m_current_url, udsentry, true); - m_current_url.cd(".."); - - // Call base class to list entry - listEntry(udsentry, false); - } - else if(dirp->smbc_type == SMBC_DIR) - { - m_current_url.addPath(dirpName); - browse_stat_path(m_current_url, udsentry, true); - m_current_url.cd(".."); - - // Call base class to list entry - listEntry(udsentry, false); - } - else if(dirp->smbc_type == SMBC_SERVER || - dirp->smbc_type == SMBC_FILE_SHARE) - { - // Set type - atom.m_uds = TDEIO::UDS_FILE_TYPE; - atom.m_long = S_IFDIR; - udsentry.append( atom ); - - // Set permissions - atom.m_uds = TDEIO::UDS_ACCESS; - atom.m_long = (S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH); - udsentry.append(atom); - - if (dirp->smbc_type == SMBC_SERVER) { - atom.m_uds = TDEIO::UDS_URL; - // TQString workgroup = m_current_url.host().upper(); - KURL u("smb:/"); - u.setHost(dirpName); - atom.m_str = u.url(); - - // when libsmbclient knows - // atom.m_str = TQString("smb://%1?WORKGROUP=%2").arg(dirpName).arg(workgroup.upper()); - kdDebug(KIO_SMB) << "list item " << atom.m_str << endl; - udsentry.append(atom); - - atom.m_uds = TDEIO::UDS_MIME_TYPE; - atom.m_str = TQString::fromLatin1("application/x-smb-server"); - udsentry.append(atom); - } - - // Call base class to list entry - listEntry(udsentry, false); - } - else if(dirp->smbc_type == SMBC_WORKGROUP) - { - // Set type - atom.m_uds = TDEIO::UDS_FILE_TYPE; - atom.m_long = S_IFDIR; - udsentry.append( atom ); - - // Set permissions - atom.m_uds = TDEIO::UDS_ACCESS; - atom.m_long = (S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH); - udsentry.append(atom); - - atom.m_uds = TDEIO::UDS_MIME_TYPE; - atom.m_str = TQString::fromLatin1("application/x-smb-workgroup"); - udsentry.append(atom); - - atom.m_uds = TDEIO::UDS_URL; - // TQString workgroup = m_current_url.host().upper(); - KURL u("smb:/"); - u.setHost(dirpName); - atom.m_str = u.url(); - udsentry.append(atom); - - // Call base class to list entry - listEntry(udsentry, false); - } - else - { - kdDebug(KIO_SMB) << "SMBSlave::listDir SMBC_UNKNOWN :" << dirpName << endl; - // TODO: we don't handle SMBC_IPC_SHARE, SMBC_PRINTER_SHARE - // SMBC_LINK, SMBC_COMMS_SHARE - //SlaveBase::error(ERR_INTERNAL, TEXT_UNSUPPORTED_FILE_TYPE); - // continue; - } - udsentry.clear(); - } while (dirp); // checked already in the head - - // clean up - smbc_closedir(dirfd); - } - else - { - if (errno == EPERM || errno == EACCES) - if (checkPassword(m_current_url)) { - redirection( m_current_url ); - finished(); - return; - } - - reportError(m_current_url); - finished(); - return; - } - - listEntry(udsentry, true); - finished(); -} - diff --git a/tdeioslave/smb/kio_smb_config.cpp b/tdeioslave/smb/kio_smb_config.cpp deleted file mode 100644 index 8179371e7..000000000 --- a/tdeioslave/smb/kio_smb_config.cpp +++ /dev/null @@ -1,66 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: kio_smb_config.cpp -// -// Abstract: member function implementations for SMBSlave that deal with -// KDE/SMB slave configuration -// -// Author(s): Matthew Peterson -// -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - -#include "kio_smb.h" -#include "kio_smb_internal.h" -#include - -#include -//=========================================================================== -void SMBSlave::reparseConfiguration() -{ - TDEConfig *cfg = new TDEConfig("tdeioslaverc", true); - cfg->setGroup("Browser Settings/SMBro"); - m_default_user=cfg->readEntry("User"); -// m_default_workgroup=cfg->readEntry("Workgroup"); -// m_showHiddenShares=cfg->readBoolEntry("ShowHiddenShares",false); - - TQString m_encoding = TQTextCodec::codecForLocale()->name(); - m_default_encoding = cfg->readEntry( "Encoding", m_encoding.lower() ); - - // unscramble, taken from Nicola Brodu's smb ioslave - //not really secure, but better than storing the plain password - TQString scrambled = cfg->readEntry( "Password" ); - m_default_password = ""; - for (uint i=0; i -// -////--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - -#include "kio_smb.h" -#include "kio_smb_internal.h" - - -//=========================================================================== -// TODO: add when libsmbclient supports it -void SMBSlave::copy( const KURL& ksrc, - const KURL& kdst, - int permissions, - bool overwrite) -{ - - SMBUrl src; - SMBUrl dst; - mode_t initialmode; - int n; - int dstflags; - int srcfd = -1; - int dstfd = -1; - TDEIO::filesize_t processed_size = 0; - unsigned char buf[MAX_XFER_BUF_SIZE]; - - kdDebug(KIO_SMB) << "SMBSlave::copy with src = " << ksrc << "and dest = " << kdst << endl; - - // setup urls - src = ksrc; - dst = kdst; - - // Obtain information about source - if(cache_stat(src, &st ) == -1) - { - if ( errno == EACCES ) - { - error( TDEIO::ERR_ACCESS_DENIED, src.prettyURL()); - } - else - { - error( TDEIO::ERR_DOES_NOT_EXIST, src.prettyURL()); - } - return; - } - if ( S_ISDIR( st.st_mode ) ) - { - error( TDEIO::ERR_IS_DIRECTORY, src.prettyURL() ); - return; - } - totalSize(st.st_size); - - // Check to se if the destination exists - if(cache_stat(dst, &st) != -1) - { - if(S_ISDIR(st.st_mode)) - { - error( TDEIO::ERR_DIR_ALREADY_EXIST, dst.prettyURL()); - return; - } - if(!overwrite) - { - error( TDEIO::ERR_FILE_ALREADY_EXIST, dst.prettyURL()); - return; - } - } - - // Open the source file - srcfd = smbc_open(src.toSmbcUrl(), O_RDONLY, 0); - if(srcfd < 0) - { - if(errno == EACCES) - { - error( TDEIO::ERR_ACCESS_DENIED, src.prettyURL() ); - } - else - { - error( TDEIO::ERR_DOES_NOT_EXIST, src.prettyURL() ); - } - return; - } - - // Determine initial creation mode - if(permissions != -1) - { - initialmode = permissions | S_IWUSR; - } - else - { - initialmode = 0 | S_IWUSR;//0666; - } - - - // Open the destination file - dstflags = O_CREAT | O_TRUNC | O_WRONLY; - if(!overwrite) - { - dstflags |= O_EXCL; - } - dstfd = smbc_open(dst.toSmbcUrl(), dstflags, initialmode); - if(dstfd < 0) - { - if(errno == EACCES) - { - error(TDEIO::ERR_WRITE_ACCESS_DENIED, dst.prettyURL()); - } - else - { - error(TDEIO::ERR_CANNOT_OPEN_FOR_READING, dst.prettyURL()); - } - if(srcfd >= 0 ) - { - smbc_close(srcfd); - } - return; - } - - - // Perform copy - while(1) - { - n = smbc_read(srcfd, buf, MAX_XFER_BUF_SIZE ); - if(n > 0) - { - n = smbc_write(dstfd, buf, n); - if(n == -1) - { - kdDebug(KIO_SMB) << "SMBSlave::copy copy now TDEIO::ERR_COULD_NOT_WRITE" << endl; - error( TDEIO::ERR_COULD_NOT_WRITE, dst.prettyURL()); - break; - } - - processed_size += n; - processedSize(processed_size); - } - else if(n == 0) - { - break; // finished - } - else - { - error( TDEIO::ERR_COULD_NOT_READ, src.prettyURL()); - break; - } - } - - - // FINISHED: - - if(srcfd >= 0 ) - { - smbc_close(srcfd); - } - - if(dstfd >= 0) - { - if(smbc_close(dstfd) == 0) - { - - // TODO: set final permissions - } - else - { - error( TDEIO::ERR_COULD_NOT_WRITE, dst.prettyURL()); - return; - } - } - - finished(); -} - -//=========================================================================== -void SMBSlave::del( const KURL &kurl, bool isfile) -{ - kdDebug(KIO_SMB) << "SMBSlave::del on " << kurl << endl; - m_current_url = kurl; - - if(isfile) - { - // Delete file - kdDebug(KIO_SMB) << "SMBSlave:: unlink " << kurl << endl; - if(smbc_unlink(m_current_url.toSmbcUrl()) == -1) - { - switch(errno) - { - case EISDIR: - error( TDEIO::ERR_IS_DIRECTORY, m_current_url.prettyURL()); - break; - default: - reportError(kurl); - } - } - } - else - { - kdDebug(KIO_SMB) << "SMBSlave:: rmdir " << kurl << endl; - // Delete directory - if(smbc_rmdir(m_current_url.toSmbcUrl()) == -1) - { - reportError(kurl); - } - } - - finished(); -} - -//=========================================================================== -void SMBSlave::mkdir( const KURL &kurl, int permissions ) -{ - kdDebug(KIO_SMB) << "SMBSlave::mkdir on " << kurl << endl; - m_current_url = kurl; - - if(smbc_mkdir(m_current_url.toSmbcUrl(), 0777) != 0) - { - if (errno == EEXIST) { - if(cache_stat(m_current_url, &st ) == 0) - { - if(S_ISDIR(st.st_mode )) - { - error( TDEIO::ERR_DIR_ALREADY_EXIST, m_current_url.prettyURL()); - } - } - else - { - error( TDEIO::ERR_FILE_ALREADY_EXIST, m_current_url.prettyURL()); - } - } else - reportError(kurl); - kdDebug(KIO_SMB) << "SMBSlave::mkdir exit with error " << kurl << endl; - } - else - { - if(permissions != -1) - { - // TODO enable the following when complete - //smbc_chmod( url.toSmbcUrl(), permissions ); - } - } - - finished(); -} - - -//=========================================================================== -void SMBSlave::rename( const KURL& ksrc, const KURL& kdest, bool overwrite ) -{ - - SMBUrl src; - SMBUrl dst; - - kdDebug(KIO_SMB) << "SMBSlave::rename, old name = " << ksrc << ", new name = " << kdest << endl; - - src = ksrc; - dst = kdest; - - // Check to se if the destination exists - - kdDebug(KIO_SMB) << "SMBSlave::rename stat dst" << endl; - if(cache_stat(dst, &st) != -1) - { - if(S_ISDIR(st.st_mode)) - { - kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_DIR_ALREADY_EXIST" << endl; - error( TDEIO::ERR_DIR_ALREADY_EXIST, dst.prettyURL()); - finished(); - return; - } - if(!overwrite) - { - kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_FILE_ALREADY_EXIST" << endl; - error( TDEIO::ERR_FILE_ALREADY_EXIST, dst.prettyURL()); - finished(); - return; - } - } - kdDebug(KIO_SMB ) << "smbc_rename " << src.toSmbcUrl() << " " << dst.toSmbcUrl() << endl; - if(smbc_rename(src.toSmbcUrl(), dst.toSmbcUrl())!=0) - { - kdDebug(KIO_SMB ) << "failed " << perror << endl; - switch(errno) - { - case ENOENT: - if(cache_stat(src, &st) == -1) - { - if(errno == EACCES) - { - kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_ACCESS_DENIED" << endl; - error(TDEIO::ERR_ACCESS_DENIED, src.prettyURL()); - } - else - { - kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_DOES_NOT_EXIST" << endl; - error(TDEIO::ERR_DOES_NOT_EXIST, src.prettyURL()); - } - } - break; - - case EACCES: - case EPERM: - kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_ACCESS_DENIED" << endl; - error( TDEIO::ERR_ACCESS_DENIED, dst.prettyURL() ); - break; - - default: - kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_CANNOT_RENAME" << endl; - error( TDEIO::ERR_CANNOT_RENAME, src.prettyURL() ); - - } - - kdDebug(KIO_SMB) << "SMBSlave::rename exit with error" << endl; - return; - } - - kdDebug(KIO_SMB ) << "everything fine\n"; - finished(); -} - - diff --git a/tdeioslave/smb/kio_smb_file.cpp b/tdeioslave/smb/kio_smb_file.cpp deleted file mode 100644 index b65f79f42..000000000 --- a/tdeioslave/smb/kio_smb_file.cpp +++ /dev/null @@ -1,279 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: kio_smb_file.cpp -// -// Abstract: member function implementations for SMBSlave that deal with -// SMB file access -// -// Author(s): Matthew Peterson -// -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - - -#include "kio_smb.h" -#include "kio_smb_internal.h" - -#include - -//=========================================================================== -void SMBSlave::get( const KURL& kurl ) -{ - char buf[MAX_XFER_BUF_SIZE]; - int filefd = 0; - ssize_t bytesread = 0; - // time_t curtime = 0; - time_t lasttime = 0; - time_t starttime = 0; - TDEIO::filesize_t totalbytesread = 0; - TQByteArray filedata; - SMBUrl url; - - kdDebug(KIO_SMB) << "SMBSlave::get on " << kurl << endl; - - // check (correct) URL - KURL kvurl = checkURL(kurl); - // if URL is not valid we have to redirect to correct URL - if (kvurl != kurl) { - redirection(kvurl); - finished(); - return; - } - - if(!auth_initialize_smbc()) - return; - - - // Stat - url = kurl; - if(cache_stat(url,&st) == -1 ) - { - if ( errno == EACCES ) - error( TDEIO::ERR_ACCESS_DENIED, url.prettyURL()); - else - error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL()); - return; - } - if ( S_ISDIR( st.st_mode ) ) { - error( TDEIO::ERR_IS_DIRECTORY, url.prettyURL()); - return; - } - - // Set the total size - totalSize( st.st_size ); - - // Open and read the file - filefd = smbc_open(url.toSmbcUrl(),O_RDONLY,0); - if(filefd >= 0) - { - if(buf) - { - bool isFirstPacket = true; - lasttime = starttime = time(NULL); - while(1) - { - bytesread = smbc_read(filefd, buf, MAX_XFER_BUF_SIZE); - if(bytesread == 0) - { - // All done reading - break; - } - else if(bytesread < 0) - { - error( TDEIO::ERR_COULD_NOT_READ, url.prettyURL()); - return; - } - - filedata.setRawData(buf,bytesread); - if (isFirstPacket) - { - // We need a KMimeType::findByNameAndContent(filename,data) - // For now we do: find by extension, and if not found (or extension not reliable) - // then find by content. - bool accurate = false; - KMimeType::Ptr mime = KMimeType::findByURL( kurl, st.st_mode, false, true, &accurate ); - if ( !mime || mime->name() == KMimeType::defaultMimeType() - || !accurate ) - { - KMimeType::Ptr p_mimeType = KMimeType::findByContent(filedata); - if ( p_mimeType && p_mimeType->name() != KMimeType::defaultMimeType() ) - mime = p_mimeType; - } - mimeType(mime->name()); - isFirstPacket = false; - } - data( filedata ); - filedata.resetRawData(buf,bytesread); - - // increment total bytes read - totalbytesread += bytesread; - - processedSize(totalbytesread); - } - } - - smbc_close(filefd); - data( TQByteArray() ); - processedSize(static_cast(st.st_size)); - - } - else - { - error( TDEIO::ERR_CANNOT_OPEN_FOR_READING, url.prettyURL()); - return; - } - - finished(); -} - - -//=========================================================================== -void SMBSlave::put( const KURL& kurl, - int permissions, - bool overwrite, - bool resume ) -{ - - void *buf; - size_t bufsize; - - m_current_url = kurl; - - int filefd; - bool exists; - mode_t mode; - TQByteArray filedata; - - kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl << endl; - - - exists = (cache_stat(m_current_url, &st) != -1 ); - if ( exists && !overwrite && !resume) - { - if (S_ISDIR(st.st_mode)) - { - kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl <<" already isdir !!"<< endl; - error( TDEIO::ERR_DIR_ALREADY_EXIST, m_current_url.prettyURL()); - } - else - { - kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl <<" already exist !!"<< endl; - error( TDEIO::ERR_FILE_ALREADY_EXIST, m_current_url.prettyURL()); - } - return; - } - - if (exists && !resume && overwrite) - { - kdDebug(KIO_SMB) << "SMBSlave::put exists try to remove " << m_current_url.toSmbcUrl()<< endl; - // remove(m_current_url.url().local8Bit()); - } - - - if (resume) - { - // append if resuming - kdDebug(KIO_SMB) << "SMBSlave::put resume " << m_current_url.toSmbcUrl()<< endl; - filefd = smbc_open(m_current_url.toSmbcUrl(), O_RDWR, 0 ); - smbc_lseek(filefd, 0, SEEK_END); - } - else - { - if (permissions != -1) - { - mode = permissions | S_IWUSR | S_IRUSR; - } - else - { - mode = 600;//0666; - } - - kdDebug(KIO_SMB) << "SMBSlave::put NO resume " << m_current_url.toSmbcUrl()<< endl; - filefd = smbc_open(m_current_url.toSmbcUrl(), O_CREAT | O_TRUNC | O_WRONLY, mode); - } - - if ( filefd < 0 ) - { - if ( errno == EACCES ) - { - kdDebug(KIO_SMB) << "SMBSlave::put error " << kurl <<" access denied !!"<< endl; - error( TDEIO::ERR_WRITE_ACCESS_DENIED, m_current_url.prettyURL()); - } - else - { - kdDebug(KIO_SMB) << "SMBSlave::put error " << kurl <<" can not open for writing !!"<< endl; - error( TDEIO::ERR_CANNOT_OPEN_FOR_WRITING, m_current_url.prettyURL()); - } - finished(); - return; - } - - // Loop until we got 0 (end of data) - while(1) - { - kdDebug(KIO_SMB) << "SMBSlave::put request data "<< endl; - dataReq(); // Request for data - kdDebug(KIO_SMB) << "SMBSlave::put write " << m_current_url.toSmbcUrl()<< endl; - - if (readData(filedata) <= 0) - { - kdDebug(KIO_SMB) << "readData <= 0" << endl; - break; - } - kdDebug(KIO_SMB) << "SMBSlave::put write " << m_current_url.toSmbcUrl()<< endl; - buf = filedata.data(); - bufsize = filedata.size(); - int size = smbc_write(filefd, buf, bufsize); - if ( size < 0) - { - kdDebug(KIO_SMB) << "SMBSlave::put error " << kurl <<" could not write !!"<< endl; - error( TDEIO::ERR_COULD_NOT_WRITE, m_current_url.prettyURL()); - finished(); - return; - } - kdDebug(KIO_SMB ) << "wrote " << size << endl; - } - kdDebug(KIO_SMB) << "SMBSlave::put close " << m_current_url.toSmbcUrl()<< endl; - - if(smbc_close(filefd)) - { - kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl <<" could not write !!"<< endl; - error( TDEIO::ERR_COULD_NOT_WRITE, m_current_url.prettyURL()); - finished(); - return; - } - - // set final permissions, if the file was just created - if ( permissions != -1 && !exists ) - { - // TODO: did the smbc_chmod fail? - // TODO: put in call to chmod when it is working! - // smbc_chmod(url.toSmbcUrl(),permissions); - } - - // We have done our job => finish - finished(); -} - - - - diff --git a/tdeioslave/smb/kio_smb_internal.cpp b/tdeioslave/smb/kio_smb_internal.cpp deleted file mode 100644 index 8f56a8f62..000000000 --- a/tdeioslave/smb/kio_smb_internal.cpp +++ /dev/null @@ -1,135 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: kio_smb_internal.cpp -// -// Abstract: Utility class implementation used by SMBSlave -// -// Author(s): Matthew Peterson -// -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - -#include "kio_smb.h" -#include "kio_smb_internal.h" - -#include - -#include -#include - - -//=========================================================================== -// SMBUrl Function Implementation -//=========================================================================== - -//----------------------------------------------------------------------- -SMBUrl::SMBUrl() -{ - m_type = SMBURLTYPE_UNKNOWN; -} - -//----------------------------------------------------------------------- -SMBUrl::SMBUrl(const KURL& kurl) - : KURL(kurl) - //----------------------------------------------------------------------- -{ - updateCache(); -} - - -//----------------------------------------------------------------------- -void SMBUrl::addPath(const TQString &filedir) -{ - KURL::addPath(filedir); - updateCache(); -} - -//----------------------------------------------------------------------- -bool SMBUrl::cd(const TQString &filedir) -{ - if (!KURL::cd(filedir)) - return false; - updateCache(); - return true; -} - -//----------------------------------------------------------------------- -void SMBUrl::updateCache() - //----------------------------------------------------------------------- -{ - cleanPath(); - - // SMB URLs are UTF-8 encoded - kdDebug(KIO_SMB) << "updateCache " << KURL::path() << endl; - if (KURL::url() == "smb:/") - m_surl = "smb://"; - else { - TQString surl = "smb://"; - if (KURL::hasUser()) { - surl += KURL::encode_string(KURL::user(), 106); - if (KURL::hasPass()) { - surl += ":" + KURL::encode_string(KURL::pass(), 106); - } - surl += "@"; - } - surl += KURL::encode_string(KURL::host().upper(), 106); - surl += KURL::encode_string(KURL::path(), 106); - m_surl = surl.utf8(); - } - m_type = SMBURLTYPE_UNKNOWN; - // update m_type - (void)getType(); -} - -//----------------------------------------------------------------------- -SMBUrlType SMBUrl::getType() const - // Returns the type of this SMBUrl: - // SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url. - // SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network - // SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver" - // SMBURLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir" - //----------------------------------------------------------------------- -{ - if(m_type != SMBURLTYPE_UNKNOWN) - return m_type; - - if (protocol() != "smb") - { - m_type = SMBURLTYPE_UNKNOWN; - return m_type; - } - - if (path(1) == "/") - { - if (host().isEmpty()) - m_type = SMBURLTYPE_ENTIRE_NETWORK; - else - m_type = SMBURLTYPE_WORKGROUP_OR_SERVER; - return m_type; - } - - // Check for the path if we get this far - m_type = SMBURLTYPE_SHARE_OR_PATH; - - return m_type; -} - diff --git a/tdeioslave/smb/kio_smb_internal.h b/tdeioslave/smb/kio_smb_internal.h deleted file mode 100644 index 2d97aee31..000000000 --- a/tdeioslave/smb/kio_smb_internal.h +++ /dev/null @@ -1,118 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Project: SMB tdeioslave for KDE2 -// -// File: kio_smb_internal.h -// -// Abstract: Utility classes used by SMBSlave -// -// Author(s): Matthew Peterson -// Frank Schwanz -//--------------------------------------------------------------------------- -// -// Copyright (c) 2000 Caldera Systems, Inc. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, please obtain -// a copy from http://www.gnu.org/copyleft/gpl.html -// -///////////////////////////////////////////////////////////////////////////// - -#ifndef KIO_SMB_INTERNAL_H_INCLUDED -#define KIO_SMB_INTERNAL_H_INCLUDED - -#include - -/** - * Types of a SMBURL : - * SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url. - * SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network - * SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver" - * URLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir" - */ -enum SMBUrlType { - SMBURLTYPE_UNKNOWN = 0, SMBURLTYPE_ENTIRE_NETWORK = 1, - SMBURLTYPE_WORKGROUP_OR_SERVER = 2, SMBURLTYPE_SHARE_OR_PATH = 3 -}; - - -//=========================================================================== -/** - * Class to handle URL's - * it can convert KURL to smbUrl - * and Handle UserInfo - * it also check the correctness of the URL - */ -class SMBUrl : public KURL -{ - - -public: - SMBUrl(); - SMBUrl(const KURL & kurl); - - /** - * Appends the specified file and dir to this SMBUrl - * "smb://server/share" --> "smb://server/share/filedir" - */ - void addPath(const TQString &filedir); - - bool cd(const TQString &dir); - - /** - * Returns the type of this SMBUrl: - * SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url. - * SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network - * SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver" - * URLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir" - */ - SMBUrlType getType() const; - - void setPass( const TQString& _txt ) { KURL::setPass(_txt); updateCache(); } - void setUser( const TQString& _txt ) { KURL::setUser(_txt); updateCache(); } - void setHost( const TQString& _txt ) { KURL::setHost(_txt); updateCache(); } - - /** - * Returns the workgroup if it given in url - */ -// TQString getWorkgroup() const; - - /** - * Returns path after workgroup - */ -// TQString getServerShareDir() const; - - /** - * Return a URL that is suitable for libsmbclient - */ - TQCString toSmbcUrl() const { return m_surl; } - -private: - /** - * Change from TQString to TQCString (MS Windows's character encoding) - */ - TQCString fromUnicode( const TQString &_str ) const; - - void updateCache(); - TQCString m_surl; - - /** - * Type of URL - * @see _SMBUrlType - */ - mutable SMBUrlType m_type; -}; - - -#endif - diff --git a/tdeioslave/smb/kio_smb_mount.cpp b/tdeioslave/smb/kio_smb_mount.cpp deleted file mode 100644 index ad421f631..000000000 --- a/tdeioslave/smb/kio_smb_mount.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2000 Alexander Neundorf - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kio_smb.h" -#include -#include -#include -#include -#include - -void SMBSlave::readOutput(TDEProcess *, char *buffer, int buflen) -{ - mybuf += TQString::fromLocal8Bit(buffer, buflen); -} - -void SMBSlave::readStdErr(TDEProcess *, char *buffer, int buflen) -{ - mystderr += TQString::fromLocal8Bit(buffer, buflen); -} - -void SMBSlave::special( const TQByteArray & data) -{ - kdDebug(KIO_SMB)<<"Smb::special()"<> tmp; - //mounting and umounting are both blocking, "guarded" by a SIGALARM in the future - switch (tmp) - { - case 1: - case 3: - { - TQString remotePath, mountPoint, user; - stream >> remotePath >> mountPoint; - - TQStringList sl=TQStringList::split("/",remotePath); - TQString share,host; - if (sl.count()>=2) - { - host=(*sl.at(0)).mid(2); - share=(*sl.at(1)); - kdDebug(KIO_SMB)<<"special() host -"<< host <<"- share -" << share <<"-"<> mountPoint; - - TDEProcess proc; - proc.setUseShell(true); - proc << "smbumount"; - proc << TDEProcess::quote(mountPoint); - - mybuf.truncate(0); - mystderr.truncate(0); - - connect(&proc, TQT_SIGNAL( receivedStdout(TDEProcess *, char *, int )), - TQT_SLOT(readOutput(TDEProcess *, char *, int))); - - connect(&proc, TQT_SIGNAL( receivedStderr(TDEProcess *, char *, int )), - TQT_SLOT(readStdErr(TDEProcess *, char *, int))); - - if ( !proc.start( TDEProcess::Block, TDEProcess::AllOutput ) ) - { - error(TDEIO::ERR_CANNOT_LAUNCH_PROCESS, - "smbumount"+i18n("\nMake sure that the samba package is installed properly on your system.")); - return; - } - - kdDebug(KIO_SMB) << "smbumount exit " << proc.exitStatus() << endl - << "stdout:" << mybuf << endl << "stderr:" << mystderr << endl; - - if (proc.exitStatus() != 0) - { - error(TDEIO::ERR_COULD_NOT_UNMOUNT, - i18n("Unmounting of mountpoint \"%1\" failed.\n%2") - .arg(mountPoint).arg(mybuf + "\n" + mystderr)); - return; - } - - if ( tmp == 4 ) - { - bool ok; - - TQDir dir(mountPoint); - dir.cdUp(); - ok = dir.rmdir(mountPoint); - if ( ok ) - { - TQString p=dir.path(); - dir.cdUp(); - ok = dir.rmdir(p); - } - - if ( !ok ) - { - error(TDEIO::ERR_COULD_NOT_RMDIR, mountPoint); - return; - } - } - - finished(); - } - break; - default: - break; - } - finished(); -} - -#include "kio_smb.moc" diff --git a/tdeioslave/smb/smb.protocol b/tdeioslave/smb/smb.protocol index 2c0bda020..06ac69a10 100644 --- a/tdeioslave/smb/smb.protocol +++ b/tdeioslave/smb/smb.protocol @@ -1,5 +1,5 @@ [Protocol] -exec=kio_smb +exec=tdeio_smb protocol=smb input=none output=filesystem diff --git a/tdeioslave/smb/tdeio_smb.cpp b/tdeioslave/smb/tdeio_smb.cpp new file mode 100644 index 000000000..8ee270256 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb.cpp @@ -0,0 +1,77 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: Top level implementation file for tdeio_smb.cpp +// +// Abstract: member function implementations for SMBSlave +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#include "tdeio_smb.h" +#include "tdeio_smb_internal.h" + +//=========================================================================== +SMBSlave::SMBSlave(const TQCString& pool, const TQCString& app) + : SlaveBase( "smb", pool, app ) +{ + m_initialized_smbc = false; + + //read in the default workgroup info... + reparseConfiguration(); + + //initialize the library... + auth_initialize_smbc(); +} + + +//=========================================================================== +SMBSlave::~SMBSlave() +{ +} + + +//=========================================================================== +// pointer to the slave created in kdemain +SMBSlave* G_TheSlave; + +//=========================================================================== +int KDE_EXPORT kdemain( int argc, char **argv ) +{ + + TDEInstance instance( "tdeio_smb" ); + if( argc != 4 ) + { + kdDebug(KIO_SMB) << "Usage: tdeio_smb protocol domain-socket1 domain-socket2" + << endl; + return -1; + } + + SMBSlave slave( argv[2], argv[3] ); + + G_TheSlave = &slave; + slave.dispatchLoop(); + + return 0; +} + diff --git a/tdeioslave/smb/tdeio_smb.h b/tdeioslave/smb/tdeio_smb.h new file mode 100644 index 000000000..0c89eae95 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb.h @@ -0,0 +1,301 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: tdeio_smb.h +// +// Abstract: The main tdeio slave class declaration. For convenience, +// in concurrent devlopment, the implementation for this class +// is separated into several .cpp files -- the file containing +// the implementation should be noted in the comments for each +// member function. +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + + +#ifndef KIO_SMB_H_INCLUDED +#define KIO_SMB_H_INCLUDED + +//------------- +// QT includes +//------------- +#include +#include +#include +#include +#include + +//-------------- +// KDE includes +//-------------- +#include +#include +#include +#include +#include +#include + +//----------------------------- +// Standard C library includes +//----------------------------- +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//------------------------------- +// Samba client library includes +//------------------------------- +extern "C" +{ +#include +} + +//--------------------------- +// tdeio_smb internal includes +//--------------------------- +#include "tdeio_smb_internal.h" + +#define MAX_XFER_BUF_SIZE 16348 +#define KIO_SMB 7106 + +using namespace TDEIO; +class TDEProcess; + +//=========================================================================== + + +class SMBSlave : public TQObject, public TDEIO::SlaveBase +{ + Q_OBJECT + +private: + //--------------------------------------------------------------------- + // please make sure your private data does not duplicate existing data + //--------------------------------------------------------------------- + bool m_initialized_smbc; + + /** + * From Controlcenter + */ + TQString m_default_user; +// TQString m_default_workgroup; //currently unused, Alex + TQString m_default_password; + TQString m_default_encoding; + + /** + * we store the current url, it's needed for + * callback authorisation method + */ + SMBUrl m_current_url; + + /** + * From Controlcenter, show SHARE$ or not + */ +// bool m_showHiddenShares; //currently unused, Alex + + /** + * libsmbclient need global variables to store in, + * else it crashes on exit next method after use cache_stat, + * looks like gcc (C/C++) failure + */ + struct stat st; +protected: + //--------------------------------------------- + // Authentication functions (tdeio_smb_auth.cpp) + //--------------------------------------------- + // (please prefix functions with auth) + + + /** + * Description : Initilizes the libsmbclient + * Return : true on success false with errno set on error + */ + bool auth_initialize_smbc(); + + bool checkPassword(SMBUrl &url); + + + //--------------------------------------------- + // Cache functions (tdeio_smb_auth.cpp) + //--------------------------------------------- + + //Stat methods + + //----------------------------------------- + // Browsing functions (tdeio_smb_browse.cpp) + //----------------------------------------- + // (please prefix functions with browse) + + /** + * Description : Return a stat of given SMBUrl. Calls cache_stat and + * pack it in UDSEntry. UDSEntry will not be cleared + * Parameter : SMBUrl the url to stat + * ignore_errors do not call error(), but warning() + * Return : false if any error occoured (errno), else true + */ + bool browse_stat_path(const SMBUrl& url, UDSEntry& udsentry, bool ignore_errors); + + /** + * Description : call smbc_stat and return stats of the url + * Parameter : SMBUrl the url to stat + * Return : stat* of the url + * Note : it has some problems with stat in method, looks like + * something leave(or removed) on the stack. If your + * method segfault on returning try to change the stat* + * variable + */ + int cache_stat( const SMBUrl& url, struct stat* st ); + + //--------------------------------------------- + // Configuration functions (tdeio_smb_config.cpp) + //--------------------------------------------- + // (please prefix functions with config) + + + //--------------------------------------- + // Directory functions (tdeio_smb_dir.cpp) + //--------------------------------------- + // (please prefix functions with dir) + + + //-------------------------------------- + // File IO functions (tdeio_smb_file.cpp) + //-------------------------------------- + // (please prefix functions with file) + + //---------------------------- + // Misc functions (this file) + //---------------------------- + + + /** + * Description : correct a given URL + * valid URL's are + * + * smb://[[domain;]user[:password]@]server[:port][/share[/path[/file]]] + * smb:/[[domain;]user[:password]@][group/[server[/share[/path[/file]]]]] + * domain = workgroup(domain) of the user + * user = username + * password = password of useraccount + * group = workgroup(domain) of server + * server = host to connect + * share = a share of the server (host) + * path = a path of the share + * Parameter : KURL the url to check + * Return : new KURL if its corrected. else the same KURL + */ + KURL checkURL(const KURL& kurl) const; + + void reportError(const SMBUrl &kurl); + +public: + + //----------------------------------------------------------------------- + // smbclient authentication callback (note that this is called by the + // global ::auth_smbc_get_data() call. + void auth_smbc_get_data(const char *server,const char *share, + char *workgroup, int wgmaxlen, + char *username, int unmaxlen, + char *password, int pwmaxlen); + + + //----------------------------------------------------------------------- + // Overwritten functions from the base class that define the operation of + // this slave. (See the base class headerfile slavebase.h for more + // details) + //----------------------------------------------------------------------- + + // Functions overwritten in tdeio_smb.cpp + SMBSlave(const TQCString& pool, const TQCString& app); + virtual ~SMBSlave(); + + // Functions overwritten in tdeio_smb_browse.cpp + virtual void listDir( const KURL& url ); + virtual void stat( const KURL& url ); + + // Functions overwritten in tdeio_smb_config.cpp + virtual void reparseConfiguration(); + + // Functions overwritten in tdeio_smb_dir.cpp + virtual void copy( const KURL& src, const KURL &dest, int permissions, bool overwrite ); + virtual void del( const KURL& kurl, bool isfile); + virtual void mkdir( const KURL& kurl, int permissions ); + virtual void rename( const KURL& src, const KURL& dest, bool overwrite ); + + // Functions overwritten in tdeio_smb_file.cpp + virtual void get( const KURL& kurl ); + virtual void put( const KURL& kurl, int permissions, bool overwrite, bool resume ); + + // Functions not implemented (yet) + //virtual void setHost(const TQString& host, int port, const TQString& user, const TQString& pass); + //virtual void openConnection(); + //virtual void closeConnection(); + //virtual void slave_status(); + virtual void special( const TQByteArray & ); + +private slots: + void readOutput(TDEProcess *proc, char *buffer, int buflen); + void readStdErr(TDEProcess *proc, char *buffer, int buflen); + +private: + TQString mybuf, mystderr; + +}; + +//=========================================================================== +// pointer to the slave created in kdemain +extern SMBSlave* G_TheSlave; + + +//========================================================================== +// the global libsmbclient authentication callback function +extern "C" +{ + +void auth_smbc_get_data(const char *server,const char *share, + char *workgroup, int wgmaxlen, + char *username, int unmaxlen, + char *password, int pwmaxlen); + +} + + +//=========================================================================== +// Main slave entrypoint (see tdeio_smb.cpp) +extern "C" +{ + +int kdemain( int argc, char **argv ); + +} + + +#endif //#endif KIO_SMB_H_INCLUDED diff --git a/tdeioslave/smb/tdeio_smb_auth.cpp b/tdeioslave/smb/tdeio_smb_auth.cpp new file mode 100644 index 000000000..ebc15c1c6 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb_auth.cpp @@ -0,0 +1,207 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: tdeio_smb_auth.cpp +// +// Abstract: member function implementations for SMBSlave that deal with +// SMB directory access +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#include "tdeio_smb.h" +#include "tdeio_smb_internal.h" + +#include +#include +#include + +// call for libsmbclient +//========================================================================== +void auth_smbc_get_data(const char *server,const char *share, + char *workgroup, int wgmaxlen, + char *username, int unmaxlen, + char *password, int pwmaxlen) +//========================================================================== +{ + G_TheSlave->auth_smbc_get_data(server, share, + workgroup,wgmaxlen, + username, unmaxlen, + password, pwmaxlen); +} + +//-------------------------------------------------------------------------- +void SMBSlave::auth_smbc_get_data(const char *server,const char *share, + char *workgroup, int wgmaxlen, + char *username, int unmaxlen, + char *password, int pwmaxlen) +//-------------------------------------------------------------------------- +{ + //check this to see if we "really" need to authenticate... + SMBUrlType t = m_current_url.getType(); + if( t == SMBURLTYPE_ENTIRE_NETWORK ) + { + kdDebug(KIO_SMB) << "we don't really need to authenticate for this top level url, returning" << endl; + return; + } + kdDebug(KIO_SMB) << "AAAAAAAAAAAAAA auth_smbc_get_dat: set user=" << username << ", workgroup=" << workgroup + << " server=" << server << ", share=" << share << endl; + + TQString s_server = TQString::fromUtf8(server); + TQString s_share = TQString::fromUtf8(share); + workgroup[wgmaxlen - 1] = 0; + TQString s_workgroup = TQString::fromUtf8(workgroup); + username[unmaxlen - 1] = 0; + TQString s_username = TQString::fromUtf8(username); + password[pwmaxlen - 1] = 0; + TQString s_password = TQString::fromUtf8(password); + + TDEIO::AuthInfo info; + info.url = KURL("smb:///"); + info.url.setHost(s_server); + info.url.setPath("/" + s_share); + + info.username = s_username; + info.password = s_password; + info.verifyPath = true; + + kdDebug(KIO_SMB) << "libsmb-auth-callback URL:" << info.url << endl; + + if ( !checkCachedAuthentication( info ) ) + { + if ( m_default_user.isEmpty() ) + { + // ok, we do not know the password. Let's try anonymous before we try for real + info.username = "anonymous"; + info.password = TQString::null; + } + else + { + // user defined a default username/password in kcontrol; try this + info.username = m_default_user; + info.password = m_default_password; + } + + } else + kdDebug(KIO_SMB) << "got password through cache" << endl; + + strncpy(username, info.username.utf8(), unmaxlen - 1); + strncpy(password, info.password.utf8(), pwmaxlen - 1); +} + +bool SMBSlave::checkPassword(SMBUrl &url) +{ + kdDebug(KIO_SMB) << "checkPassword for " << url << endl; + + TDEIO::AuthInfo info; + info.url = KURL("smb:///"); + info.url.setHost(url.host()); + + TQString share = url.path(); + int index = share.find('/', 1); + if (index > 1) + share = share.left(index); + if (share.at(0) == '/') + share = share.mid(1); + info.url.setPath("/" + share); + info.verifyPath = true; + + if ( share.isEmpty() ) + info.prompt = i18n( + "Please enter authentication information for %1" ) + .arg( url.host() ); + else + info.prompt = i18n( + "Please enter authentication information for:\n" + "Server = %1\n" + "Share = %2" ) + .arg( url.host() ) + .arg( share ); + + info.username = url.user(); + kdDebug(KIO_SMB) << "call openPassDlg for " << info.url << endl; + + if ( openPassDlg(info) ) { + kdDebug(KIO_SMB) << "openPassDlg returned " << info.username << endl; + url.setUser(info.username); + url.setPass(info.password); + return true; + } + kdDebug(KIO_SMB) << "no value from openPassDlg\n"; + return false; +} + +//-------------------------------------------------------------------------- +// Initalizes the smbclient library +// +// Returns: 0 on success -1 with errno set on error +bool SMBSlave::auth_initialize_smbc() +{ + SMBCCTX *smb_context = NULL; + + kdDebug(KIO_SMB) << "auth_initialize_smbc " << endl; + if(m_initialized_smbc == false) + { + kdDebug(KIO_SMB) << "smbc_init call" << endl; + KSimpleConfig cfg( "tdeioslaverc", true ); + + cfg.setGroup( "SMB" ); + int debug_level = cfg.readNumEntry( "DebugLevel", 0 ); + +#if 0 + /* old API initialisation routine does not allow to set flags */ + + if(smbc_init(::auth_smbc_get_data,debug_level) == -1) + { + SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to initialize")); + return false; + } +#endif + smb_context = smbc_new_context(); + if (smb_context == NULL) { + SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to create context")); + return false; + } + + smb_context->debug = debug_level; + smb_context->callbacks.auth_fn = ::auth_smbc_get_data; + + if (!smbc_init_context(smb_context)) { + smbc_free_context(smb_context, false); + smb_context = NULL; + SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to initialize context")); + return false; + } + +#if defined(SMB_CTX_FLAG_USE_KERBEROS) && defined(SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS) + smb_context->flags |= SMB_CTX_FLAG_USE_KERBEROS | SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS; +#endif + + smbc_set_context(smb_context); + + m_initialized_smbc = true; + } + + return true; +} + diff --git a/tdeioslave/smb/tdeio_smb_browse.cpp b/tdeioslave/smb/tdeio_smb_browse.cpp new file mode 100644 index 000000000..e06bb81d1 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb_browse.cpp @@ -0,0 +1,476 @@ + +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: tdeio_smb_browse.cpp +// +// Abstract: member function implementations for SMBSlave that deal with +// SMB browsing +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +#include + +#include + +#include "tdeio_smb.h" +#include "tdeio_smb_internal.h" + +using namespace TDEIO; + +int SMBSlave::cache_stat(const SMBUrl &url, struct stat* st ) +{ + int result = smbc_stat( url.toSmbcUrl(), st); + kdDebug(KIO_SMB) << "smbc_stat " << url << " " << errno << " " << result << endl; + kdDebug(KIO_SMB) << "size " << (TDEIO::filesize_t)st->st_size << endl; + return result; +} + +//--------------------------------------------------------------------------- +bool SMBSlave::browse_stat_path(const SMBUrl& _url, UDSEntry& udsentry, bool ignore_errors) + // Returns: true on success, false on failure +{ + UDSAtom udsatom; + + SMBUrl url = _url; + + if(cache_stat(url, &st) == 0) + { + if(!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) + { + kdDebug(KIO_SMB)<<"SMBSlave::browse_stat_path mode: "<pw_name; + else + udsatom.m_str = TQString::number( uid ); + udsentry.append(udsatom); + + udsatom.m_uds = TDEIO::UDS_GROUP; + gid_t gid = st.st_gid; + struct group *grp = getgrgid( gid ); + if ( grp ) + udsatom.m_str = grp->gr_name; + else + udsatom.m_str = TQString::number( gid ); + udsentry.append(udsatom); + + udsatom.m_uds = TDEIO::UDS_ACCESS; + udsatom.m_long = st.st_mode & 07777; + udsentry.append(udsatom); + + udsatom.m_uds = UDS_MODIFICATION_TIME; + udsatom.m_long = st.st_mtime; + udsentry.append(udsatom); + + udsatom.m_uds = UDS_ACCESS_TIME; + udsatom.m_long = st.st_atime; + udsentry.append(udsatom); + + udsatom.m_uds = UDS_CREATION_TIME; + udsatom.m_long = st.st_ctime; + udsentry.append(udsatom); + + } + else + { + if (!ignore_errors) { + if (errno == EPERM || errno == EACCES) + if (checkPassword(url)) { + redirection( url ); + return false; + } + + reportError(url); + } else if (errno == ENOENT || errno == ENOTDIR) { + warning(i18n("File does not exist: %1").arg(url.url())); + } + kdDebug(KIO_SMB) << "SMBSlave::browse_stat_path ERROR!!"<< endl; + return false; + } + + return true; +} + +//=========================================================================== +void SMBSlave::stat( const KURL& kurl ) +{ + kdDebug(KIO_SMB) << "SMBSlave::stat on "<< kurl << endl; + // make a valid URL + KURL url = checkURL(kurl); + + // if URL is not valid we have to redirect to correct URL + if (url != kurl) + { + kdDebug() << "redirection " << url << endl; + redirection(url); + finished(); + return; + } + + m_current_url = url; + + UDSAtom udsatom; + UDSEntry udsentry; + // Set name + udsatom.m_uds = TDEIO::UDS_NAME; + udsatom.m_str = kurl.fileName(); + udsentry.append( udsatom ); + + switch(m_current_url.getType()) + { + case SMBURLTYPE_UNKNOWN: + error(ERR_MALFORMED_URL,m_current_url.prettyURL()); + finished(); + return; + + case SMBURLTYPE_ENTIRE_NETWORK: + case SMBURLTYPE_WORKGROUP_OR_SERVER: + udsatom.m_uds = TDEIO::UDS_FILE_TYPE; + udsatom.m_long = S_IFDIR; + udsentry.append(udsatom); + break; + + case SMBURLTYPE_SHARE_OR_PATH: + if (browse_stat_path(m_current_url, udsentry, false)) + break; + else { + kdDebug(KIO_SMB) << "SMBSlave::stat ERROR!!"<< endl; + finished(); + return; + } + default: + kdDebug(KIO_SMB) << "SMBSlave::stat UNKNOWN " << url << endl; + finished(); + return; + } + + statEntry(udsentry); + finished(); +} + +//=========================================================================== +// TODO: complete checking +KURL SMBSlave::checkURL(const KURL& kurl) const +{ + kdDebug(KIO_SMB) << "checkURL " << kurl << endl; + TQString surl = kurl.url(); + if (surl.startsWith("smb:/")) { + if (surl.length() == 5) // just the above + return kurl; // unchanged + + if (surl.at(5) != '/') { + surl = "smb://" + surl.mid(5); + kdDebug(KIO_SMB) << "checkURL return1 " << surl << " " << KURL(surl) << endl; + return KURL(surl); + } + } + + // smb:/ normaly have no userinfo + // we must redirect ourself to remove the username and password + if (surl.contains('@') && !surl.contains("smb://")) { + KURL url(kurl); + url.setPath("/"+kurl.url().right( kurl.url().length()-kurl.url().find('@') -1)); + TQString userinfo = kurl.url().mid(5, kurl.url().find('@')-5); + if(userinfo.contains(':')) { + url.setUser(userinfo.left(userinfo.find(':'))); + url.setPass(userinfo.right(userinfo.length()-userinfo.find(':')-1)); + } else { + url.setUser(userinfo); + } + kdDebug(KIO_SMB) << "checkURL return2 " << url << endl; + return url; + } + + // no emtpy path + KURL url(kurl); + + if (url.path().isEmpty()) + url.setPath("/"); + + kdDebug(KIO_SMB) << "checkURL return3 " << url << endl; + return url; +} + +void SMBSlave::reportError(const SMBUrl &url) +{ + kdDebug(KIO_SMB) << "reportError " << url << " " << perror << endl; + switch(errno) + { + case ENOENT: + if (url.getType() == SMBURLTYPE_ENTIRE_NETWORK) + error( ERR_SLAVE_DEFINED, i18n("Unable to find any workgroups in your local network. This might be caused by an enabled firewall.")); + else + error( ERR_DOES_NOT_EXIST, url.prettyURL()); + break; +#ifdef ENOMEDIUM + case ENOMEDIUM: + error( ERR_SLAVE_DEFINED, + i18n( "No media in device for %1" ).arg( url.prettyURL() ) ); + break; +#endif +#ifdef EHOSTDOWN + case EHOSTDOWN: +#endif + case ECONNREFUSED: + error( ERR_SLAVE_DEFINED, + i18n( "Could not connect to host for %1" ).arg( url.prettyURL() ) ); + break; + case ENOTDIR: + error( ERR_CANNOT_ENTER_DIRECTORY, url.prettyURL()); + break; + case EFAULT: + case EINVAL: + error( ERR_DOES_NOT_EXIST, url.prettyURL()); + break; + case EPERM: + case EACCES: + error( ERR_ACCESS_DENIED, url.prettyURL() ); + break; + case EIO: + case ENETUNREACH: + if ( url.getType() == SMBURLTYPE_ENTIRE_NETWORK || url.getType() == SMBURLTYPE_WORKGROUP_OR_SERVER ) + error( ERR_SLAVE_DEFINED, i18n( "Error while connecting to server responsible for %1" ).arg( url.prettyURL() ) ); + else + error( ERR_CONNECTION_BROKEN, url.prettyURL()); + break; + case ENOMEM: + error( ERR_OUT_OF_MEMORY, url.prettyURL() ); + break; + case ENODEV: + error( ERR_SLAVE_DEFINED, i18n("Share could not be found on given server")); + break; + case EBADF: + error( ERR_INTERNAL, i18n("BAD File descriptor")); + break; + case ETIMEDOUT: + error( ERR_SERVER_TIMEOUT, url.host() ); + break; +#ifdef ENOTUNIQ + case ENOTUNIQ: + error( ERR_SLAVE_DEFINED, i18n( "The given name could not be resolved to a unique server. " + "Make sure your network is setup without any name conflicts " + "between names used by Windows and by UNIX name resolution." ) ); + break; +#endif + case 0: // success + error( ERR_INTERNAL, i18n("libsmbclient reported an error, but did not specify " + "what the problem is. This might indicate a severe problem " + "with your network - but also might indicate a problem with " + "libsmbclient.\n" + "If you want to help us, please provide a tcpdump of the " + "network interface while you try to browse (be aware that " + "it might contain private data, so do not post it if you are " + "unsure about that - you can send it privately to the developers " + "if they ask for it)") ); + break; + default: + error( ERR_INTERNAL, i18n("Unknown error condition in stat: %1").arg(TQString::fromLocal8Bit( strerror(errno))) ); + } +} + +//=========================================================================== +void SMBSlave::listDir( const KURL& kurl ) +{ + kdDebug(KIO_SMB) << "SMBSlave::listDir on " << kurl << endl; + + // check (correct) URL + KURL url = checkURL(kurl); + // if URL is not valid we have to redirect to correct URL + if (url != kurl) + { + redirection(url); + finished(); + return; + } + + m_current_url = kurl; + + int dirfd; + struct smbc_dirent *dirp = NULL; + UDSEntry udsentry; + UDSAtom atom; + + dirfd = smbc_opendir( m_current_url.toSmbcUrl() ); + kdDebug(KIO_SMB) << "SMBSlave::listDir open " << m_current_url.toSmbcUrl() << " " << m_current_url.getType() << " " << dirfd << endl; + if(dirfd >= 0) + { + do { + kdDebug(KIO_SMB) << "smbc_readdir " << endl; + dirp = smbc_readdir(dirfd); + if(dirp == 0) + break; + + // Set name + atom.m_uds = TDEIO::UDS_NAME; + TQString dirpName = TQString::fromUtf8( dirp->name ); + // We cannot trust dirp->commentlen has it might be with or without the NUL character + // See KDE bug #111430 and Samba bug #3030 + TQString comment = TQString::fromUtf8( dirp->comment ); + if ( dirp->smbc_type == SMBC_SERVER || dirp->smbc_type == SMBC_WORKGROUP ) { + atom.m_str = dirpName.lower(); + atom.m_str.at( 0 ) = dirpName.at( 0 ).upper(); + if ( !comment.isEmpty() && dirp->smbc_type == SMBC_SERVER ) + atom.m_str += " (" + comment + ")"; + } else + atom.m_str = dirpName; + + kdDebug(KIO_SMB) << "dirp->name " << dirp->name << " " << dirpName << " '" << comment << "'" << " " << dirp->smbc_type << endl; + + udsentry.append( atom ); + if (atom.m_str.upper()=="IPC$" || atom.m_str=="." || atom.m_str == ".." || + atom.m_str.upper() == "ADMIN$" || atom.m_str.lower() == "printer$" || atom.m_str.lower() == "print$" ) + { +// fprintf(stderr,"----------- hide: -%s-\n",dirp->name); + // do nothing and hide the hidden shares + } + else if(dirp->smbc_type == SMBC_FILE) + { + // Set stat information + m_current_url.addPath(dirpName); + browse_stat_path(m_current_url, udsentry, true); + m_current_url.cd(".."); + + // Call base class to list entry + listEntry(udsentry, false); + } + else if(dirp->smbc_type == SMBC_DIR) + { + m_current_url.addPath(dirpName); + browse_stat_path(m_current_url, udsentry, true); + m_current_url.cd(".."); + + // Call base class to list entry + listEntry(udsentry, false); + } + else if(dirp->smbc_type == SMBC_SERVER || + dirp->smbc_type == SMBC_FILE_SHARE) + { + // Set type + atom.m_uds = TDEIO::UDS_FILE_TYPE; + atom.m_long = S_IFDIR; + udsentry.append( atom ); + + // Set permissions + atom.m_uds = TDEIO::UDS_ACCESS; + atom.m_long = (S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH); + udsentry.append(atom); + + if (dirp->smbc_type == SMBC_SERVER) { + atom.m_uds = TDEIO::UDS_URL; + // TQString workgroup = m_current_url.host().upper(); + KURL u("smb:/"); + u.setHost(dirpName); + atom.m_str = u.url(); + + // when libsmbclient knows + // atom.m_str = TQString("smb://%1?WORKGROUP=%2").arg(dirpName).arg(workgroup.upper()); + kdDebug(KIO_SMB) << "list item " << atom.m_str << endl; + udsentry.append(atom); + + atom.m_uds = TDEIO::UDS_MIME_TYPE; + atom.m_str = TQString::fromLatin1("application/x-smb-server"); + udsentry.append(atom); + } + + // Call base class to list entry + listEntry(udsentry, false); + } + else if(dirp->smbc_type == SMBC_WORKGROUP) + { + // Set type + atom.m_uds = TDEIO::UDS_FILE_TYPE; + atom.m_long = S_IFDIR; + udsentry.append( atom ); + + // Set permissions + atom.m_uds = TDEIO::UDS_ACCESS; + atom.m_long = (S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH); + udsentry.append(atom); + + atom.m_uds = TDEIO::UDS_MIME_TYPE; + atom.m_str = TQString::fromLatin1("application/x-smb-workgroup"); + udsentry.append(atom); + + atom.m_uds = TDEIO::UDS_URL; + // TQString workgroup = m_current_url.host().upper(); + KURL u("smb:/"); + u.setHost(dirpName); + atom.m_str = u.url(); + udsentry.append(atom); + + // Call base class to list entry + listEntry(udsentry, false); + } + else + { + kdDebug(KIO_SMB) << "SMBSlave::listDir SMBC_UNKNOWN :" << dirpName << endl; + // TODO: we don't handle SMBC_IPC_SHARE, SMBC_PRINTER_SHARE + // SMBC_LINK, SMBC_COMMS_SHARE + //SlaveBase::error(ERR_INTERNAL, TEXT_UNSUPPORTED_FILE_TYPE); + // continue; + } + udsentry.clear(); + } while (dirp); // checked already in the head + + // clean up + smbc_closedir(dirfd); + } + else + { + if (errno == EPERM || errno == EACCES) + if (checkPassword(m_current_url)) { + redirection( m_current_url ); + finished(); + return; + } + + reportError(m_current_url); + finished(); + return; + } + + listEntry(udsentry, true); + finished(); +} + diff --git a/tdeioslave/smb/tdeio_smb_config.cpp b/tdeioslave/smb/tdeio_smb_config.cpp new file mode 100644 index 000000000..f2f1ce562 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb_config.cpp @@ -0,0 +1,66 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: tdeio_smb_config.cpp +// +// Abstract: member function implementations for SMBSlave that deal with +// KDE/SMB slave configuration +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#include "tdeio_smb.h" +#include "tdeio_smb_internal.h" +#include + +#include +//=========================================================================== +void SMBSlave::reparseConfiguration() +{ + TDEConfig *cfg = new TDEConfig("tdeioslaverc", true); + cfg->setGroup("Browser Settings/SMBro"); + m_default_user=cfg->readEntry("User"); +// m_default_workgroup=cfg->readEntry("Workgroup"); +// m_showHiddenShares=cfg->readBoolEntry("ShowHiddenShares",false); + + TQString m_encoding = TQTextCodec::codecForLocale()->name(); + m_default_encoding = cfg->readEntry( "Encoding", m_encoding.lower() ); + + // unscramble, taken from Nicola Brodu's smb ioslave + //not really secure, but better than storing the plain password + TQString scrambled = cfg->readEntry( "Password" ); + m_default_password = ""; + for (uint i=0; i +// +////--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#include "tdeio_smb.h" +#include "tdeio_smb_internal.h" + + +//=========================================================================== +// TODO: add when libsmbclient supports it +void SMBSlave::copy( const KURL& ksrc, + const KURL& kdst, + int permissions, + bool overwrite) +{ + + SMBUrl src; + SMBUrl dst; + mode_t initialmode; + int n; + int dstflags; + int srcfd = -1; + int dstfd = -1; + TDEIO::filesize_t processed_size = 0; + unsigned char buf[MAX_XFER_BUF_SIZE]; + + kdDebug(KIO_SMB) << "SMBSlave::copy with src = " << ksrc << "and dest = " << kdst << endl; + + // setup urls + src = ksrc; + dst = kdst; + + // Obtain information about source + if(cache_stat(src, &st ) == -1) + { + if ( errno == EACCES ) + { + error( TDEIO::ERR_ACCESS_DENIED, src.prettyURL()); + } + else + { + error( TDEIO::ERR_DOES_NOT_EXIST, src.prettyURL()); + } + return; + } + if ( S_ISDIR( st.st_mode ) ) + { + error( TDEIO::ERR_IS_DIRECTORY, src.prettyURL() ); + return; + } + totalSize(st.st_size); + + // Check to se if the destination exists + if(cache_stat(dst, &st) != -1) + { + if(S_ISDIR(st.st_mode)) + { + error( TDEIO::ERR_DIR_ALREADY_EXIST, dst.prettyURL()); + return; + } + if(!overwrite) + { + error( TDEIO::ERR_FILE_ALREADY_EXIST, dst.prettyURL()); + return; + } + } + + // Open the source file + srcfd = smbc_open(src.toSmbcUrl(), O_RDONLY, 0); + if(srcfd < 0) + { + if(errno == EACCES) + { + error( TDEIO::ERR_ACCESS_DENIED, src.prettyURL() ); + } + else + { + error( TDEIO::ERR_DOES_NOT_EXIST, src.prettyURL() ); + } + return; + } + + // Determine initial creation mode + if(permissions != -1) + { + initialmode = permissions | S_IWUSR; + } + else + { + initialmode = 0 | S_IWUSR;//0666; + } + + + // Open the destination file + dstflags = O_CREAT | O_TRUNC | O_WRONLY; + if(!overwrite) + { + dstflags |= O_EXCL; + } + dstfd = smbc_open(dst.toSmbcUrl(), dstflags, initialmode); + if(dstfd < 0) + { + if(errno == EACCES) + { + error(TDEIO::ERR_WRITE_ACCESS_DENIED, dst.prettyURL()); + } + else + { + error(TDEIO::ERR_CANNOT_OPEN_FOR_READING, dst.prettyURL()); + } + if(srcfd >= 0 ) + { + smbc_close(srcfd); + } + return; + } + + + // Perform copy + while(1) + { + n = smbc_read(srcfd, buf, MAX_XFER_BUF_SIZE ); + if(n > 0) + { + n = smbc_write(dstfd, buf, n); + if(n == -1) + { + kdDebug(KIO_SMB) << "SMBSlave::copy copy now TDEIO::ERR_COULD_NOT_WRITE" << endl; + error( TDEIO::ERR_COULD_NOT_WRITE, dst.prettyURL()); + break; + } + + processed_size += n; + processedSize(processed_size); + } + else if(n == 0) + { + break; // finished + } + else + { + error( TDEIO::ERR_COULD_NOT_READ, src.prettyURL()); + break; + } + } + + + // FINISHED: + + if(srcfd >= 0 ) + { + smbc_close(srcfd); + } + + if(dstfd >= 0) + { + if(smbc_close(dstfd) == 0) + { + + // TODO: set final permissions + } + else + { + error( TDEIO::ERR_COULD_NOT_WRITE, dst.prettyURL()); + return; + } + } + + finished(); +} + +//=========================================================================== +void SMBSlave::del( const KURL &kurl, bool isfile) +{ + kdDebug(KIO_SMB) << "SMBSlave::del on " << kurl << endl; + m_current_url = kurl; + + if(isfile) + { + // Delete file + kdDebug(KIO_SMB) << "SMBSlave:: unlink " << kurl << endl; + if(smbc_unlink(m_current_url.toSmbcUrl()) == -1) + { + switch(errno) + { + case EISDIR: + error( TDEIO::ERR_IS_DIRECTORY, m_current_url.prettyURL()); + break; + default: + reportError(kurl); + } + } + } + else + { + kdDebug(KIO_SMB) << "SMBSlave:: rmdir " << kurl << endl; + // Delete directory + if(smbc_rmdir(m_current_url.toSmbcUrl()) == -1) + { + reportError(kurl); + } + } + + finished(); +} + +//=========================================================================== +void SMBSlave::mkdir( const KURL &kurl, int permissions ) +{ + kdDebug(KIO_SMB) << "SMBSlave::mkdir on " << kurl << endl; + m_current_url = kurl; + + if(smbc_mkdir(m_current_url.toSmbcUrl(), 0777) != 0) + { + if (errno == EEXIST) { + if(cache_stat(m_current_url, &st ) == 0) + { + if(S_ISDIR(st.st_mode )) + { + error( TDEIO::ERR_DIR_ALREADY_EXIST, m_current_url.prettyURL()); + } + } + else + { + error( TDEIO::ERR_FILE_ALREADY_EXIST, m_current_url.prettyURL()); + } + } else + reportError(kurl); + kdDebug(KIO_SMB) << "SMBSlave::mkdir exit with error " << kurl << endl; + } + else + { + if(permissions != -1) + { + // TODO enable the following when complete + //smbc_chmod( url.toSmbcUrl(), permissions ); + } + } + + finished(); +} + + +//=========================================================================== +void SMBSlave::rename( const KURL& ksrc, const KURL& kdest, bool overwrite ) +{ + + SMBUrl src; + SMBUrl dst; + + kdDebug(KIO_SMB) << "SMBSlave::rename, old name = " << ksrc << ", new name = " << kdest << endl; + + src = ksrc; + dst = kdest; + + // Check to se if the destination exists + + kdDebug(KIO_SMB) << "SMBSlave::rename stat dst" << endl; + if(cache_stat(dst, &st) != -1) + { + if(S_ISDIR(st.st_mode)) + { + kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_DIR_ALREADY_EXIST" << endl; + error( TDEIO::ERR_DIR_ALREADY_EXIST, dst.prettyURL()); + finished(); + return; + } + if(!overwrite) + { + kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_FILE_ALREADY_EXIST" << endl; + error( TDEIO::ERR_FILE_ALREADY_EXIST, dst.prettyURL()); + finished(); + return; + } + } + kdDebug(KIO_SMB ) << "smbc_rename " << src.toSmbcUrl() << " " << dst.toSmbcUrl() << endl; + if(smbc_rename(src.toSmbcUrl(), dst.toSmbcUrl())!=0) + { + kdDebug(KIO_SMB ) << "failed " << perror << endl; + switch(errno) + { + case ENOENT: + if(cache_stat(src, &st) == -1) + { + if(errno == EACCES) + { + kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_ACCESS_DENIED" << endl; + error(TDEIO::ERR_ACCESS_DENIED, src.prettyURL()); + } + else + { + kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_DOES_NOT_EXIST" << endl; + error(TDEIO::ERR_DOES_NOT_EXIST, src.prettyURL()); + } + } + break; + + case EACCES: + case EPERM: + kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_ACCESS_DENIED" << endl; + error( TDEIO::ERR_ACCESS_DENIED, dst.prettyURL() ); + break; + + default: + kdDebug(KIO_SMB) << "SMBSlave::rename TDEIO::ERR_CANNOT_RENAME" << endl; + error( TDEIO::ERR_CANNOT_RENAME, src.prettyURL() ); + + } + + kdDebug(KIO_SMB) << "SMBSlave::rename exit with error" << endl; + return; + } + + kdDebug(KIO_SMB ) << "everything fine\n"; + finished(); +} + + diff --git a/tdeioslave/smb/tdeio_smb_file.cpp b/tdeioslave/smb/tdeio_smb_file.cpp new file mode 100644 index 000000000..a6c010526 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb_file.cpp @@ -0,0 +1,279 @@ +//////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: tdeio_smb_file.cpp +// +// Abstract: member function implementations for SMBSlave that deal with +// SMB file access +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + + +#include "tdeio_smb.h" +#include "tdeio_smb_internal.h" + +#include + +//=========================================================================== +void SMBSlave::get( const KURL& kurl ) +{ + char buf[MAX_XFER_BUF_SIZE]; + int filefd = 0; + ssize_t bytesread = 0; + // time_t curtime = 0; + time_t lasttime = 0; + time_t starttime = 0; + TDEIO::filesize_t totalbytesread = 0; + TQByteArray filedata; + SMBUrl url; + + kdDebug(KIO_SMB) << "SMBSlave::get on " << kurl << endl; + + // check (correct) URL + KURL kvurl = checkURL(kurl); + // if URL is not valid we have to redirect to correct URL + if (kvurl != kurl) { + redirection(kvurl); + finished(); + return; + } + + if(!auth_initialize_smbc()) + return; + + + // Stat + url = kurl; + if(cache_stat(url,&st) == -1 ) + { + if ( errno == EACCES ) + error( TDEIO::ERR_ACCESS_DENIED, url.prettyURL()); + else + error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL()); + return; + } + if ( S_ISDIR( st.st_mode ) ) { + error( TDEIO::ERR_IS_DIRECTORY, url.prettyURL()); + return; + } + + // Set the total size + totalSize( st.st_size ); + + // Open and read the file + filefd = smbc_open(url.toSmbcUrl(),O_RDONLY,0); + if(filefd >= 0) + { + if(buf) + { + bool isFirstPacket = true; + lasttime = starttime = time(NULL); + while(1) + { + bytesread = smbc_read(filefd, buf, MAX_XFER_BUF_SIZE); + if(bytesread == 0) + { + // All done reading + break; + } + else if(bytesread < 0) + { + error( TDEIO::ERR_COULD_NOT_READ, url.prettyURL()); + return; + } + + filedata.setRawData(buf,bytesread); + if (isFirstPacket) + { + // We need a KMimeType::findByNameAndContent(filename,data) + // For now we do: find by extension, and if not found (or extension not reliable) + // then find by content. + bool accurate = false; + KMimeType::Ptr mime = KMimeType::findByURL( kurl, st.st_mode, false, true, &accurate ); + if ( !mime || mime->name() == KMimeType::defaultMimeType() + || !accurate ) + { + KMimeType::Ptr p_mimeType = KMimeType::findByContent(filedata); + if ( p_mimeType && p_mimeType->name() != KMimeType::defaultMimeType() ) + mime = p_mimeType; + } + mimeType(mime->name()); + isFirstPacket = false; + } + data( filedata ); + filedata.resetRawData(buf,bytesread); + + // increment total bytes read + totalbytesread += bytesread; + + processedSize(totalbytesread); + } + } + + smbc_close(filefd); + data( TQByteArray() ); + processedSize(static_cast(st.st_size)); + + } + else + { + error( TDEIO::ERR_CANNOT_OPEN_FOR_READING, url.prettyURL()); + return; + } + + finished(); +} + + +//=========================================================================== +void SMBSlave::put( const KURL& kurl, + int permissions, + bool overwrite, + bool resume ) +{ + + void *buf; + size_t bufsize; + + m_current_url = kurl; + + int filefd; + bool exists; + mode_t mode; + TQByteArray filedata; + + kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl << endl; + + + exists = (cache_stat(m_current_url, &st) != -1 ); + if ( exists && !overwrite && !resume) + { + if (S_ISDIR(st.st_mode)) + { + kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl <<" already isdir !!"<< endl; + error( TDEIO::ERR_DIR_ALREADY_EXIST, m_current_url.prettyURL()); + } + else + { + kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl <<" already exist !!"<< endl; + error( TDEIO::ERR_FILE_ALREADY_EXIST, m_current_url.prettyURL()); + } + return; + } + + if (exists && !resume && overwrite) + { + kdDebug(KIO_SMB) << "SMBSlave::put exists try to remove " << m_current_url.toSmbcUrl()<< endl; + // remove(m_current_url.url().local8Bit()); + } + + + if (resume) + { + // append if resuming + kdDebug(KIO_SMB) << "SMBSlave::put resume " << m_current_url.toSmbcUrl()<< endl; + filefd = smbc_open(m_current_url.toSmbcUrl(), O_RDWR, 0 ); + smbc_lseek(filefd, 0, SEEK_END); + } + else + { + if (permissions != -1) + { + mode = permissions | S_IWUSR | S_IRUSR; + } + else + { + mode = 600;//0666; + } + + kdDebug(KIO_SMB) << "SMBSlave::put NO resume " << m_current_url.toSmbcUrl()<< endl; + filefd = smbc_open(m_current_url.toSmbcUrl(), O_CREAT | O_TRUNC | O_WRONLY, mode); + } + + if ( filefd < 0 ) + { + if ( errno == EACCES ) + { + kdDebug(KIO_SMB) << "SMBSlave::put error " << kurl <<" access denied !!"<< endl; + error( TDEIO::ERR_WRITE_ACCESS_DENIED, m_current_url.prettyURL()); + } + else + { + kdDebug(KIO_SMB) << "SMBSlave::put error " << kurl <<" can not open for writing !!"<< endl; + error( TDEIO::ERR_CANNOT_OPEN_FOR_WRITING, m_current_url.prettyURL()); + } + finished(); + return; + } + + // Loop until we got 0 (end of data) + while(1) + { + kdDebug(KIO_SMB) << "SMBSlave::put request data "<< endl; + dataReq(); // Request for data + kdDebug(KIO_SMB) << "SMBSlave::put write " << m_current_url.toSmbcUrl()<< endl; + + if (readData(filedata) <= 0) + { + kdDebug(KIO_SMB) << "readData <= 0" << endl; + break; + } + kdDebug(KIO_SMB) << "SMBSlave::put write " << m_current_url.toSmbcUrl()<< endl; + buf = filedata.data(); + bufsize = filedata.size(); + int size = smbc_write(filefd, buf, bufsize); + if ( size < 0) + { + kdDebug(KIO_SMB) << "SMBSlave::put error " << kurl <<" could not write !!"<< endl; + error( TDEIO::ERR_COULD_NOT_WRITE, m_current_url.prettyURL()); + finished(); + return; + } + kdDebug(KIO_SMB ) << "wrote " << size << endl; + } + kdDebug(KIO_SMB) << "SMBSlave::put close " << m_current_url.toSmbcUrl()<< endl; + + if(smbc_close(filefd)) + { + kdDebug(KIO_SMB) << "SMBSlave::put on " << kurl <<" could not write !!"<< endl; + error( TDEIO::ERR_COULD_NOT_WRITE, m_current_url.prettyURL()); + finished(); + return; + } + + // set final permissions, if the file was just created + if ( permissions != -1 && !exists ) + { + // TODO: did the smbc_chmod fail? + // TODO: put in call to chmod when it is working! + // smbc_chmod(url.toSmbcUrl(),permissions); + } + + // We have done our job => finish + finished(); +} + + + + diff --git a/tdeioslave/smb/tdeio_smb_internal.cpp b/tdeioslave/smb/tdeio_smb_internal.cpp new file mode 100644 index 000000000..de3f98127 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb_internal.cpp @@ -0,0 +1,135 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: tdeio_smb_internal.cpp +// +// Abstract: Utility class implementation used by SMBSlave +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#include "tdeio_smb.h" +#include "tdeio_smb_internal.h" + +#include + +#include +#include + + +//=========================================================================== +// SMBUrl Function Implementation +//=========================================================================== + +//----------------------------------------------------------------------- +SMBUrl::SMBUrl() +{ + m_type = SMBURLTYPE_UNKNOWN; +} + +//----------------------------------------------------------------------- +SMBUrl::SMBUrl(const KURL& kurl) + : KURL(kurl) + //----------------------------------------------------------------------- +{ + updateCache(); +} + + +//----------------------------------------------------------------------- +void SMBUrl::addPath(const TQString &filedir) +{ + KURL::addPath(filedir); + updateCache(); +} + +//----------------------------------------------------------------------- +bool SMBUrl::cd(const TQString &filedir) +{ + if (!KURL::cd(filedir)) + return false; + updateCache(); + return true; +} + +//----------------------------------------------------------------------- +void SMBUrl::updateCache() + //----------------------------------------------------------------------- +{ + cleanPath(); + + // SMB URLs are UTF-8 encoded + kdDebug(KIO_SMB) << "updateCache " << KURL::path() << endl; + if (KURL::url() == "smb:/") + m_surl = "smb://"; + else { + TQString surl = "smb://"; + if (KURL::hasUser()) { + surl += KURL::encode_string(KURL::user(), 106); + if (KURL::hasPass()) { + surl += ":" + KURL::encode_string(KURL::pass(), 106); + } + surl += "@"; + } + surl += KURL::encode_string(KURL::host().upper(), 106); + surl += KURL::encode_string(KURL::path(), 106); + m_surl = surl.utf8(); + } + m_type = SMBURLTYPE_UNKNOWN; + // update m_type + (void)getType(); +} + +//----------------------------------------------------------------------- +SMBUrlType SMBUrl::getType() const + // Returns the type of this SMBUrl: + // SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url. + // SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network + // SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver" + // SMBURLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir" + //----------------------------------------------------------------------- +{ + if(m_type != SMBURLTYPE_UNKNOWN) + return m_type; + + if (protocol() != "smb") + { + m_type = SMBURLTYPE_UNKNOWN; + return m_type; + } + + if (path(1) == "/") + { + if (host().isEmpty()) + m_type = SMBURLTYPE_ENTIRE_NETWORK; + else + m_type = SMBURLTYPE_WORKGROUP_OR_SERVER; + return m_type; + } + + // Check for the path if we get this far + m_type = SMBURLTYPE_SHARE_OR_PATH; + + return m_type; +} + diff --git a/tdeioslave/smb/tdeio_smb_internal.h b/tdeioslave/smb/tdeio_smb_internal.h new file mode 100644 index 000000000..3eeae43a7 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb_internal.h @@ -0,0 +1,118 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB tdeioslave for KDE2 +// +// File: tdeio_smb_internal.h +// +// Abstract: Utility classes used by SMBSlave +// +// Author(s): Matthew Peterson +// Frank Schwanz +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from http://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef KIO_SMB_INTERNAL_H_INCLUDED +#define KIO_SMB_INTERNAL_H_INCLUDED + +#include + +/** + * Types of a SMBURL : + * SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url. + * SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network + * SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver" + * URLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir" + */ +enum SMBUrlType { + SMBURLTYPE_UNKNOWN = 0, SMBURLTYPE_ENTIRE_NETWORK = 1, + SMBURLTYPE_WORKGROUP_OR_SERVER = 2, SMBURLTYPE_SHARE_OR_PATH = 3 +}; + + +//=========================================================================== +/** + * Class to handle URL's + * it can convert KURL to smbUrl + * and Handle UserInfo + * it also check the correctness of the URL + */ +class SMBUrl : public KURL +{ + + +public: + SMBUrl(); + SMBUrl(const KURL & kurl); + + /** + * Appends the specified file and dir to this SMBUrl + * "smb://server/share" --> "smb://server/share/filedir" + */ + void addPath(const TQString &filedir); + + bool cd(const TQString &dir); + + /** + * Returns the type of this SMBUrl: + * SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url. + * SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network + * SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver" + * URLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir" + */ + SMBUrlType getType() const; + + void setPass( const TQString& _txt ) { KURL::setPass(_txt); updateCache(); } + void setUser( const TQString& _txt ) { KURL::setUser(_txt); updateCache(); } + void setHost( const TQString& _txt ) { KURL::setHost(_txt); updateCache(); } + + /** + * Returns the workgroup if it given in url + */ +// TQString getWorkgroup() const; + + /** + * Returns path after workgroup + */ +// TQString getServerShareDir() const; + + /** + * Return a URL that is suitable for libsmbclient + */ + TQCString toSmbcUrl() const { return m_surl; } + +private: + /** + * Change from TQString to TQCString (MS Windows's character encoding) + */ + TQCString fromUnicode( const TQString &_str ) const; + + void updateCache(); + TQCString m_surl; + + /** + * Type of URL + * @see _SMBUrlType + */ + mutable SMBUrlType m_type; +}; + + +#endif + diff --git a/tdeioslave/smb/tdeio_smb_mount.cpp b/tdeioslave/smb/tdeio_smb_mount.cpp new file mode 100644 index 000000000..1cda7f5f4 --- /dev/null +++ b/tdeioslave/smb/tdeio_smb_mount.cpp @@ -0,0 +1,211 @@ +/* This file is part of the KDE project + + Copyright (C) 2000 Alexander Neundorf + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdeio_smb.h" +#include +#include +#include +#include +#include + +void SMBSlave::readOutput(TDEProcess *, char *buffer, int buflen) +{ + mybuf += TQString::fromLocal8Bit(buffer, buflen); +} + +void SMBSlave::readStdErr(TDEProcess *, char *buffer, int buflen) +{ + mystderr += TQString::fromLocal8Bit(buffer, buflen); +} + +void SMBSlave::special( const TQByteArray & data) +{ + kdDebug(KIO_SMB)<<"Smb::special()"<> tmp; + //mounting and umounting are both blocking, "guarded" by a SIGALARM in the future + switch (tmp) + { + case 1: + case 3: + { + TQString remotePath, mountPoint, user; + stream >> remotePath >> mountPoint; + + TQStringList sl=TQStringList::split("/",remotePath); + TQString share,host; + if (sl.count()>=2) + { + host=(*sl.at(0)).mid(2); + share=(*sl.at(1)); + kdDebug(KIO_SMB)<<"special() host -"<< host <<"- share -" << share <<"-"<> mountPoint; + + TDEProcess proc; + proc.setUseShell(true); + proc << "smbumount"; + proc << TDEProcess::quote(mountPoint); + + mybuf.truncate(0); + mystderr.truncate(0); + + connect(&proc, TQT_SIGNAL( receivedStdout(TDEProcess *, char *, int )), + TQT_SLOT(readOutput(TDEProcess *, char *, int))); + + connect(&proc, TQT_SIGNAL( receivedStderr(TDEProcess *, char *, int )), + TQT_SLOT(readStdErr(TDEProcess *, char *, int))); + + if ( !proc.start( TDEProcess::Block, TDEProcess::AllOutput ) ) + { + error(TDEIO::ERR_CANNOT_LAUNCH_PROCESS, + "smbumount"+i18n("\nMake sure that the samba package is installed properly on your system.")); + return; + } + + kdDebug(KIO_SMB) << "smbumount exit " << proc.exitStatus() << endl + << "stdout:" << mybuf << endl << "stderr:" << mystderr << endl; + + if (proc.exitStatus() != 0) + { + error(TDEIO::ERR_COULD_NOT_UNMOUNT, + i18n("Unmounting of mountpoint \"%1\" failed.\n%2") + .arg(mountPoint).arg(mybuf + "\n" + mystderr)); + return; + } + + if ( tmp == 4 ) + { + bool ok; + + TQDir dir(mountPoint); + dir.cdUp(); + ok = dir.rmdir(mountPoint); + if ( ok ) + { + TQString p=dir.path(); + dir.cdUp(); + ok = dir.rmdir(p); + } + + if ( !ok ) + { + error(TDEIO::ERR_COULD_NOT_RMDIR, mountPoint); + return; + } + } + + finished(); + } + break; + default: + break; + } + finished(); +} + +#include "tdeio_smb.moc" -- cgit v1.2.1