Commit 9d52cd9c authored by Harald Sitter's avatar Harald Sitter 🌈
Browse files

smb: enable anonymous and domain extra field in authinfo

Summary:
this causes kiod to query the password with the relevant functionality
enabled. domain additionally defaults to whatever smbc_getWorkgroup returns

BUG: 327484
FIXED-IN: 19.12.3

Test Plan:
- builds
- auth query has new functionality
- logging in still works as expected

I couldn't actually get the original problem in 327484 to appear with a samba DC I threw together, so for all I know this doesn't actually fix the bug but I have no way to test :|

Reviewers: ngraham, dfaure

Reviewed By: ngraham

Subscribers: kde-frameworks-devel, kfm-devel

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D27320
parent 718abcb6
......@@ -109,7 +109,7 @@ private:
* From Controlcenter
*/
QString m_default_user;
// QString m_default_workgroup; //currently unused, Alex <neundorf@kde.org>
QString m_default_workgroup = QStringLiteral("WORKGROUP"); // overwritten with value from smbc
QString m_default_password;
QString m_default_encoding;
......
......@@ -95,6 +95,8 @@ void SMBSlave::auth_smbc_get_data(const char *server,const char *share,
info.password = s_password;
info.verifyPath = true;
info.setExtraField("domain", s_workgroup);
qCDebug(KIO_SMB) << "libsmb-auth-callback URL:" << info.url;
if ( !checkCachedAuthentication( info ) )
......@@ -115,8 +117,21 @@ void SMBSlave::auth_smbc_get_data(const char *server,const char *share,
} else
qCDebug(KIO_SMB) << "got password through cache";
strncpy(username, info.username.toUtf8(), unmaxlen - 1);
strncpy(password, info.password.toUtf8(), pwmaxlen - 1);
// Make sure it'll be safe to cast to size_t (unsigned)
Q_ASSERT(unmaxlen > 0);
Q_ASSERT(pwmaxlen > 0);
Q_ASSERT(wgmaxlen > 0);
strncpy(username, info.username.toUtf8(), static_cast<size_t>(unmaxlen - 1));
strncpy(password, info.password.toUtf8(), static_cast<size_t>(pwmaxlen - 1));
// TODO: isEmpty guard can be removed in 20.08+
// It is only here to prevent us setting an empty work group if a user updates
// but doesn't restart so kiod5 could hold an old cache without domain
// field. In that event we'll leave the input workgroup as-is.
const QString domain = info.getExtraField("domain").toString();
if (!domain.isEmpty()) {
strncpy(workgroup, domain.toUtf8(), static_cast<size_t>(wgmaxlen - 1));
}
}
int SMBSlave::checkPassword(SMBUrl &url)
......@@ -137,6 +152,9 @@ int SMBSlave::checkPassword(SMBUrl &url)
info.verifyPath = true;
info.keepPassword = true;
info.setExtraField("anonymous", true); // arbitrary default for dialog
info.setExtraField("domain", m_default_workgroup);
if ( share.isEmpty() )
info.prompt = i18n(
"<qt>Please enter authentication information for <b>%1</b></qt>" ,
......@@ -220,6 +238,13 @@ bool SMBSlave::auth_initialize_smbc()
smbc_set_context(smb_context);
// TODO: refactor; checkPassword should query this on
// demand to not run into situations where we may have cached
// the workgroup early on and it changed since. Needs context
// being held in the slave though, which opens us up to nullptr
// problems should checkPassword be called without init first.
m_default_workgroup = smbc_getWorkgroup(smb_context);
m_initialized_smbc = true;
}
......
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