Skip to content

Commit

Permalink
fix: Resolve the issue of Sudo export logs being empty
Browse files Browse the repository at this point in the history
   Resolve the issue of Sudo export logs being empty

Log: Resolve the issue of Sudo export logs being empty
Bug: https://pms.uniontech.com/bug-view-238985.html
  • Loading branch information
starhcq committed Feb 6, 2024
1 parent 88d1d48 commit 566538d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
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

0 comments on commit 566538d

Please sign in to comment.