Skip to content

feat:Add authentication log support - #417

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
re2zero:auth
Nov 5, 2025
Merged

deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
re2zero:auth

Conversation

@re2zero

@re2zero re2zero commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

Implement authentication log viewing functionality to parse and display logs from /var/log/auth.log and its rotated files. Includes UI integration, filtering, export capabilities, and full feature parity with existing audit log functionality.

Log: Add authentication log support.
story:https://pms.uniontech.com/story-view-39399.html

@re2zero
re2zero force-pushed the auth branch 2 times, most recently from fb6b3c5 to fbda99f Compare November 5, 2025 08:03
Implement authentication log viewing functionality to parse and display
logs from /var/log/auth.log and its rotated files. Includes UI
integration, filtering, export capabilities, and full feature parity
with existing audit log functionality.

Log: Add authentication log support.
story: https://pms.uniontech.com/story-view-39399.html
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

这是一个关于添加认证日志(Auth Log)功能的大型代码变更。让我从几个方面分析这段代码:

  1. 语法逻辑:
  • 代码整体结构清晰,遵循了现有的日志处理模式
  • 新增的认证日志相关类和函数命名规范统一
  • 信号槽连接正确,使用了Qt::QueuedConnection确保线程安全
  1. 代码质量:
  • 添加了详细的注释说明功能
  • 使用了正则表达式进行日志解析,提高了可维护性
  • 错误处理完善,包含文件权限检查和异常处理
  • 代码复用性好,遵循了现有日志类型的处理模式
  1. 性能优化:
  • 使用线程池处理日志解析
  • 实现了批量处理机制(SINGLE_READ_CNT)
  • 支持增量加载和分页显示
  1. 安全性:
  • 使用pkexec进行权限提升
  • 添加了文件存在性和权限检查
  • 对日志内容进行了适当的过滤

改进建议:

  1. 日志解析优化:
// 建议将正则表达式编译为类的成员变量,避免重复编译
class LogAuthThread {
private:
    static const QRegularExpression authRe;  // 在cpp文件中初始化
};
  1. 内存管理:
// 在parseListToModel中使用智能指针
for (int i = 0; i < listCount; i++) {
    items.clear();
    QScopedPointer<DStandardItem> item(new DStandardItem(iList[i].dateTime));
    // ...
}
  1. 错误处理增强:
// 添加更详细的错误信息
if (!file.exists()) {
    qCWarning(logApp) << "Auth log file does not exist:" << filePath 
                      << "Error:" << file.errorString();
    emit errorOccurred(tr("Log file not found: %1").arg(filePath));
    return;
}
  1. 性能优化:
// 使用QByteArray直接处理,避免不必要的字符串转换
QByteArray logData = file.readAll();
QTextStream stream(logData);
while (!stream.atEnd()) {
    // 处理每一行
}
  1. 代码复用:
// 将通用的日志处理逻辑提取为模板函数
template<typename T>
void LogAuthThread::processLogFile(const QString& filePath, 
                                 std::function<T(const QString&)> parser) {
    // 通用处理逻辑
}
  1. 安全性增强:
// 添加日志文件完整性检查
bool verifyLogFile(const QString& filePath) {
    QFile file(filePath);
    if (!file.open(QIODevice::ReadOnly)) {
        return false;
    }
    
    // 检查文件大小
    if (file.size() > MAX_LOG_SIZE) {
        return false;
    }
    
    // 检查文件头
    QByteArray header = file.read(HEADER_SIZE);
    return isValidLogHeader(header);
}
  1. 代码组织:
// 将认证日志相关的类和方法组织到单独的头文件和源文件中
// authlog.h
class AuthLogParser {
public:
    static QList<LOG_MSG_AUTH> parse(const QString& content);
    static bool validate(const QString& line);
};

// authlog.cpp
QList<LOG_MSG_AUTH> AuthLogParser::parse(const QString& content) {
    // 实现解析逻辑
}
  1. 国际化支持:
// 确保所有用户可见的字符串都使用tr()函数
QString errorMsg = tr("Failed to read auth log: %1").arg(filePath);
  1. 测试覆盖:
// 添加单元测试
class TestAuthLog : public QObject {
    Q_OBJECT
private slots:
    void testParseAuthLog();
    void testInvalidLogFormat();
    void testLargeLogHandling();
};
  1. 文档完善:
/**
 * @brief parseAuthLog 解析认证日志文件
 * @param filePath 日志文件路径
 * @return 解析后的日志条目列表
 * 
 * 该函数支持以下格式的认证日志:
 * - 标准syslog格式
 * - 带时间戳的格式
 * - 带进程ID的格式
 * 
 * @note 该函数会自动处理日志轮转文件
 * @warning 需要root权限才能访问某些认证日志文件
 */

这些改进建议可以帮助提高代码的质量、性能和可维护性。建议在实施这些改进时保持与现有代码风格的一致性。

add DBus fallback for restricted file access in zip export.

Log: Fix auth logs can not be exported if with all.
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@re2zero

re2zero commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit fec362b into linuxdeepin:master Nov 5, 2025
16 of 18 checks passed
@re2zero
re2zero deleted the auth branch November 5, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants