Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/dfm-mount/private/dnetworkmounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
static constexpr char kSchemaProtocol[] { "protocol" };
static constexpr char kSchemaDomain[] { "domain" };
static constexpr char kSchemaServer[] { "server" };
static constexpr char kSchemaObject[] { "object" };

static constexpr char kLoginUser[] { "user" };
static constexpr char kLoginDomain[] { "domain" };
Expand Down Expand Up @@ -112,15 +113,17 @@
QList<QVariantMap> DNetworkMounter::loginPasswd(const QString &address)
{
QUrl u(address);
QString protocol = u.scheme();

Check warning on line 116 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'protocol' shadows outer variable

Check warning on line 116 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Local variable 'protocol' shadows outer variable
QString host = u.host();
QString share = u.path().remove("/");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): u.path().remove("/") removes every slash instead of extracting the SMB share component. For an address such as smb://server/share/subdirectory, the credential is keyed as sharesubdirectory, so it does not match the credential saved or queried for the actual share share; credentials therefore fail to auto-fill for valid SMB URLs containing a subpath, and distinct paths can be collapsed into the same key.

Triggers: When an SMB address contains a path below the share root, such as smb://server/share/subdirectory.

Suggested fix: Extract only the first non-empty path component as the share name, while preserving the rest of the URL path for mounting.


GHashTable_autoptr query = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
g_hash_table_insert(query, strdup(kSchemaServer), strdup(host.toStdString().c_str()));
g_hash_table_insert(query, strdup(kSchemaProtocol), strdup(protocol.toStdString().c_str()));
g_hash_table_insert(query, strdup(kSchemaObject), strdup(share.toStdString().c_str()));

QList<QVariantMap> passwds;
GError_autoptr err { nullptr };

Check warning on line 126 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'err' shadows outer variable

Check warning on line 126 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Local variable 'err' shadows outer variable
GList_autoptr items = secret_service_search_sync(nullptr, smbSchema(), query, SECRET_SEARCH_ALL,
nullptr, &err);

Expand Down Expand Up @@ -164,10 +167,11 @@
std::string domain = passwd.value(kSchemaDomain).toString().toStdString();

GError_autoptr err { nullptr };
std::string object = passwd.value(kSchemaObject).toString().toStdString();
g_autofree char *pwd = secret_password_lookup_sync(
smbSchema(), nullptr, &err, kSchemaServer, server.c_str(), kSchemaProtocol,
protocol.c_str(), kSchemaUser, user.c_str(), kSchemaDomain, domain.c_str(),
nullptr);
kSchemaObject, object.c_str(), nullptr);
if (err)
qDebug() << "query password failed: " << passwd << err->message;
else {
Expand All @@ -182,6 +186,7 @@
QUrl u(address);
QString protocol = u.scheme();
QString server = u.host();
QString share = u.path().remove("/");
const char *collection = info.savePasswd == NetworkMountPasswdSaveMode::kSaveBeforeLogout
? SECRET_COLLECTION_SESSION
: SECRET_COLLECTION_DEFAULT;
Expand All @@ -196,7 +201,8 @@
info.domain.toStdString().c_str(), kSchemaProtocol,
protocol.toStdString().c_str(), kSchemaServer,
server.toStdString().c_str(), kSchemaUser,
info.userName.toStdString().c_str(), nullptr);
info.userName.toStdString().c_str(), kSchemaObject,
share.toStdString().c_str(), nullptr);
if (err)
qWarning() << "save passwd failed: " << err->message;
}
Expand All @@ -211,6 +217,7 @@
sche.attributes[1] = { kSchemaDomain, SECRET_SCHEMA_ATTRIBUTE_STRING };
sche.attributes[2] = { kSchemaServer, SECRET_SCHEMA_ATTRIBUTE_STRING };
sche.attributes[3] = { kSchemaProtocol, SECRET_SCHEMA_ATTRIBUTE_STRING };
sche.attributes[4] = { kSchemaObject, SECRET_SCHEMA_ATTRIBUTE_STRING };
return &sche;
}

Expand Down
Loading