1
/* This file is part of the KDE project
3
Copyright (C) 2000 Alexander Neundorf <neundorf@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
22
#include <kstandarddirs.h>
28
void SMBSlave::readOutput(KProcess *, char *buffer, int buflen)
30
mybuf += QString::fromLocal8Bit(buffer, buflen);
33
void SMBSlave::readStdErr(KProcess *, char *buffer, int buflen)
35
mystderr += QString::fromLocal8Bit(buffer, buflen);
38
void SMBSlave::special( const QByteArray & data)
40
kdDebug(KIO_SMB)<<"Smb::special()"<<endl;
42
QDataStream stream(data, IO_ReadOnly);
44
//mounting and umounting are both blocking, "guarded" by a SIGALARM in the future
50
QString remotePath, mountPoint, user;
51
stream >> remotePath >> mountPoint;
53
QStringList sl=QStringList::split("/",remotePath);
57
host=(*sl.at(0)).mid(2);
59
kdDebug(KIO_SMB)<<"special() host -"<< host <<"- share -" << share <<"-"<<endl;
62
remotePath.replace('\\', '/'); // smbmounterplugin sends \\host/share
64
kdDebug(KIO_SMB) << "mounting: " << remotePath.local8Bit() << " to " << mountPoint.local8Bit() << endl;
67
if (!KStandardDirs::makeDir(mountPoint)) {
68
error(KIO::ERR_COULD_NOT_MKDIR, mountPoint);
75
SMBUrl smburl("smb:///");
77
smburl.setPath("/" + share);
79
if ( !checkPassword(smburl) )
85
// using smbmount instead of "mount -t smbfs", because mount does not allow a non-root
86
// user to do a mount, but a suid smbmnt does allow this
89
proc.setUseShell(true); // to have the path to smbmnt (which is used by smbmount); see man smbmount
94
if ( smburl.user().isEmpty() )
101
options = "-o username=" + KProcess::quote(smburl.user());
102
user = smburl.user();
104
if ( ! smburl.pass().isEmpty() )
105
options += ",password=" + KProcess::quote(smburl.pass());
108
// TODO: check why the control center uses encodings with a blank char, e.g. "cp 1250"
109
//if ( ! m_default_encoding.isEmpty() )
110
//options += ",codepage=" + KProcess::quote(m_default_encoding);
112
proc << KProcess::quote(remotePath.local8Bit());
113
proc << KProcess::quote(mountPoint.local8Bit());
116
connect(&proc, SIGNAL( receivedStdout(KProcess *, char *, int )),
117
SLOT(readOutput(KProcess *, char *, int)));
119
connect(&proc, SIGNAL( receivedStderr(KProcess *, char *, int )),
120
SLOT(readStdErr(KProcess *, char *, int)));
122
if (!proc.start( KProcess::Block, KProcess::AllOutput ))
124
error(KIO::ERR_CANNOT_LAUNCH_PROCESS,
125
"smbmount"+i18n("\nMake sure that the samba package is installed properly on your system."));
129
kdDebug(KIO_SMB) << "mount exit " << proc.exitStatus() << endl
130
<< "stdout:" << mybuf << endl << "stderr:" << mystderr << endl;
132
if (proc.exitStatus() != 0)
134
error( KIO::ERR_COULD_NOT_MOUNT,
135
i18n("Mounting of share \"%1\" from host \"%2\" by user \"%3\" failed.\n%4")
136
.arg(share).arg(host).arg(user).arg(mybuf + "\n" + mystderr));
147
stream >> mountPoint;
150
proc.setUseShell(true);
152
proc << KProcess::quote(mountPoint);
155
mystderr.truncate(0);
157
connect(&proc, SIGNAL( receivedStdout(KProcess *, char *, int )),
158
SLOT(readOutput(KProcess *, char *, int)));
160
connect(&proc, SIGNAL( receivedStderr(KProcess *, char *, int )),
161
SLOT(readStdErr(KProcess *, char *, int)));
163
if ( !proc.start( KProcess::Block, KProcess::AllOutput ) )
165
error(KIO::ERR_CANNOT_LAUNCH_PROCESS,
166
"smbumount"+i18n("\nMake sure that the samba package is installed properly on your system."));
170
kdDebug(KIO_SMB) << "smbumount exit " << proc.exitStatus() << endl
171
<< "stdout:" << mybuf << endl << "stderr:" << mystderr << endl;
173
if (proc.exitStatus() != 0)
175
error(KIO::ERR_COULD_NOT_UNMOUNT,
176
i18n("Unmounting of mountpoint \"%1\" failed.\n%2")
177
.arg(mountPoint).arg(mybuf + "\n" + mystderr));
185
QDir dir(mountPoint);
187
ok = dir.rmdir(mountPoint);
190
QString p=dir.path();
197
error(KIO::ERR_COULD_NOT_RMDIR, mountPoint);
211
#include "kio_smb.moc"