Commit 3e2ecf06 authored by Jonathan Marten's avatar Jonathan Marten
Browse files

nfs: Support for access as a specified user

It is insecure, but then the entire concept of this ioslave is
already insecure.
parent 5745deb0
......@@ -148,7 +148,7 @@ case 2: m_protocol = new NFSProtocolV2(this);
if (m_protocol != nullptr) // created protocol for that version
{
m_protocol->setHost(m_host); // try to make initial connection
m_protocol->setHost(m_host, m_user); // try to make initial connection
if (m_protocol->isCompatible(connectionError)) break;
}
......@@ -184,24 +184,32 @@ void NFSSlave::closeConnection()
}
}
void NFSSlave::setHost(const QString& host, quint16 /*port*/, const QString& /*user*/, const QString& /*pass*/)
void NFSSlave::setHost(const QString& host, quint16 /*port*/, const QString &user, const QString& /*pass*/)
{
qCDebug(LOG_KIO_NFS);
qCDebug(LOG_KIO_NFS) << "host" << host << "user" << user;
if (m_protocol != nullptr) {
// New host? New protocol!
if (m_host != host) {
if (m_protocol != nullptr)
{
// New host or user? New protocol!
if (host != m_host || user != m_user)
{
qCDebug(LOG_KIO_NFS) << "Deleting old protocol";
delete m_protocol;
m_protocol = nullptr;
} else {
m_protocol->setHost(host);
}
else
{
// TODO: Doing this is pointless if nothing has changed
m_protocol->setHost(host, user);
}
}
m_host = host;
m_user = user;
}
void NFSSlave::put(const QUrl& url, int _mode, KIO::JobFlags _flags)
{
qCDebug(LOG_KIO_NFS);
......@@ -824,7 +832,20 @@ KIO::Error NFSProtocol::openConnection(const QString& host, int prog, int vers,
hostName = hostName + QLatin1Char('.') + domainName;
}
client->cl_auth = authunix_create(hostName.toUtf8().data(), geteuid(), getegid(), 0, nullptr);
uid_t uid = geteuid();
if (!m_currentUser.isEmpty())
{
bool ok;
uid_t num = m_currentUser.toUInt(&ok);
if (ok) uid = num;
else
{
const struct passwd *pwd = getpwnam(m_currentUser.toLocal8Bit());
if (pwd != nullptr) uid = pwd->pw_uid;
}
}
client->cl_auth = authunix_create(hostName.toUtf8().data(), uid, getegid(), 0, nullptr);
return KIO::Error(0);
}
......@@ -1022,19 +1043,20 @@ QString NFSProtocol::statInternal(const QUrl &url)
// host name changes then the protocol will always be deleted
// and recreated. So in reality this function does nothing useful.
void NFSProtocol::setHost(const QString& host)
void NFSProtocol::setHost(const QString &host, const QString &user)
{
qCDebug(LOG_KIO_NFS) << host;
qCDebug(LOG_KIO_NFS) << "host" << host << "user" << user;
if (host.isEmpty()) // must have a host name
{
m_slave->setError(KIO::ERR_UNKNOWN_HOST, host);
return;
}
if (host == m_currentHost) return; // nothing to do if host hasn't changed
// nothing to do if no change
if (host == m_currentHost && user == m_currentUser) return;
closeConnection(); // close the existing connection
m_currentHost = host; // set the new host name
m_currentUser = user; // set the new user name
}
......
......@@ -78,9 +78,11 @@ protected:
private:
NFSProtocol* m_protocol;
// We need to cache this because the @openConnection call is responsible
// We need to cache these because the @openConnection call is responsible
// for creating the protocol, and the @setHost call might happen before that.
QString m_host;
QString m_user;
bool m_usedirplus3;
KIO::Error m_errorId;
......@@ -159,7 +161,7 @@ public:
virtual void openConnection() = 0;
virtual void closeConnection() = 0;
virtual void setHost(const QString &host);
virtual void setHost(const QString &host, const QString &user = QString());
virtual void put(const QUrl& url, int _mode, KIO::JobFlags _flags) = 0;
virtual void get(const QUrl& url) = 0;
......@@ -217,6 +219,7 @@ protected:
private:
NFSSlave* m_slave;
QString m_currentHost;
QString m_currentUser;
NFSFileHandleMap m_handleCache;
QStringList m_exportedDirs;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment