Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve the issue of Sudo export logs being empty #268

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions application/dbusmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@ bool DBusManager::isAuditAdmin()

return bIsAuditAdmin;
}

QString DBusManager::getHomePathByFreeDesktop()
{
QString homePath;
QDBusInterface interface("org.freedesktop.login1", "/org/freedesktop/login1/user/self", "org.freedesktop.login1.User", QDBusConnection::systemBus());
QString userName = qvariant_cast<QString>(interface.property("Name"));

if (!userName.isEmpty())
homePath = "/home/" + userName;

return homePath;
}
3 changes: 2 additions & 1 deletion application/dbusmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class DBusManager : public QObject
static bool isSEOpen();
// 开启等保四情况下,判断是否为审计管理员身份
static bool isAuditAdmin();

// 利用freedeskop获取当前用户家目录路径
static QString getHomePathByFreeDesktop();
signals:

public slots:
Expand Down
5 changes: 4 additions & 1 deletion application/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "utils.h"
#include "logsettings.h"
#include "dbusmanager.h"

#include <math.h>
#include <pwd.h>
Expand Down Expand Up @@ -41,7 +42,9 @@ QHash<QString, QPixmap> Utils::m_imgCacheHash;
QHash<QString, QString> Utils::m_fontNameCache;
QMap<QString, QStringList> Utils::m_mapAuditType2EventType;
int Utils::specialComType = -1;
QString Utils::homePath = QDir::homePath();
// sudo权限运行deepin-log-viewer,QDir::homePath返回的是/root
// 此种情况下,使用freedesktop dbus接口获取当前登录用户家目录,以便能正确导出日志
QString Utils::homePath = (QDir::homePath() != "/root" ? QDir::homePath() : DBusManager::getHomePathByFreeDesktop());
bool Utils::runInCmd = false;
Utils::Utils(QObject *parent)
: QObject(parent)
Expand Down
1 change: 0 additions & 1 deletion logViewerService/logviewerservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ QStringList LogViewerService::getHomePaths()
homeList.push_back(info.absoluteFilePath());
}

qInfo() << "homeList: " << homeList;
return homeList;
}

Expand Down
Loading