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>
26 #include <k3process.h>
28 void SMBSlave::readOutput(K3Process
*, char *buffer
, int buflen
)
30 mybuf
+= QString::fromLocal8Bit(buffer
, buflen
);
33 void SMBSlave::readStdErr(K3Process
*, char *buffer
, int buflen
)
35 mystderr
+= QString::fromLocal8Bit(buffer
, buflen
);
38 void SMBSlave::special( const QByteArray
& data
)
40 kDebug(KIO_SMB
)<<"Smb::special()";
42 QDataStream
stream(data
);
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
=remotePath
.split( "/");
59 kDebug(KIO_SMB
)<<"special() host -"<< host
<<"- share -" << share
<<"-";
62 remotePath
.replace('\\', '/'); // smbmounterplugin sends \\host/share
64 kDebug(KIO_SMB
) << "mounting: " << remotePath
.toLocal8Bit() << " to " << mountPoint
.toLocal8Bit();
67 if (!KStandardDirs::makeDir(mountPoint
)) {
68 error(KIO::ERR_COULD_NOT_MKDIR
, mountPoint
);
75 SMBUrl
smburl(KUrl("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=" + KShell::quoteArg(smburl
.user());
102 user
= smburl
.user();
104 if ( ! smburl
.pass().isEmpty() )
105 options
+= ",password=" + KShell::quoteArg(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=" + KShell::quoteArg(m_default_encoding);
112 proc
<< KShell::quoteArg(remotePath
.toLocal8Bit());
113 proc
<< KShell::quoteArg(mountPoint
.toLocal8Bit());
116 connect(&proc
, SIGNAL( receivedStdout(K3Process
*, char *, int )),
117 SLOT(readOutput(K3Process
*, char *, int)));
119 connect(&proc
, SIGNAL( receivedStderr(K3Process
*, char *, int )),
120 SLOT(readStdErr(K3Process
*, char *, int)));
122 if (!proc
.start( K3Process::Block
, K3Process::AllOutput
))
124 error(KIO::ERR_CANNOT_LAUNCH_PROCESS
,
125 "smbmount"+i18n("\nMake sure that the samba package is installed properly on your system."));
129 kDebug(KIO_SMB
) << "mount exit " << proc
.exitStatus()
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 share
, host
, user
, mybuf
+ '\n' + mystderr
));
147 stream
>> mountPoint
;
150 proc
.setUseShell(true);
152 proc
<< KShell::quoteArg(mountPoint
);
155 mystderr
.truncate(0);
157 connect(&proc
, SIGNAL( receivedStdout(K3Process
*, char *, int )),
158 SLOT(readOutput(K3Process
*, char *, int)));
160 connect(&proc
, SIGNAL( receivedStderr(K3Process
*, char *, int )),
161 SLOT(readStdErr(K3Process
*, char *, int)));
163 if ( !proc
.start( K3Process::Block
, K3Process::AllOutput
) )
165 error(KIO::ERR_CANNOT_LAUNCH_PROCESS
,
166 "smbumount"+i18n("\nMake sure that the samba package is installed properly on your system."));
170 kDebug(KIO_SMB
) << "smbumount exit " << proc
.exitStatus()
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 mountPoint
, 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"