kiran-session-guard/0013-fix-code-scanning-Fix-some-static-code-scanning-issu.patch
2024-04-09 17:11:59 +08:00

988 lines
39 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From a076bff281bf7d8b3a5b6dc61f82a2e2cb25d23c Mon Sep 17 00:00:00 2001
From: liuxinhao <liuxinhao@kylinsec.com.cn>
Date: Wed, 31 Jan 2024 11:46:23 +0800
Subject: [PATCH 13/16] fix(code scanning ): Fix some static code scanning
issues
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 修复一些代码静态扫描问题
---
lib/auth-proxy/auth-controller-i.h | 13 ++
lib/common-widgets/auth-type-drawer.cpp | 15 ++-
lib/common-widgets/auth-type-drawer.h | 13 ++
lib/common-widgets/auth-type-switcher.cpp | 17 ++-
...m.kylinsec.Kiran.SystemDaemon.Accounts.xml | 8 --
lib/login-frame/login-frame.cpp | 2 +-
lib/utils/keyboard-monitor.cpp | 69 ++++------
lib/utils/scaling-helper.cpp | 125 ++++++++++--------
lib/utils/virtual-keyboard.h | 4 +-
src/lightdm-greeter/common/prefs.cpp | 26 ++--
src/lightdm-greeter/frame.cpp | 6 +-
.../kiran-cpanel-greeter/main.cpp | 13 ++
.../kiran-cpanel-greeter/setting-window.cpp | 1 -
src/lightdm-greeter/term-signal-handler.cpp | 2 +-
.../widgets/disabledeselectlistwidget.cpp | 11 +-
src/lightdm-greeter/widgets/login-button.cpp | 7 +-
src/lightdm-greeter/widgets/user-info.h | 2 +
src/lightdm-greeter/widgets/user-list.cpp | 15 ++-
src/lightdm-greeter/widgets/user-list.h | 2 +-
src/polkit-agent/auth-polkit.h | 2 +-
src/polkit-agent/dialog.cpp | 2 +-
src/polkit-agent/moreinfo-button.cpp | 16 +--
src/screensaver-dialog/auth-pam.h | 2 +-
.../checkpass-common/pam-message.cpp | 4 +-
src/screensaver-dialog/frame.cpp | 10 +-
src/screensaver-dialog/prefs.cpp | 12 +-
.../session-guard-checkpass/main.cpp | 30 +++--
27 files changed, 240 insertions(+), 189 deletions(-)
diff --git a/lib/auth-proxy/auth-controller-i.h b/lib/auth-proxy/auth-controller-i.h
index 3340807..6f75241 100644
--- a/lib/auth-proxy/auth-controller-i.h
+++ b/lib/auth-proxy/auth-controller-i.h
@@ -1,3 +1,16 @@
+/**
+ * Copyright (c) 2020 ~ 2024 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
#pragma once
#include <QString>
#include "auth-define.h"
diff --git a/lib/common-widgets/auth-type-drawer.cpp b/lib/common-widgets/auth-type-drawer.cpp
index bddc5e8..57109ee 100644
--- a/lib/common-widgets/auth-type-drawer.cpp
+++ b/lib/common-widgets/auth-type-drawer.cpp
@@ -1,3 +1,16 @@
+/**
+ * Copyright (c) 2020 ~ 2024 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
#include "auth-type-drawer.h"
#include "style-palette.h"
@@ -84,7 +97,7 @@ void AuthTypeDrawer::setAuthTypes(QList<std::tuple<int, QString, QString>> authT
authButtonInfo.m_icon = icon;
m_buttonMap[authType] = authButtonInfo;
}
-
+
updateValidSizeHint();
if (m_adjustColorToTheme)
diff --git a/lib/common-widgets/auth-type-drawer.h b/lib/common-widgets/auth-type-drawer.h
index 7095773..f6edb79 100644
--- a/lib/common-widgets/auth-type-drawer.h
+++ b/lib/common-widgets/auth-type-drawer.h
@@ -1,3 +1,16 @@
+/**
+ * Copyright (c) 2020 ~ 2024 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
#pragma once
#include <QWidget>
diff --git a/lib/common-widgets/auth-type-switcher.cpp b/lib/common-widgets/auth-type-switcher.cpp
index a1a4470..37ead7d 100644
--- a/lib/common-widgets/auth-type-switcher.cpp
+++ b/lib/common-widgets/auth-type-switcher.cpp
@@ -1,3 +1,16 @@
+/**
+ * Copyright (c) 2020 ~ 2024 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
#include "auth-type-switcher.h"
#include <qt5-log-i.h>
#include <QDebug>
@@ -21,9 +34,9 @@ AuthTypeSwitcher::AuthTypeSwitcher(AuthTypeDrawerExpandDirection direction, int
m_drawer = new AuthTypeDrawer(direction, radius, parent, this);
connect(m_drawer, &AuthTypeDrawer::authTypeClicked, this, &AuthTypeSwitcher::onAuthTypeChanged);
// clang-format off
- connect(m_drawer, &AuthTypeDrawer::expandedStatusChanged, [this](bool expaned){
+ connect(m_drawer, &AuthTypeDrawer::expandedStatusChanged, [this](bool expaned){
m_isExpanded = expaned;
- update();
+ update();
});
// clang-format on
}
diff --git a/lib/dbus/com.kylinsec.Kiran.SystemDaemon.Accounts.xml b/lib/dbus/com.kylinsec.Kiran.SystemDaemon.Accounts.xml
index 2248466..f7cb8f8 100644
--- a/lib/dbus/com.kylinsec.Kiran.SystemDaemon.Accounts.xml
+++ b/lib/dbus/com.kylinsec.Kiran.SystemDaemon.Accounts.xml
@@ -65,14 +65,6 @@
</arg>
</method>
- <!--<method name="SetGlobalAuthModes">
- <arg name="auth_modes" direction="in" type="i">
- <description>Bitwise OR the enabled authorization mode.</description>
- </arg>>
- <description>Set the global enabled authentication modes. It will reset to all users using the auth_modes
- and also use the auth_modes when user is added.</description>
- </method>-->
-
<property name="rsa_public_key" type="s" access="read">
<description>The RSA public key.</description>
</property>
diff --git a/lib/login-frame/login-frame.cpp b/lib/login-frame/login-frame.cpp
index 1657296..67e54e5 100644
--- a/lib/login-frame/login-frame.cpp
+++ b/lib/login-frame/login-frame.cpp
@@ -280,8 +280,8 @@ void LoginFrame::onShowPrmpt(const QString& text, PromptType type)
ui->edit->setPlaceHolderText(text);
m_editMode = EDIT_MODE_PROMPT_RESPOSE;
ui->edit->setEchoMode(type == PromptTypeSecret ? QLineEdit::Password : QLineEdit::Normal);
- /// FIXME:需要延时设置输入焦点到输入框不然又会被置回UserItem
m_prompted = true;
+ /// NOTE:需要延时设置输入焦点到输入框不然又会被置回UserItem
setEditFocus(200);
}
diff --git a/lib/utils/keyboard-monitor.cpp b/lib/utils/keyboard-monitor.cpp
index 290d8e4..4b7e89e 100644
--- a/lib/utils/keyboard-monitor.cpp
+++ b/lib/utils/keyboard-monitor.cpp
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
namespace Kiran
{
@@ -36,61 +37,39 @@ int KeyboardMonitor::getXiMajorVersion(Display *display)
XExtensionVersion *version;
static int vers = -1;
- if (vers != -1) return vers;
-
- version = XGetExtensionVersion(display, INAME);
-
- if (version && (version != (XExtensionVersion *)NoSuchExtension))
+ if (vers != -1)
{
- vers = version->major_version;
- XFree(version);
+ return vers;
}
- /* Announce our supported version so the server treats us correctly. */
- if (vers >= XI_2_Major)
+ version = XGetExtensionVersion(display, INAME);
+ if (!version || (version == reinterpret_cast<XExtensionVersion *>(NoSuchExtension)))
{
- const char *forced_version;
- int maj = 2, min = 2;
-
- forced_version = getenv("XINPUT_XI2_VERSION");
- if (forced_version)
- {
- if (sscanf(forced_version, "%d.%d", &maj, &min) != 2)
- {
- fprintf(stderr,
- "Invalid format of XINPUT_XI2_VERSION "
- "environment variable. Need major.minor\n");
- exit(1);
- }
- printf("Overriding XI2 version to: %d.%d\n", maj, min);
- }
-
- XIQueryVersion(display, &maj, &min);
+ vers = 0;
+ return vers;
}
+ vers = version->major_version;
+ XFree(version);
return vers;
}
void KeyboardMonitor::selectEvents(Display *display)
{
- XIEventMask m;
- m.deviceid = XIAllMasterDevices;
- m.mask_len = XIMaskLen(XI_LASTEVENT);
- m.mask = (unsigned char *)calloc(m.mask_len, sizeof(char));
-
- XISetMask(m.mask, XI_RawKeyRelease);
- // XISetMask(m.mask, XI_RawKeyPress);
- // XISetMask(m.mask, XI_RawButtonPress);
- // XISetMask(m.mask, XI_RawButtonRelease);
- // XISetMask(m.mask, XI_RawMotion);
- // XISetMask(m.mask, XI_RawTouchBegin);
- // XISetMask(m.mask, XI_RawTouchUpdate);
- // XISetMask(m.mask, XI_RawTouchEnd);
-
- XISelectEvents(display, DefaultRootWindow(display), &m, 1);
-
- free(m.mask);
- XSync(display, False);
+ XIEventMask evmask;
+ unsigned char mask[XIMaskLen(XI_LASTEVENT)] = {0};
+
+ memset(&evmask, 0, sizeof(evmask));
+ memset(mask, 0, sizeof(mask));
+
+ XISetMask(mask, XI_RawKeyRelease);
+
+ evmask.deviceid = XIAllMasterDevices;
+ evmask.mask_len = sizeof(mask);
+ evmask.mask = mask;
+
+ XISelectEvents(display, DefaultRootWindow(display), &evmask, 1);
+ XFlush(display);
}
int KeyboardMonitor::listenXiEvent(Display *display)
@@ -118,7 +97,7 @@ int KeyboardMonitor::listenXiEvent(Display *display)
}
else if (sym == XKB_KEY_Num_Lock)
{
- emit numlockStatusChanged(isNumlockOn());
+ emit this->numlockStatusChanged(isNumlockOn());
}
break;
}
diff --git a/lib/utils/scaling-helper.cpp b/lib/utils/scaling-helper.cpp
index ed051d9..697744e 100644
--- a/lib/utils/scaling-helper.cpp
+++ b/lib/utils/scaling-helper.cpp
@@ -36,8 +36,14 @@ void ScalingHelper::auto_calculate_screen_scaling()
std::list<double> scaleFactors;
display = XOpenDisplay(nullptr);
- resources = XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
+ if (!display)
+ {
+ KLOG_WARNING("auto_calculate_screen_scaling failed,set QT_AUTO_SCREEN_SCALE_FACTOR=1");
+ qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
+ return;
+ }
+ resources = XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
if (!resources)
{
KLOG_WARNING("XRRGetScreenResourcesCurrent failed,try XRRGetScreenResources");
@@ -47,81 +53,86 @@ void ScalingHelper::auto_calculate_screen_scaling()
if (!resources)
{
KLOG_WARNING("get screen resources failed");
- goto failed;
+ if (display)
+ {
+ XCloseDisplay(display);
+ }
+ KLOG_WARNING("auto_calculate_screen_scaling failed,set QT_AUTO_SCREEN_SCALE_FACTOR=1");
+ qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
+ return;
}
- if (resources)
+ for (int i = 0; i < resources->noutput; i++)
{
- for (int i = 0; i < resources->noutput; i++)
+ XRROutputInfo *outputInfo = XRRGetOutputInfo(display, resources, resources->outputs[i]);
+ if (!outputInfo)
+ {
+ KLOG_WARNING("get output info %d from resources failed", i);
+ continue;
+ }
+ else if ((outputInfo->crtc == 0) || (outputInfo->mm_width == 0))
{
- XRROutputInfo *outputInfo = XRRGetOutputInfo(display, resources, resources->outputs[i]);
- if (outputInfo->crtc == 0 || outputInfo->mm_width == 0)
- {
- if (outputInfo != nullptr)
- {
- XRRFreeOutputInfo(outputInfo);
- }
- continue;
- }
- XRRCrtcInfo *crtInfo = XRRGetCrtcInfo(display, resources, outputInfo->crtc);
- if (crtInfo == nullptr)
- {
- XRRFreeOutputInfo(outputInfo);
- continue;
- }
-
- // 计算屏幕尺寸
- qreal screenInch;
- screenInch = qSqrt(qPow(outputInfo->mm_width, 2.0) + qPow(outputInfo->mm_height, 2.0)) / qreal(25.4);
-
- // 计算ppi
- qreal hypotenusePixel = qSqrt(qPow(crtInfo->width, 2.0) + qPow(crtInfo->height, 2.0));
- qreal ppi = hypotenusePixel / screenInch;
-
- KLOG_INFO() << "Screen:" << outputInfo->name;
- KLOG_INFO() << " physical size: " << outputInfo->mm_width << "x" << outputInfo->mm_height;
- KLOG_INFO() << " virtual size: " << crtInfo->width << crtInfo->height;
- KLOG_INFO() << " inch: " << screenInch;
- KLOG_INFO() << " ppi: " << ppi;
-
- double screen_scale_factor = 1.0;
- if (ppi >= 150 && ppi < 196)
- {
- screen_scale_factor = 1.5;
- }
- else if (ppi >= 196)
- {
- screen_scale_factor = 2.0;
- }
- else if (crtInfo->width >= 4096)
- {
- screen_scale_factor = 2.0;
- }
- scaleFactors.push_back(screen_scale_factor);
- XRRFreeCrtcInfo(crtInfo);
+ KLOG_WARNING("ignore crtc==0 or mm_width==0 output");
XRRFreeOutputInfo(outputInfo);
+ continue;
+ }
+
+ XRRCrtcInfo *crtInfo = XRRGetCrtcInfo(display, resources, outputInfo->crtc);
+ if (crtInfo == nullptr)
+ {
+ KLOG_WARNING("ignore crtcinfo==null output");
+ XRRFreeOutputInfo(outputInfo);
+ continue;
+ }
+
+ // 计算屏幕尺寸
+ qreal screenInch;
+ screenInch = qSqrt(qPow(outputInfo->mm_width, 2.0) + qPow(outputInfo->mm_height, 2.0)) / qreal(25.4);
+
+ // 计算ppi
+ qreal hypotenusePixel = qSqrt(qPow(crtInfo->width, 2.0) + qPow(crtInfo->height, 2.0));
+ qreal ppi = hypotenusePixel / screenInch;
+
+ KLOG_INFO() << "Screen:" << outputInfo->name;
+ KLOG_INFO() << " physical size: " << outputInfo->mm_width << "x" << outputInfo->mm_height;
+ KLOG_INFO() << " virtual size: " << crtInfo->width << crtInfo->height;
+ KLOG_INFO() << " inch: " << screenInch;
+ KLOG_INFO() << " ppi: " << ppi;
+
+ double screen_scale_factor = 1.0;
+ if (ppi >= 150 && ppi < 196)
+ {
+ screen_scale_factor = 1.5;
+ }
+ else if (ppi >= 196)
+ {
+ screen_scale_factor = 2.0;
+ }
+ else if (crtInfo->width >= 4096)
+ {
+ screen_scale_factor = 2.0;
}
- XRRFreeScreenResources(resources);
+ scaleFactors.push_back(screen_scale_factor);
+
+ XRRFreeCrtcInfo(crtInfo);
+ XRRFreeOutputInfo(outputInfo);
}
+ XRRFreeScreenResources(resources);
XCloseDisplay(display);
+
if (scaleFactors.size())
{
scaleFactors.sort();
scale_factor = *scaleFactors.begin();
}
+
KLOG_INFO() << "QT_SCALE_FACTOR:" << scale_factor;
if (!qputenv("QT_SCALE_FACTOR", QString::number(scale_factor).toUtf8()))
{
KLOG_WARNING() << "set scale factor failed.";
}
+
return;
-failed:
- if (display)
- {
- XCloseDisplay(display);
- }
- KLOG_WARNING("auto_calculate_screen_scaling failed,set QT_AUTO_SCREEN_SCALE_FACTOR=1");
- qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
}
} // namespace SessionGuard
diff --git a/lib/utils/virtual-keyboard.h b/lib/utils/virtual-keyboard.h
index 09bbc37..4670105 100644
--- a/lib/utils/virtual-keyboard.h
+++ b/lib/utils/virtual-keyboard.h
@@ -44,8 +44,8 @@ private slots:
void slotReadyReadStandardOutput();
private:
- QWidget *m_keyboardWidget;
- QProcess *m_process;
+ QWidget *m_keyboardWidget = nullptr;
+ QProcess *m_process = nullptr;
QWidget *m_keyboardEmbed = nullptr;
};
} // namespace SessionGuard
diff --git a/src/lightdm-greeter/common/prefs.cpp b/src/lightdm-greeter/common/prefs.cpp
index 91d7072..82891b4 100644
--- a/src/lightdm-greeter/common/prefs.cpp
+++ b/src/lightdm-greeter/common/prefs.cpp
@@ -51,31 +51,31 @@ void Prefs::init()
/// common
settings.beginGroup("Common");
- auto hiddenSession = settings.value("hidden-sessions");
+ auto hiddenSession = settings.value("hidden-sessions","");
m_hiddenSessions = hiddenSession.toStringList();
- auto hiddenUsers = settings.value("hide-users");
- m_hiddenUsers = hiddenUsers.toStringList();
+ auto needHideUsers = settings.value("hide-users","");
+ m_hiddenUsers = needHideUsers.toStringList();
- auto numlockInitState = settings.value("numlock-init-state");
- m_numlockInitState = numlockInitState.toBool();
+ auto numInitState = settings.value("numlock-init-state");
+ m_numlockInitState = numInitState.toBool();
settings.endGroup();
/// power
settings.beginGroup("Power");
- auto canPowerOff = settings.value("can-poweroff");
- m_canPowerOff = canPowerOff.toBool();
+ auto powerOffEnable = settings.value("can-poweroff");
+ m_canPowerOff = powerOffEnable.toBool();
- auto canReboot = settings.value("can-reboot");
- m_canReboot = canReboot.toBool();
+ auto rebootEnable = settings.value("can-reboot");
+ m_canReboot = rebootEnable.toBool();
- auto canSuspend = settings.value("can-suspend");
- m_canSuspend = canSuspend.toBool();
+ auto suspendEnable = settings.value("can-suspend");
+ m_canSuspend = suspendEnable.toBool();
- auto canHibernate = settings.value("can-hibernate");
- m_canHibernate = canHibernate.toBool();
+ auto hibernateEnable = settings.value("can-hibernate");
+ m_canHibernate = hibernateEnable.toBool();
}
Prefs::~Prefs()
diff --git a/src/lightdm-greeter/frame.cpp b/src/lightdm-greeter/frame.cpp
index 3d8dada..e4afcb9 100644
--- a/src/lightdm-greeter/frame.cpp
+++ b/src/lightdm-greeter/frame.cpp
@@ -110,7 +110,7 @@ void Frame::initMenus()
auto setMenuAttributes = [](QMenu* menu)
{
menu->setAttribute(Qt::WA_TranslucentBackground); // 透明必需
- // FIXME:QMenu不能为窗口只能为控件不然透明效果依赖于窗口管理器混成特效与显卡
+ // NOTE:QMenu不能为窗口只能为控件不然透明效果依赖于窗口管理器混成特效与显卡
// 控件的话QMenu显示出来的话不能点击其他区域隐藏窗口需要手动隐藏
menu->setWindowFlags(Qt::FramelessWindowHint | Qt::Widget); // 透明必需
menu->setContentsMargins(0, 0, 0, 0);
@@ -165,7 +165,7 @@ void Frame::initUI()
{
resize(1024, 768);
- /// FIXME:因弹出窗口不是作为新的窗口,而是作为一个控件,需要我们去做隐藏
+ /// NOTE:因弹出窗口不是作为新的窗口,而是作为一个控件,需要我们去做隐藏
/// 开始监听整个应用程序事件,在窗口点击事件中判断隐藏菜单
qApp->installEventFilter(this);
@@ -205,7 +205,7 @@ void Frame::initUI()
// 初始化添加右下控件
// 获取菜单弹出坐标,按钮和触发菜单右对齐
- // FIXME: Qt在特定虚拟机环境下QMenu::popup传入正确的pos时,QMenu通过Pos找到screen,但screen的大小错误(为调整分辨率之前的分辨率)
+ // NOTE: Qt在特定虚拟机环境下QMenu::popup传入正确的pos时,QMenu通过Pos找到screen,但screen的大小错误(为调整分辨率之前的分辨率)
// 导致popup pos被修改成在错误的屏幕范围内
auto getMenuPopupPos = [this](QMenu* menu, const QToolButton* triggerBtn) -> QPoint
{
diff --git a/src/lightdm-greeter/kiran-cpanel-greeter/main.cpp b/src/lightdm-greeter/kiran-cpanel-greeter/main.cpp
index eeffb39..96567b7 100644
--- a/src/lightdm-greeter/kiran-cpanel-greeter/main.cpp
+++ b/src/lightdm-greeter/kiran-cpanel-greeter/main.cpp
@@ -1,3 +1,16 @@
+/**
+ * Copyright (c) 2020 ~ 2024 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
#include <QApplication>
int main(int argc, char* argv[])
diff --git a/src/lightdm-greeter/kiran-cpanel-greeter/setting-window.cpp b/src/lightdm-greeter/kiran-cpanel-greeter/setting-window.cpp
index 5c3fd15..45c9fb9 100644
--- a/src/lightdm-greeter/kiran-cpanel-greeter/setting-window.cpp
+++ b/src/lightdm-greeter/kiran-cpanel-greeter/setting-window.cpp
@@ -435,7 +435,6 @@ void SettingWindow::initUserComboBox(QComboBox *combo)
iconFile.clear();
}
};
- QVector<UserInfo> userInfoVector;
QStringList users = UserManager::getCachedUsers();
users.append("root");
diff --git a/src/lightdm-greeter/term-signal-handler.cpp b/src/lightdm-greeter/term-signal-handler.cpp
index 5375d19..646c7e1 100644
--- a/src/lightdm-greeter/term-signal-handler.cpp
+++ b/src/lightdm-greeter/term-signal-handler.cpp
@@ -22,7 +22,7 @@
#include <QApplication>
#include <QSocketNotifier>
-//FIXME该种方式退出时,可能会有线程阻塞在xcb_wait_for_reply
+//TODO该种方式退出时,可能会有线程阻塞在xcb_wait_for_reply
namespace Kiran
{
namespace SessionGuard
diff --git a/src/lightdm-greeter/widgets/disabledeselectlistwidget.cpp b/src/lightdm-greeter/widgets/disabledeselectlistwidget.cpp
index c2f0190..e6a7962 100644
--- a/src/lightdm-greeter/widgets/disabledeselectlistwidget.cpp
+++ b/src/lightdm-greeter/widgets/disabledeselectlistwidget.cpp
@@ -31,24 +31,27 @@ DisableDeselectListWidget::DisableDeselectListWidget(QWidget *parent)
QItemSelectionModel::SelectionFlags
DisableDeselectListWidget::selectionCommand(const QModelIndex &index, const QEvent *event) const
{
- //FIXME:为了避免一些环境下会出现ItemFocus直接设置选中的情况
+ // NOTE:为了避免一些环境下会出现ItemFocus直接设置选中的情况
if (event == nullptr)
{
return QItemSelectionModel::NoUpdate;
}
- //禁用用户按住鼠标切换用户情况
+
+ // 禁用用户按住鼠标切换用户情况
if (event->type() == QEvent::MouseMove)
{
return QItemSelectionModel::NoUpdate;
}
- if ((event != nullptr) && (event->type() == QEvent::MouseButtonPress))
+
+ if ((event->type() == QEvent::MouseButtonPress))
{
- const QMouseEvent *mouseEvent = (QMouseEvent *)event;
+ const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event);
if ((mouseEvent->modifiers() & Qt::ControlModifier) != 0)
{
return QItemSelectionModel::NoUpdate;
}
}
+
return QListWidget::selectionCommand(index, event);
}
diff --git a/src/lightdm-greeter/widgets/login-button.cpp b/src/lightdm-greeter/widgets/login-button.cpp
index 428f18d..63f9367 100644
--- a/src/lightdm-greeter/widgets/login-button.cpp
+++ b/src/lightdm-greeter/widgets/login-button.cpp
@@ -24,9 +24,10 @@ namespace SessionGuard
{
namespace Greeter
{
-LoginButton::LoginButton(QWidget *parent) : QWidget(parent),
- ui(new Ui::LoginButton),
- m_pressed(false)
+LoginButton::LoginButton(QWidget *parent)
+ : QWidget(parent),
+ ui(new Ui::LoginButton),
+ m_pressed(false)
{
ui->setupUi(this);
ui->label_text->setText(tr("login"));
diff --git a/src/lightdm-greeter/widgets/user-info.h b/src/lightdm-greeter/widgets/user-info.h
index c7ca0d2..0aceaa8 100644
--- a/src/lightdm-greeter/widgets/user-info.h
+++ b/src/lightdm-greeter/widgets/user-info.h
@@ -24,6 +24,8 @@ namespace Greeter
{
struct UserInfo
{
+ UserInfo():uid(0),hasMessage(false),loggedIn(false)
+ {};
QString name;
QString realName;
QString session;
diff --git a/src/lightdm-greeter/widgets/user-list.cpp b/src/lightdm-greeter/widgets/user-list.cpp
index e59fa8b..1b9be4b 100644
--- a/src/lightdm-greeter/widgets/user-list.cpp
+++ b/src/lightdm-greeter/widgets/user-list.cpp
@@ -281,8 +281,9 @@ QString UserList::getIconByUserName(const QString &userName)
UserInfo UserList::getUserInfoByUserName(const QString &userName)
{
UserInfo info;
+ int rowCout = m_filterModel.rowCount(QModelIndex());
- for (int i = 0; i < m_filterModel.rowCount(QModelIndex()); i++)
+ for (int i = 0; i < rowCout; i++)
{
UserInfo userInfo;
getUserInfoFromModel(i, userInfo);
@@ -339,10 +340,10 @@ void UserList::onModelRowsRemoved(const QModelIndex &parent, int first, int last
const QString userName = item->text();
QListWidgetItem *removedItem = ui->userList->takeItem(i);
delete removedItem;
- emit userRemoved(userName);
+ emit this->userRemoved(userName);
}
int newCount = userCount();
- emit userCountChanged(oldCount, newCount);
+ emit this->userCountChanged(oldCount, newCount);
updateGeometry();
}
@@ -359,7 +360,7 @@ void UserList::onModelRowsInserted(const QModelIndex &parent, int first, int las
KLOG_DEBUG() << "row inserted: "
<< "cout[" << ui->userList->count() << "]";
updateGeometry();
- emit userCountChanged(oldCount, newCount);
+ emit this->userCountChanged(oldCount, newCount);
}
void UserList::onAppFocusChanged(QWidget *oldFocus, QWidget *newFocus)
@@ -409,10 +410,10 @@ void UserList::onDataChanged(const QModelIndex &topLeft,
break;
}
};
- int startRow = topLeft.row();
- int endRow = topLeft.row();
- // FIXME: QLightdDM此处信号发出时roles为默认参数, 无法判断数据变化范围
+ int startRow = topLeft.row();
+ int endRow = bottomRight.row();
+ // NOTE: QLightdDM此处信号发出时roles为默认参数, 无法判断数据变化范围
// 检查图片更新,用户列表中的顺序可能和用户不一致
for (int i = startRow; i <= endRow; i++)
{
diff --git a/src/lightdm-greeter/widgets/user-list.h b/src/lightdm-greeter/widgets/user-list.h
index e58b39c..32730cc 100644
--- a/src/lightdm-greeter/widgets/user-list.h
+++ b/src/lightdm-greeter/widgets/user-list.h
@@ -64,7 +64,7 @@ private slots:
void onAppFocusChanged(QWidget* oldFocus,QWidget* newFocus);
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> roles);
-Q_SIGNALS:
+signals:
void userActivated(const UserInfo &userInfo);
void userCountChanged(int oldCount, int newCount);
void userRemoved(const QString &userName);
diff --git a/src/polkit-agent/auth-polkit.h b/src/polkit-agent/auth-polkit.h
index 063a964..2b3cb91 100644
--- a/src/polkit-agent/auth-polkit.h
+++ b/src/polkit-agent/auth-polkit.h
@@ -59,7 +59,7 @@ private slots:
void handleSessionShowInfo(const QString& text);
private:
- AuthControllerInterface* m_controllerInterface;
+ AuthControllerInterface* m_controllerInterface = nullptr;
QString m_cookie;
PolkitQt1::Agent::Session* m_session = nullptr;
PolkitQt1::Identity m_identity;
diff --git a/src/polkit-agent/dialog.cpp b/src/polkit-agent/dialog.cpp
index 6094a71..460e834 100644
--- a/src/polkit-agent/dialog.cpp
+++ b/src/polkit-agent/dialog.cpp
@@ -247,7 +247,7 @@ void Dialog::onAuthComplete(bool success)
{
if (m_authController->isAuthenticated())
{
- emit completed(true);
+ emit this->completed(true);
this->close();
return;
}
diff --git a/src/polkit-agent/moreinfo-button.cpp b/src/polkit-agent/moreinfo-button.cpp
index 9415f11..babdac2 100644
--- a/src/polkit-agent/moreinfo-button.cpp
+++ b/src/polkit-agent/moreinfo-button.cpp
@@ -27,17 +27,13 @@ namespace SessionGuard
namespace PolkitAgent
{
MoreInfoButton::MoreInfoButton(QWidget* parent)
- : QWidget(parent)
+ : QWidget(parent),
+ m_expandPix(style()->standardPixmap(QStyle::SP_ArrowUp)),
+ m_shrinkPix(style()->standardPixmap(QStyle::SP_ArrowRight)),
+ m_iconSize(QSize(16, 16)),
+ m_text(QString("more info"))
{
- m_shrinkPix = style()->standardPixmap(QStyle::SP_ArrowRight);
- m_expandPix = style()->standardPixmap(QStyle::SP_ArrowUp);
-
- m_iconSize = QSize(16, 16);
-
- // m_shrinkPix = m_shrinkPix.scaled(m_iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation);
- // m_expandPix = m_expandPix.scaled(m_iconSize,Qt::KeepAspectRatio,Qt::SmoothTransformation);
-
- setText("more info");
+ setText(m_text);
}
MoreInfoButton::~MoreInfoButton()
diff --git a/src/screensaver-dialog/auth-pam.h b/src/screensaver-dialog/auth-pam.h
index 210ad6f..99e0bb5 100644
--- a/src/screensaver-dialog/auth-pam.h
+++ b/src/screensaver-dialog/auth-pam.h
@@ -60,7 +60,7 @@ private:
void handleChildExit();
private:
- AuthControllerInterface* m_interface;
+ AuthControllerInterface* m_interface = nullptr;
QString m_userName;
bool m_isAuthenticated = false;
diff --git a/src/screensaver-dialog/checkpass-common/pam-message.cpp b/src/screensaver-dialog/checkpass-common/pam-message.cpp
index 3cd50f5..76fce7f 100644
--- a/src/screensaver-dialog/checkpass-common/pam-message.cpp
+++ b/src/screensaver-dialog/checkpass-common/pam-message.cpp
@@ -43,12 +43,12 @@ bool kiran_pam_message_send(int fd, QJsonDocument& content)
QByteArray qByteArray = content.toJson();
uint32_t contentLength = qByteArray.length();
- if (sendStream.writeRawData((const char*)&contentLength, sizeof(contentLength)) == -1)
+ if (sendStream.writeRawData(reinterpret_cast<const char*>(&contentLength), sizeof(contentLength)) == -1)
{
return false;
}
- if (sendStream.writeRawData((const char*)qByteArray.data(), qByteArray.length()) == -1)
+ if (sendStream.writeRawData(const_cast<const char*>(qByteArray.data()), qByteArray.length()) == -1)
{
return false;
}
diff --git a/src/screensaver-dialog/frame.cpp b/src/screensaver-dialog/frame.cpp
index 590c19d..73f50dc 100644
--- a/src/screensaver-dialog/frame.cpp
+++ b/src/screensaver-dialog/frame.cpp
@@ -50,9 +50,9 @@ Frame::Frame(Kiran::ScreenSaver::Interface* ksinterface, Power* power, QWidget*
m_power(power),
m_keyboard(nullptr),
m_ksInterface(ksinterface),
+ m_userName(UserManager::getCurrentUser()),
m_authProxy(nullptr)
{
- m_userName = UserManager::getCurrentUser();
KLOG_DEBUG() << "locker create for" << m_userName;
initMenus();
initUI();
@@ -102,9 +102,9 @@ void Frame::initUI()
{
// 初始化添加右下控件
// 获取菜单弹出坐标,按钮和触发菜单右对齐
- // FIXME: Qt在特定虚拟机环境下QMenu::popup传入正确的pos时,QMenu通过Pos找到screen,但screen的大小错误(为调整分辨率之前的分辨率)
+ // NOTE: Qt在特定虚拟机环境下QMenu::popup传入正确的pos时,QMenu通过Pos找到screen,但screen的大小错误(为调整分辨率之前的分辨率)
// 导致popup pos被修改成在错误的屏幕范围内
- auto getMenuPopupPos = [this](QMenu* menu, const QToolButton* triggerBtn) -> QPoint
+ auto getMenuPopupPos = [](QMenu* menu, const QToolButton* triggerBtn) -> QPoint
{
QSize menuSize = menu->actions().count() == 0 ? QSize(92, 10) : menu->sizeHint();
QPoint btnRightTopPos = triggerBtn->mapToGlobal(QPoint(triggerBtn->width(), 0));
@@ -137,7 +137,7 @@ void Frame::initUI()
};
// clang-format off
- m_btnSwitchToGreeter = createActionButton("btn_switchuser", tr("switch to greeter"), [](){
+ m_btnSwitchToGreeter = createActionButton("btn_switchuser", tr("switch to greeter"), [](){
KLOG_DEBUG() << "switch to greeter clicked";
UserManager::switchToGreeter();
});
@@ -159,7 +159,7 @@ void Frame::initUI()
return;
}
QPoint pos = getMenuPopupPos(m_powerMenu,m_btnPower);
- m_powerMenu->popup(pos);
+ m_powerMenu->popup(pos);
});
// clang-format on
diff --git a/src/screensaver-dialog/prefs.cpp b/src/screensaver-dialog/prefs.cpp
index 2e12e91..65fb565 100644
--- a/src/screensaver-dialog/prefs.cpp
+++ b/src/screensaver-dialog/prefs.cpp
@@ -33,14 +33,14 @@ void Prefs::init()
///power
settings.beginGroup("Power");
- auto canPowerOff = settings.value("can-poweroff");
- m_canPowerOff = canPowerOff.toBool();
+ auto powerOffEnable = settings.value("can-poweroff");
+ m_canPowerOff = powerOffEnable.toBool();
- auto canReboot = settings.value("can-reboot");
- m_canReboot = canReboot.toBool();
+ auto rebootEnable = settings.value("can-reboot");
+ m_canReboot = rebootEnable.toBool();
- auto canSuspend = settings.value("can-suspend");
- m_canSuspend = canSuspend.toBool();
+ auto suspendEnable = settings.value("can-suspend");
+ m_canSuspend = suspendEnable.toBool();
}
Prefs::~Prefs()
diff --git a/src/screensaver-dialog/session-guard-checkpass/main.cpp b/src/screensaver-dialog/session-guard-checkpass/main.cpp
index 9bad98d..30e8d91 100644
--- a/src/screensaver-dialog/session-guard-checkpass/main.cpp
+++ b/src/screensaver-dialog/session-guard-checkpass/main.cpp
@@ -33,7 +33,7 @@ int conversation(int num_msg, const pam_message **msgs, pam_response **resp, voi
struct pam_response *reply = NULL;
char *username = nullptr;
- reply = (struct pam_response *)calloc(num_msg, sizeof(*reply));
+ reply = static_cast<pam_response *>(calloc(num_msg, sizeof(pam_response)));
if (reply == nullptr)
{
KLOG_ERROR() << "can't malloc memory for replies,return PAM_CONV_ERR";
@@ -56,14 +56,14 @@ int conversation(int num_msg, const pam_message **msgs, pam_response **resp, voi
if (!kiran_pam_message_send_event(CHANNEL_WRITE, &event))
{
- //发送消息失败
+ // 发送消息失败
KLOG_DEBUG() << "send pam message to parent process failed!";
replyRet = PAM_CONV_ERR;
}
else
{
PamEvent *recvReply = nullptr;
- //接收消息失败
+ // 接收消息失败
if (!kiran_pam_message_recv_event(CHANNEL_READ, &recvReply))
{
KLOG_ERROR() << "recv pam prompt reply failed";
@@ -71,7 +71,7 @@ int conversation(int num_msg, const pam_message **msgs, pam_response **resp, voi
}
else
{
- //消息类型不正确
+ // 消息类型不正确
if (recvReply->type() != PamEvent::PromptReply)
{
KLOG_ERROR() << "recv event is not reply!";
@@ -80,8 +80,8 @@ int conversation(int num_msg, const pam_message **msgs, pam_response **resp, voi
else
{
auto replyEvent = dynamic_cast<PromptReplyEvent *>(recvReply);
- //KLOG_DEBUG() << "recv prompt reply:" << replyEvent->result() << replyEvent->text();
- //消息返回失败
+ // KLOG_DEBUG() << "recv prompt reply:" << replyEvent->result() << replyEvent->text();
+ // 消息返回失败
if (!replyEvent->result())
{
replyRet = PAM_CONV_ERR;
@@ -89,8 +89,10 @@ int conversation(int num_msg, const pam_message **msgs, pam_response **resp, voi
else
{
reply[i].resp_retcode = PAM_SUCCESS;
- reply[i].resp = (char *)calloc(1, replyEvent->text().length() + 1);
- strcpy(reply[i].resp, replyEvent->text().toStdString().c_str());
+ reply[i].resp = static_cast<char *>(calloc(1, replyEvent->text().length() + 1));
+ strncpy(reply[i].resp,
+ replyEvent->text().toStdString().c_str(),
+ replyEvent->text().length());
}
}
}
@@ -103,7 +105,7 @@ int conversation(int num_msg, const pam_message **msgs, pam_response **resp, voi
MessageEvent messageEvent(msg->msg_style == PAM_ERROR_MSG, msg->msg);
if (!kiran_pam_message_send_event(CHANNEL_WRITE, &messageEvent))
{
- //发送消息失败
+ // 发送消息失败
KLOG_DEBUG() << "send pam message to parent process failed!";
replyRet = PAM_CONV_ERR;
}
@@ -141,7 +143,7 @@ int main(int argc, char *argv[])
"kiran-screensaver-dialog",
"kiran-session-guard-checkpass");
- ///判断参数合法性
+ /// 判断参数合法性
if (argc != 3)
{
KLOG_ERROR() << "usage: pam-authproxy-checkpass READFD WRITEFD USERNAME";
@@ -172,8 +174,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- ///安全性
- //可以参考lightdm session-child
+ /// 安全性
+ // 可以参考lightdm session-child
/* Protect memory from being paged to disk, as we deal with passwords */
mlockall(MCL_CURRENT | MCL_FUTURE);
@@ -187,7 +189,7 @@ int main(int argc, char *argv[])
<< "\t write fd: " << CHANNEL_WRITE << "\n"
<< "\t authproxy user name:" << userName;
- ///开始pam认证
+ /// 开始pam认证
// clang-format off
struct pam_conv conv = {
.conv = &conversation,
@@ -201,7 +203,7 @@ int main(int argc, char *argv[])
KLOG_WARNING() << "failed to start pam:" << pam_strerror(pamh, ret);
return EXIT_FAILURE;
}
-
+
int authRes = PAM_SUCCESS;
authRes = pam_authenticate(pamh, 0);
const char *newUserName;
--
2.27.0