From 47d46b5422d755ccd7e85d83b1d18e84396e04fa Mon Sep 17 00:00:00 2001 From: winnerym Date: Mon, 17 Oct 2022 19:20:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E7=BA=BF=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + bioauth-bin/i18n_ts/zh_CN.ts | 9 +- bioauth-bin/src/main.cpp | 14 +- bioauth/CMakeLists.txt | 2 + bioauth/i18n_ts/bo.ts | 22 +- bioauth/i18n_ts/bo_CN.ts | 18 +- bioauth/i18n_ts/tr.ts | 22 +- bioauth/i18n_ts/zh_CN.ts | 25 +- bioauth/include/biodevices.h | 7 + bioauth/include/biotypes.h | 98 +++ bioauth/include/loginoptionswidget.h | 9 +- bioauth/include/uniauthservice.h | 78 ++ bioauth/src/biodevices.cpp | 297 +++++-- bioauth/src/loginoptionswidget.cpp | 126 ++- bioauth/src/uniauthservice.cpp | 251 ++++++ debian/changelog | 579 +++++++++++++ debian/control | 47 ++ debian/copyright | 23 + debian/libpam-biometric.install | 10 + debian/libpam-biometric.manpages | 3 + debian/libpam-biometric.postinst | 54 ++ debian/libpam-biometric.prerm | 6 + debian/rules | 8 + debian/source/format | 1 + debian/source/include-binaries | 9 + debian/ukui-polkit.install | 3 + debian/watch | 3 + pam-biometric/CMakeLists.txt | 2 +- ...op.plicykit.pkexec.bioctl-helper.policy.in | 2 + ...esktop.plicykit.pkexec.biodrvctl.policy.in | 6 +- ...sktop.plicykit.pkexec.biorestart.policy.in | 6 +- pam-biometric/data/ukui-biometric.conf | 1 + pam-biometric/pam_biometric.c | 141 +++- pam-biometric/utils/bioctl | 6 +- pam-biometric/utils/bioctl-helper | 154 +++- pam-biometric/utils/biodrvctl | 1 + polkit-agent/CMakeLists.txt | 8 + polkit-agent/i18n_ts/bo.ts | 119 +-- polkit-agent/i18n_ts/bo_CN.ts | 489 ++++++++--- polkit-agent/i18n_ts/es.ts | 12 +- polkit-agent/i18n_ts/fr.ts | 12 +- polkit-agent/i18n_ts/pt.ts | 12 +- polkit-agent/i18n_ts/ru.ts | 12 +- polkit-agent/i18n_ts/tr.ts | 113 +-- polkit-agent/i18n_ts/zh_CN.ts | 117 +-- polkit-agent/src/PolkitAgent.cpp | 1 + polkit-agent/src/PolkitListener.cpp | 31 + polkit-agent/src/PolkitListener.h | 6 + polkit-agent/src/kalabel.cpp | 44 + polkit-agent/src/kalabel.h | 23 + polkit-agent/src/mainwindow.cpp | 202 +++-- polkit-agent/src/mainwindow.h | 16 +- polkit-agent/src/mainwindow.ui | 24 +- polkit-agent/src/modeButton.cpp | 5 + polkit-agent/src/modeButton.h | 1 + polkit-agent/src/pam-tally.c | 18 +- readme.txt | 7 + uniauth-backend/CMakeLists.txt | 26 + uniauth-backend/org.ukui.UniauthBackend.conf | 23 + .../org.ukui.UniauthBackend.service | 4 + uniauth-backend/src/biodeviceinfo.cpp | 53 ++ uniauth-backend/src/biodeviceinfo.h | 58 ++ uniauth-backend/src/main.cpp | 29 + uniauth-backend/src/serviceinterface.cpp | 766 ++++++++++++++++++ uniauth-backend/src/serviceinterface.h | 105 +++ uniauth-backend/src/servicemanager.cpp | 101 +++ uniauth-backend/src/servicemanager.h | 52 ++ 67 files changed, 3969 insertions(+), 564 deletions(-) create mode 100644 bioauth/include/uniauthservice.h create mode 100644 bioauth/src/uniauthservice.cpp create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/libpam-biometric.install create mode 100644 debian/libpam-biometric.manpages create mode 100644 debian/libpam-biometric.postinst create mode 100644 debian/libpam-biometric.prerm create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 debian/source/include-binaries create mode 100644 debian/ukui-polkit.install create mode 100644 debian/watch create mode 100644 polkit-agent/src/kalabel.cpp create mode 100644 polkit-agent/src/kalabel.h create mode 100644 readme.txt create mode 100644 uniauth-backend/CMakeLists.txt create mode 100644 uniauth-backend/org.ukui.UniauthBackend.conf create mode 100644 uniauth-backend/org.ukui.UniauthBackend.service create mode 100644 uniauth-backend/src/biodeviceinfo.cpp create mode 100644 uniauth-backend/src/biodeviceinfo.h create mode 100644 uniauth-backend/src/main.cpp create mode 100644 uniauth-backend/src/serviceinterface.cpp create mode 100644 uniauth-backend/src/serviceinterface.h create mode 100644 uniauth-backend/src/servicemanager.cpp create mode 100644 uniauth-backend/src/servicemanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f0271a..7e3e71d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ add_subdirectory(bioauth) add_subdirectory(bioauth-bin) add_subdirectory(pam-biometric) add_subdirectory(polkit-agent) +add_subdirectory(uniauth-backend) add_subdirectory(images) add_dependencies(bioauth BioAuth) diff --git a/bioauth-bin/i18n_ts/zh_CN.ts b/bioauth-bin/i18n_ts/zh_CN.ts index 59e3f5d..d43bcb3 100644 --- a/bioauth-bin/i18n_ts/zh_CN.ts +++ b/bioauth-bin/i18n_ts/zh_CN.ts @@ -41,7 +41,7 @@ - + AUTHENTICATION CANCELED 认证被取消 @@ -91,7 +91,12 @@ 按Q或者Esc取消 - + + BIOMETRIC AUTHENTICATION IS CLOSED + 生物识别认证已关闭 + + + AUTHENTICATION SUCCESS 认证成功 diff --git a/bioauth-bin/src/main.cpp b/bioauth-bin/src/main.cpp index b0c7855..2bd5322 100644 --- a/bioauth-bin/src/main.cpp +++ b/bioauth-bin/src/main.cpp @@ -237,14 +237,15 @@ int main(int argc, char *argv[]) exit(BIO_ERROR); BioDevices bioDevices(true); + bioDevices.setUId(uid); int maxFailedTimes = bioDevices.getFailedTimes(); - int failedTimes = 0; DeviceInfoPtr deviceInfo = bioDevices.getDefaultDevice(uid); bool isHiddenSwitchButton = bioDevices.GetHiddenSwitchButton(); - if(!deviceInfo) + if(!deviceInfo){ // 只检查默认设备,不再使用第一个设备 exit(BIO_ERROR); + } if(bioDevices.getFeatureCount(uid)<1) - exit(BIO_ERROR); + exit(BIO_ERROR); showMessage(QObject::tr("BIOMETRIC AUTHENTICATION"), START); if(!isHiddenSwitchButton) @@ -259,6 +260,11 @@ int main(int argc, char *argv[]) QObject::connect(&bioAuth, &BioAuth::authComplete, &a, [&](uid_t uid_, int result, int retErrNo){ Q_UNUSED(retErrNo); watcher.stop(); + bool isBioEnable = bioDevices.GetBioAuthEnable(uid_); + if(!isBioEnable){ + showMessage(QObject::tr("BIOMETRIC AUTHENTICATION IS CLOSED"), RESULT); + exit(BIO_IGNORE); + } if(result && uid == uid_) { showMessage(QObject::tr("AUTHENTICATION SUCCESS"), RESULT); exit(BIO_SUCCESS); @@ -277,7 +283,7 @@ int main(int argc, char *argv[]) showMessage(QObject::tr("Failed to verify %1, you still have %2 verification opportunities").arg(bioDevices.bioTypeToString_tr(deviceInfo->biotype)).arg(maxFailedTimes-m_failedTimes[deviceInfo->device_id]),RESULT); }else{ showMessage(QObject::tr("Unable to verify %1, please enter password.").arg(bioDevices.bioTypeToString_tr(deviceInfo->biotype)),RESULT); - exit(BIO_IGNORE); + exit(BIO_IGNORE); } Option option = showOption(bioDevices.count() > 1); switch(option) { diff --git a/bioauth/CMakeLists.txt b/bioauth/CMakeLists.txt index b6d7215..076db39 100644 --- a/bioauth/CMakeLists.txt +++ b/bioauth/CMakeLists.txt @@ -6,6 +6,7 @@ qt5_wrap_ui(BioAuthWidgets_SRC qt5_wrap_cpp(BioAuth_SRC include/bioauth.h include/biodevices.h + include/uniauthservice.h ) qt5_wrap_cpp(BioAuthWidgets_SRC include/bioauthwidget.h @@ -19,6 +20,7 @@ set(BioAuth_SRC src/bioauth.cpp src/biodevices.cpp src/biotypes.cpp + src/uniauthservice.cpp ) set(BioAuthWidgets_SRC diff --git a/bioauth/i18n_ts/bo.ts b/bioauth/i18n_ts/bo.ts index 710a9b7..085c291 100644 --- a/bioauth/i18n_ts/bo.ts +++ b/bioauth/i18n_ts/bo.ts @@ -34,52 +34,52 @@ BioDevices - + Unplugging of %1 device detected - + %1 device insertion detected - + ukui-biometric-manager - + biometric - + FingerPrint - + FingerVein - + Iris - + Face - + VoicePrint - + QRCode @@ -95,7 +95,7 @@ LoginOptionsWidget - + Login Options diff --git a/bioauth/i18n_ts/bo_CN.ts b/bioauth/i18n_ts/bo_CN.ts index 81c1ae3..42b8bca 100644 --- a/bioauth/i18n_ts/bo_CN.ts +++ b/bioauth/i18n_ts/bo_CN.ts @@ -29,15 +29,15 @@ %1 too many unsuccessful attempts,please enter password. - + %1ལ་ལེགས་འགྲུབ་མ་བྱུང་བའི་ཚོད་ལྟ་མང་དྲགས་པས་གསང་གྲངས་ནང་འཇུག་གནང་རོགས། %1 authentication failure,there are still %2 remaining opportunities - + %1 བདེན་དཔང་ར་སྤྲོད་བྱེད་མ་ཐུབ་ན། ད་དུང་%2ལྷག་པའི་གོ་སྐབས་ཡོད། Please use wechat to scan the code - + ཁྱེད་ཀྱིས་འཕྲིན་ཕྲན་སྤྱད་དེ་ཚབ་རྟགས་ལ་ཞིབ་བཤེར་བྱེད་རོགས། @@ -52,7 +52,7 @@ biometric - 生物特征 + སྐྱེ་དངོས་རིག་པ། VoicePrint @@ -60,11 +60,11 @@ Unplugging of %1 device detected - 检测到%1设备拔出 + ཞིབ་དཔྱད་ཚད་ལེན་བྱས་པའི་%1སྒྲིག་ཆས་ཀྱི་ཁ་པར་རྒྱག་པ། %1 device insertion detected - 检测到%1设备插入 + %1སྒྲིག་ཆས་ནང་དུ་བཅུག་ནས་ཞིབ་དཔྱད་ཚད་ལེན་བྱས་པ་རེད། FingerPrint @@ -76,11 +76,11 @@ ukui-biometric-manager - + སྐྱེ་དངོས་ཁྱབ་རྟགས་དོ་དམ་ལག་ཆ། QRCode - + ཨང་ཀི་ཕྱག་པ། @@ -106,7 +106,7 @@ LoginOptionsWidget Login Options - + ཐོ་འགོད་ཀྱི་བསལ་འདེམས་ཀྱི་དབང་ཆ། diff --git a/bioauth/i18n_ts/tr.ts b/bioauth/i18n_ts/tr.ts index 34b0078..c319001 100644 --- a/bioauth/i18n_ts/tr.ts +++ b/bioauth/i18n_ts/tr.ts @@ -46,52 +46,52 @@ BioDevices - + Unplugging of %1 device detected - + %1 device insertion detected - + ukui-biometric-manager - + biometric - + FingerPrint Parmak İzi - + FingerVein Damar İzi - + Iris Göz - + Face Yüz - + VoicePrint Ses İzi - + QRCode @@ -123,7 +123,7 @@ LoginOptionsWidget - + Login Options diff --git a/bioauth/i18n_ts/zh_CN.ts b/bioauth/i18n_ts/zh_CN.ts index 9be7e86..6777054 100644 --- a/bioauth/i18n_ts/zh_CN.ts +++ b/bioauth/i18n_ts/zh_CN.ts @@ -54,52 +54,52 @@ BioDevices - + Unplugging of %1 device detected 检测到%1设备拔出 - + %1 device insertion detected 检测到%1设备插入 - + ukui-biometric-manager 生物特征管理工具 - + biometric 生物特征 - + FingerPrint 指纹 - + FingerVein 指静脉 - + Iris 虹膜 - + Face 人脸识别 - + VoicePrint 声纹 - + QRCode 二维码 @@ -135,7 +135,7 @@ LoginOptionsWidget - + Login Options 登录选项 @@ -144,9 +144,8 @@ 微信 - Biometric - 生物识别 + 生物识别 diff --git a/bioauth/include/biodevices.h b/bioauth/include/biodevices.h index 2e21cd1..2aa8098 100644 --- a/bioauth/include/biodevices.h +++ b/bioauth/include/biodevices.h @@ -22,6 +22,7 @@ #include #include #include "biotypes.h" +#include "uniauthservice.h" class QDBusInterface; @@ -39,6 +40,7 @@ public: explicit BioDevices(bool isIgnoreQrCode = false, QObject *parent = nullptr); int count(); + void setUId(int nUId); QMap> getAllDevices(); QMap> getUserDevices(int uid); QList getDevices(int type); @@ -59,6 +61,7 @@ public: bool GetHiddenSwitchButton(); bool GetQRCodeEnable(); bool GetBioAuthEnable(); + QStringList getAllDefDevices(); /** * @brief UpdateStatus 获取更新的设备状态 * @param drvid 驱动id @@ -66,6 +69,7 @@ public: * int devStatus, int opsStatus, notifyMessageId, ...> */ StatusReslut UpdateStatus(int drvid); + bool GetBioAuthEnable(uid_t uid); private: void connectToService(); @@ -83,6 +87,9 @@ private: bool isShowHotPlug; bool useFirstDevice; bool m_isIgnoreQrCode = false; + UniAuthService *m_uniAuthService = nullptr; + int m_nUId = -1; + QList m_listPriority; }; diff --git a/bioauth/include/biotypes.h b/bioauth/include/biotypes.h index f3ccca2..862d0ee 100644 --- a/bioauth/include/biotypes.h +++ b/bioauth/include/biotypes.h @@ -62,6 +62,104 @@ enum DBusResult { DBUS_RESULT_PERMISSIONDENIED }; +/** + * @brief 识别操作(Identify)的ops状态 + */ +/* 定义操作类型 */ +typedef enum { + OPS_TYPE_COMM = 0, + OPS_TYPE_OPEN, + OPS_TYPE_ENROLL, + OPS_TYPE_VERIFY, + OPS_TYPE_IDENTIFY, + OPS_TYPE_CAPTURE, + OPS_TYPE_SEARCH, + OPS_TYPE_CLEAN, + OPS_TYPE_GET_FLIST, + OPS_TYPE_RENAME, + OPS_TYPE_CLOSE, +}BioOpsType; + +/* + * 定义各种操作结果 + */ +typedef enum { + OPS_COMM_SUCCESS = OPS_TYPE_COMM * 100, /** 空闲状态 **/ + OPS_COMM_FAIL, /** 操作失败 **/ + OPS_COMM_NO_MATCH = OPS_COMM_FAIL, /** 不匹配 **/ + OPS_COMM_ERROR, /** 通用操作错误 **/ + OPS_COMM_STOP_BY_USER, /** 用户取消 **/ + OPS_COMM_TIMEOUT, /** 操作超时 **/ + OPS_COMM_OUT_OF_MEM, /** 无法分配内存 **/ + OPS_COMM_MAX, + + OPS_OPEN_SUCCESS = OPS_TYPE_OPEN * 100, /** 打开设备完成 **/ + OPS_OPEN_FAIL, /** 打开设备失败 **/ + OPS_OPEN_ERROR, /** 打开设备遇到错误 **/ + OPS_OPEN_MAX, + + OPS_ENROLL_SUCCESS = OPS_TYPE_ENROLL * 100, /** 录入信息成功 **/ + OPS_ENROLL_FAIL, /** 录入失败 **/ + OPS_ENROLL_ERROR, /** 录入过程中遇到错误 **/ + OPS_ENROLL_STOP_BY_USER, /** 录入被用户中断 **/ + OPS_ENROLL_TIMEOUT, /** 操作超时 **/ + OPS_ENROLL_MAX, + + OPS_VERIFY_MATCH = OPS_TYPE_VERIFY * 100, /** 认证匹配 **/ + OPS_VERIFY_NO_MATCH, /** 认证不匹配 **/ + OPS_VERIFY_ERROR, /** 认证过程中遇到错误 **/ + OPS_VERIFY_STOP_BY_USER, /** 认证被用户中断 **/ + OPS_VERIFY_TIMEOUT, /** 操作超时 **/ + OPS_VERIFY_MAX, + + OPS_IDENTIFY_MATCH = OPS_TYPE_IDENTIFY * 100, /** 识别到指定特征 **/ + OPS_IDENTIFY_NO_MATCH, /** 未识别出指定特征 **/ + OPS_IDENTIFY_ERROR, /** 识别过程中遇到错误 **/ + OPS_IDENTIFY_STOP_BY_USER, /** 识别被用户中断 **/ + OPS_IDENTIFY_TIMEOUT, /** 操作超时 **/ + OPS_IDENTIFY_MAX, + + OPS_CAPTURE_SUCCESS = OPS_TYPE_CAPTURE * 100, /** 捕获成功 **/ + OPS_CAPTURE_FAIL, /** 捕获失败 **/ + OPS_CAPTURE_ERROR, /** 捕获过程中遇到错误 **/ + OPS_CAPTURE_STOP_BY_USER, /** 捕获被用户中断 **/ + OPS_CAPTURE_TIMEOUT, /** 操作超时 **/ + OPS_CAPTURE_MAX, + + OPS_SEARCH_MATCH = OPS_TYPE_SEARCH * 100, /** 搜索到指定特征 **/ + OPS_SEARCH_NO_MATCH, /** 未搜索到指定特征 **/ + OPS_SEARCH_ERROR, /** 搜索过程中遇到错误 **/ + OPS_SEARCH_STOP_BY_USER, /** 搜索被用户中断 **/ + OPS_SEARCH_TIMEOUT, /** 操作超时 **/ + OPS_SEARCH_MAX, + + OPS_CLEAN_SUCCESS = OPS_TYPE_CLEAN * 100, /** 清理特征成功 **/ + OPS_CLEAN_FAIL, /** 清理失败 **/ + OPS_CLEAN_ERROR, /** 清理过程中遇到错误 **/ + OPS_CLEAN_STOP_BY_USER, /** 清理被用户中断 **/ + OPS_CLEAN_TIMEOUT, /** 操作超时 **/ + OPS_CLEAN_MAX, + + OPS_GET_FLIST_SUCCESS = OPS_TYPE_GET_FLIST * 100, /** 获取特征列表完成 **/ + OPS_GET_FLIST_FAIL, /** 获取特征列表失败 **/ + OPS_GET_FLIST_ERROR, /** 获取特征列表过程中遇到错误 **/ + OPS_GET_FLIST_STOP_BY_USER, /** 获取特征列表被用户中断 **/ + OPS_GET_FLIST_TIMEOUT, /** 获取特征列表超时 **/ + OPS_GET_FLIST_MAX, + + OPS_RENAME_SUCCESS = OPS_TYPE_RENAME * 100, /** 重命名特征完成 **/ + OPS_RENAME_FAIL, /** 重命名特征失败 **/ + OPS_RENAME_ERROR, /** 重命名特征过程中遇到错误 **/ + OPS_RENAME_STOP_BY_USER, /** 重命名特征被用户中断 **/ + OPS_RENAME_TIMEOUT, /** 重命名特征超时 **/ + OPS_RENAME_MAX, + + OPS_CLOSE_SUCCESS = OPS_TYPE_CLOSE * 100, /** 关闭设备完成 **/ + OPS_CLOSE_FAIL, /** 关闭设备失败 **/ + OPS_CLOSE_ERROR, /** 关闭设备过程中遇到错误 **/ + OPS_CLOSE_MAX, +}OpsResult; + /** * @brief UpdateStauts调用返回的结果 */ diff --git a/bioauth/include/loginoptionswidget.h b/bioauth/include/loginoptionswidget.h index 4276b22..c5c8584 100644 --- a/bioauth/include/loginoptionswidget.h +++ b/bioauth/include/loginoptionswidget.h @@ -45,6 +45,7 @@ public: DeviceInfoPtr findDeviceByName(const QString &name); void setDeviceDisable(int nDevId, bool bDisable = true); bool isDeviceDisable(int nDevId); + void lockStatusChanged(bool locked); /** * @brief 获取默认设备 @@ -71,6 +72,7 @@ public: bool isAuthenticating() { return m_isInAuth; } + QPixmap loadSvg(QString path, QString color, int size); public slots: void readDevicesInfo(); @@ -99,11 +101,10 @@ private: void clearOptionButtons(); void updateOptionButtons(); void startAuth_(); - bool getAuthDouble(); QPixmap PixmapToRound(const QPixmap &src, int radius); QPixmap scaledPixmap(int width, int height, QString url); - QPixmap loadSvg(QString path, QString color, int size); QPixmap drawSymbolicColoredPixmap(QPixmap &source, QString cgColor); + void updatePixmap(); private: BioAuth *m_biomericProxy = nullptr; @@ -129,10 +130,14 @@ private: QMap m_mapOptBtns; QWidget *m_widgetImage = nullptr; QLabel *m_labelFace = nullptr; + QLabel *m_labelFaceLoad = nullptr; QLabel *m_labelQRCode = nullptr; // 二维码图标 QLabel *m_labelQRCodeMsg = nullptr; // 二维码状态消息提示 QLabel *m_labelQRCodeTip = nullptr; QMap> m_mapDisableDev; + bool is_Lock = false; + QPixmap m_waitingPixmap; + QTimer *w_timer; }; #endif // LOGINOPTIONSWIDGET_H diff --git a/bioauth/include/uniauthservice.h b/bioauth/include/uniauthservice.h new file mode 100644 index 0000000..9bbe5b4 --- /dev/null +++ b/bioauth/include/uniauthservice.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ +#ifndef UNIAUTH_SERVICE_H +#define UNIAUTH_SERVICE_H + +#include +#include + +enum authEnableType { + ENABLETYPE_BIO, // 全局总使能 + ENABLETYPE_SAVER, // 锁屏 + ENABLETYPE_GREETER, // 登录 + ENABLETYPE_POLKIT, // 授权 + ENABLETYPE_SU, // 暂保留 + ENABLETYPE_SUDO, // 暂保留 + ENABLETYPE_LOGIN, // 暂保留 +}; + +class UniAuthService : public QDBusAbstractInterface +{ + Q_OBJECT +public: + explicit UniAuthService(QObject *parent = nullptr); + +public Q_SLOTS: + // 设置默认设备 + void setDefaultDevice(int bioDevType, QString deviceName); + // 获取默认设备 + QString getDefaultDevice(QString userName, int bioDevType); + // 获取所有默认设备 + QStringList getAllDefaultDevice(QString userName); + //生物特征开关接口 + bool getBioAuthStatus(QString userName, int bioAuthType); + void setBioAuthStatus(int bioAuthType, bool status); + // 获取最大失败次数 + int getMaxFailedTimes(); + // 获取是否使能微信扫码登录 + bool getQRCodeEnable(); + // 获取是否双认证 + bool getDoubleAuth(); + // 获取用户绑定 + bool getUserBind(); + // 获取是否在控制面板显示 + bool getIsShownInControlCenter(); + // 获取是否使用第一个设备 + bool getUseFirstDevice(); + // 获取是否隐藏切换按钮 + bool getHiddenSwitchButton(); + +public: + bool isActivatable(); + +Q_SIGNALS: + //默认设备改变 + void defaultDeviceChanged(QString userName, int bioDevType, QString deviceName); + //开关状态改变 + void bioAuthStatusChanged(QString userName, int type, bool status); + +private: + bool m_isActivatable; +}; + +#endif // UNIAUTH_SERVICE_H diff --git a/bioauth/src/biodevices.cpp b/bioauth/src/biodevices.cpp index 0f2c230..92fb32e 100644 --- a/bioauth/src/biodevices.cpp +++ b/bioauth/src/biodevices.cpp @@ -29,14 +29,26 @@ BioDevices::BioDevices(bool isIgnoreQrCode, QObject *parent) : QObject(parent), + m_uniAuthService(new UniAuthService(this)), isShowHotPlug(false), useFirstDevice(false), m_isIgnoreQrCode(isIgnoreQrCode) { connectToService(); - getDevicesList(); - useFirstDevice = getUseFirstDevice(); + m_listPriority.clear(); + m_listPriority.push_back(BIOTYPE_FACE); + m_listPriority.push_back(BIOTYPE_FINGERPRINT); + m_listPriority.push_back(BIOTYPE_IRIS); + m_listPriority.push_back(BIOTYPE_VOICEPRINT); + m_listPriority.push_back(BIOTYPE_FINGERVEIN); + m_listPriority.push_back(REMOTE_QRCODE_TYPE); +} + +void BioDevices::setUId(int nUId) +{ + m_nUId = nUId; + getDevicesList(); } void BioDevices::connectToService() @@ -92,6 +104,31 @@ void BioDevices::onUSBDeviceHotPlug(int deviceId, int action, int devNumNow) } } +bool BioDevices::GetBioAuthEnable(uid_t uid) +{ + if (m_uniAuthService && m_uniAuthService->isActivatable()) { + struct passwd *pwd = getpwuid(uid); + if (pwd) { + return m_uniAuthService->getBioAuthStatus(pwd->pw_name, ENABLETYPE_BIO); + } else { + return false; + } + } else { + QString configPath = "/etc/biometric-auth/ukui-biometric.conf"; + QSettings settings(configPath, QSettings::IniFormat); + qDebug() << "configure path: " << settings.fileName(); + + if(settings.allKeys().contains("EnableAuth")){ + return settings.value("EnableAuth").toBool(); + }else{ + QSettings sysSettings(GET_STR(CONFIG_FILE), QSettings::IniFormat); + if(sysSettings.contains("EnableAuth")) + return sysSettings.value("EnableAuth").toBool(); + else + return true; + } + } +} /** * 获取设备列表 @@ -237,48 +274,128 @@ void BioDevices::setIsShowHotPlug(bool isShow) bool BioDevices::getUseFirstDevice() { - QSettings settings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); - return settings.value("UseFirstDevice").toBool(); + if (m_uniAuthService && m_uniAuthService->isActivatable()) { + return m_uniAuthService->getUseFirstDevice(); + } else { + QSettings settings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); + return settings.value("UseFirstDevice").toBool(); + } } bool BioDevices::GetHiddenSwitchButton() { - QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); - if(sysSettings.contains("HiddenSwitchButton")) - return sysSettings.value("HiddenSwitchButton").toBool(); - else - return false; + if (m_uniAuthService && m_uniAuthService->isActivatable()) { + return m_uniAuthService->getHiddenSwitchButton(); + } else { + QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); + if(sysSettings.contains("HiddenSwitchButton")) + return sysSettings.value("HiddenSwitchButton").toBool(); + else + return false; + } } int BioDevices::getFailedTimes() { - QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); - if(sysSettings.contains("MaxFailedTimes")) - return sysSettings.value("MaxFailedTimes").toInt(); - else - return 3; + if (m_uniAuthService && m_uniAuthService->isActivatable()) { + return m_uniAuthService->getMaxFailedTimes(); + } else { + QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); + if(sysSettings.contains("MaxFailedTimes")) + return sysSettings.value("MaxFailedTimes").toInt(); + else + return 3; + } } bool BioDevices::GetQRCodeEnable() { - bool isEnable = false; - QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); - sysSettings.beginGroup("Functions"); - if (sysSettings.allKeys().contains("EnableQRCode")) { - isEnable = sysSettings.value("EnableQRCode").toBool(); + if (m_uniAuthService && m_uniAuthService->isActivatable()) { + return m_uniAuthService->getQRCodeEnable(); + } else { + bool isEnable = false; + QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); + sysSettings.beginGroup("Functions"); + if (sysSettings.allKeys().contains("EnableQRCode")) { + isEnable = sysSettings.value("EnableQRCode").toBool(); + } + sysSettings.endGroup(); + return isEnable; } - sysSettings.endGroup(); - return isEnable; } +/** + * ukui-greeter 1 + * ukui-screensaver 1<<1 + * ukui-polkit 1<<2 + * sudo 1<<3 + * su 1<<4 + * login 1<<5 + **/ bool BioDevices::GetBioAuthEnable() { - bool isEnable = false; - QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); - if (sysSettings.allKeys().contains("EnableAuth")) { - isEnable = sysSettings.value("EnableAuth").toBool(); + if (m_uniAuthService && m_uniAuthService->isActivatable()) { + bool isEnable = false; + struct passwd *pwd = getpwuid(m_nUId); + if (pwd) { + isEnable = m_uniAuthService->getBioAuthStatus(pwd->pw_name, ENABLETYPE_BIO); + } + if (isEnable && !isShowHotPlug) { + if(qAppName() == "polkit-ukui-authentication-agent-1") //获取polkit开关是否打开 + isEnable = m_uniAuthService->getBioAuthStatus(pwd->pw_name, ENABLETYPE_POLKIT); + if(qAppName() == "bioauth"){ //获取父进程名称为sudo,su,或者login + int ppid = getppid(); //获取父进程pid + QString filename = "/proc/" + QString::number(ppid) + "/cmdline"; + QFile file(filename); + if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug()<<"Can't open the file!"<getBioAuthStatus(pwd->pw_name, ENABLETYPE_SUDO); + }else if(text.contains("su")){ + isEnable = m_uniAuthService->getBioAuthStatus(pwd->pw_name, ENABLETYPE_SU); + }else if(text.contains("login")){ + isEnable = m_uniAuthService->getBioAuthStatus(pwd->pw_name, ENABLETYPE_LOGIN); + } + } + } + + return isEnable; + } else { + bool isEnable = false; + int isEnableApp = 0; + QSettings sysSettings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); + if (sysSettings.allKeys().contains("EnableAuth")) { + isEnable = sysSettings.value("EnableAuth").toBool(); + } + + if (isEnable && sysSettings.allKeys().contains("EnableAuthApp")) { + isEnableApp = sysSettings.value("EnableAuthApp").toInt(); + if(qAppName() == "polkit-ukui-authentication-agent-1") //获取polkit开关是否打开 + isEnable = isEnableApp & (1<<2); + if(qAppName() == "bioauth"){ //获取父进程名称为sudo,su,或者login + int ppid = getppid(); //获取父进程pid + QString filename = "/proc/" + QString::number(ppid) + "/cmdline"; + QFile file(filename); + if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug()<<"Can't open the file!"<isActivatable()) { + QString defaultDeviceName = ""; + struct passwd *pwdInfo = getpwuid(uid); + DeviceInfoPtr ptrDevInfo = nullptr; + if (pwdInfo) { + for (auto bioType : m_listPriority) { + QString strDeviceName = m_uniAuthService->getDefaultDevice(pwdInfo->pw_name, bioType); + if(!strDeviceName.isEmpty()) { + ptrDevInfo = findDevice(strDeviceName); + if (ptrDevInfo) { + if (GetUserDevFeatureCount(uid,ptrDevInfo->device_id) > 0) { + defaultDeviceName = strDeviceName; + break; + } + } + } + } + } + if(defaultDeviceName.isEmpty()){ + return nullptr; + } + return ptrDevInfo; + } else { + QString defaultDeviceName; - struct passwd *pwd = getpwuid(uid); - QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; - QSettings userConfig(userConfigFile, QSettings::IniFormat); - qDebug() << userConfig.fileName(); - defaultDeviceName = userConfig.value(DEFAULT_DEVICE).toString(); - qDebug() << defaultDeviceName; - - if(defaultDeviceName.isEmpty() || !findDevice(defaultDeviceName)) { - QSettings sysConfig(GET_STR(CONFIG_FILE), QSettings::IniFormat); - defaultDeviceName = sysConfig.value(DEFAULT_DEVICE).toString(); - } - - if(defaultDeviceName.isEmpty() || !findDevice(defaultDeviceName)){ + struct passwd *pwd = getpwuid(uid); QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; QSettings userConfig(userConfigFile, QSettings::IniFormat); + qDebug() << userConfig.fileName(); defaultDeviceName = userConfig.value(DEFAULT_DEVICE).toString(); + qDebug() << defaultDeviceName; + + if(defaultDeviceName.isEmpty() || !findDevice(defaultDeviceName)) { + QSettings sysConfig(GET_STR(CONFIG_FILE), QSettings::IniFormat); + defaultDeviceName = sysConfig.value(DEFAULT_DEVICE).toString(); + } + + if(defaultDeviceName.isEmpty() || !findDevice(defaultDeviceName)){ + QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; + QSettings userConfig(userConfigFile, QSettings::IniFormat); + defaultDeviceName = userConfig.value(DEFAULT_DEVICE).toString(); + } + qDebug() << "default device: " << defaultDeviceName; + // 终端不默认使用第一个设备 + if(defaultDeviceName.isEmpty()){ + return nullptr; + } + bool defValid = false; + DeviceInfoPtr ptrDevInfo = findDevice(defaultDeviceName); + if (ptrDevInfo) { + if (GetUserDevFeatureCount(uid,ptrDevInfo->device_id) > 0) { + defValid = true; + } + } + + if (!defValid) { + ptrDevInfo = nullptr; + } + + return ptrDevInfo; } - qDebug() << "default device: " << defaultDeviceName; - // 终端不默认使用第一个设备 - if(defaultDeviceName.isEmpty()){ -// if(!useFirstDevice) -// return nullptr; -// else -// return getFirstDevice(uid); - return nullptr; - } - bool defValid = false; - DeviceInfoPtr ptrDevInfo = findDevice(defaultDeviceName); - if (ptrDevInfo) { - if (GetUserDevFeatureCount(uid,ptrDevInfo->device_id) > 0) { - defValid = true; +} + +QStringList BioDevices::getAllDefDevices() +{ + QStringList listDefDevices; + if (m_uniAuthService && m_uniAuthService->isActivatable()) { + struct passwd *pwdInfo = getpwuid(m_nUId); + if (pwdInfo) { + listDefDevices = m_uniAuthService->getAllDefaultDevice(pwdInfo->pw_name); + } + } else { + QString defaultDeviceName; + + struct passwd *pwd = getpwuid(m_nUId); + QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; + QSettings userConfig(userConfigFile, QSettings::IniFormat); + qDebug() << userConfig.fileName(); + defaultDeviceName = userConfig.value(DEFAULT_DEVICE).toString(); + qDebug() << defaultDeviceName; + + if(defaultDeviceName.isEmpty() || !findDevice(defaultDeviceName)) { + QSettings sysConfig(GET_STR(CONFIG_FILE), QSettings::IniFormat); + defaultDeviceName = sysConfig.value(DEFAULT_DEVICE).toString(); + } + + if(defaultDeviceName.isEmpty() || !findDevice(defaultDeviceName)){ + QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; + QSettings userConfig(userConfigFile, QSettings::IniFormat); + defaultDeviceName = userConfig.value(DEFAULT_DEVICE).toString(); + } + qDebug() << "default device: " << defaultDeviceName; + if(!defaultDeviceName.isEmpty()){ + listDefDevices.push_back(defaultDeviceName); } } - - if (!defValid) { -// if(!useFirstDevice) -// ptrDevInfo = nullptr; -// else -// ptrDevInfo = getFirstDevice(uid); - ptrDevInfo = nullptr; - } - - return ptrDevInfo; + return listDefDevices; } int BioDevices::GetLastDevice(const QString &userName) diff --git a/bioauth/src/loginoptionswidget.cpp b/bioauth/src/loginoptionswidget.cpp index cf06ddf..445592c 100644 --- a/bioauth/src/loginoptionswidget.cpp +++ b/bioauth/src/loginoptionswidget.cpp @@ -27,6 +27,7 @@ LoginOptionsWidget::LoginOptionsWidget(QWidget *parent) : QWidget(parent) , m_biomericProxy(new BioAuth(this)) , m_bioDevices(new BioDevices()) + , w_timer(nullptr) { initUI(); initConnections(); @@ -73,8 +74,17 @@ void LoginOptionsWidget::initUI() m_labelFace->setObjectName("faceLabel"); m_labelFace->setAlignment(Qt::AlignCenter); m_labelFace->setFixedSize(154,154); - QImage img; - setFaceImg(img); + QHBoxLayout *layoutFace = new QHBoxLayout(); + layoutFace->setContentsMargins(0,0,0,0); + layoutFace->setAlignment(Qt::AlignCenter); + m_labelFace->setLayout(layoutFace); + m_labelFaceLoad = new QLabel(); + m_labelFaceLoad->setAlignment(Qt::AlignCenter); + m_labelFaceLoad->setFixedSize(142, 142); + m_labelFaceLoad->setStyleSheet(QString("QLabel{background-color: rgba(230,230,230,0.39); border-radius: %1px; border: 8px solid white;}").arg(71)); + layoutFace->addWidget(m_labelFaceLoad, 0, Qt::AlignVCenter); +// QImage img; +// setFaceImg(img); m_labelFace->hide(); // 二维码窗口 m_labelQRCode = new QLabel(m_widgetImage); @@ -85,11 +95,11 @@ void LoginOptionsWidget::initUI() m_layoutMain->addLayout(m_layoutImage); QVBoxLayout *layoutQRCode = new QVBoxLayout(); layoutQRCode->setAlignment(Qt::AlignCenter); - layoutQRCode->setSpacing(10); + layoutQRCode->setSpacing(5); m_labelQRCode->setLayout(layoutQRCode); m_labelQRCodeTip = new QLabel(); m_labelQRCodeTip->setFixedSize(22,22); - m_labelQRCodeTip->setPixmap(QIcon::fromTheme("ukui-dialog-warning").pixmap(QSize(22,22))); + m_labelQRCodeTip->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(QSize(22,22))); layoutQRCode->addWidget(m_labelQRCodeTip, 0, Qt::AlignHCenter); m_labelQRCodeMsg = new QLabel(); m_labelQRCodeMsg->setFixedHeight(24); @@ -117,7 +127,7 @@ void LoginOptionsWidget::initConnections() if (m_bioDevices) { connect(m_bioDevices, &BioDevices::deviceCountChanged, this, &LoginOptionsWidget::onUSBDeviceCountChange); - readDevicesInfo(); + //readDevicesInfo(); } connect(m_btnGroup, SIGNAL(buttonClicked(int)), this, SLOT(onOptionSelected(int))); } @@ -293,6 +303,9 @@ void LoginOptionsWidget::setUser(int uid) } m_uid = uid; if (bNeedUpdateDevInfo) { + if (m_bioDevices) { + m_bioDevices->setUId(m_uid); + } readDevicesInfo(); } } @@ -303,6 +316,7 @@ void LoginOptionsWidget::readDevicesInfo() bool isAuthEnable = m_bioDevices->GetBioAuthEnable(); bool isQRCodeEnable = m_bioDevices->GetQRCodeEnable(); DeviceList deviceList = m_bioDevices->GetDevList(); + QStringList listDefDevices = m_bioDevices->getAllDefDevices(); for(auto pDeviceInfo : deviceList) { int nDevFeatureCount = 0; @@ -323,7 +337,10 @@ void LoginOptionsWidget::readDevicesInfo() continue; int nDevType = LOGINOPT_TYPE_OTHERS; nDevType = convertDeviceType(pDeviceInfo->biotype); - m_mapDevices[nDevType].push_back(pDeviceInfo); + if (listDefDevices.contains(pDeviceInfo->device_shortname) && + !m_mapDevices.contains(nDevType)) { + m_mapDevices[nDevType].push_back(pDeviceInfo); + } } } updateOptionButtons(); @@ -333,7 +350,7 @@ void LoginOptionsWidget::readDevicesInfo() void LoginOptionsWidget::startAuth(DeviceInfoPtr device, int uid) { - if(!m_biomericProxy) + if(!device || !m_biomericProxy || is_Lock) { qWarning() << "BiometricProxy doesn't exist."; return; @@ -363,7 +380,24 @@ void LoginOptionsWidget::startAuth_() m_isInAuth = true; m_dupFD = -1; - + if(!w_timer) + { + w_timer = new QTimer(this); + w_timer->setInterval(150); + connect(w_timer, &QTimer::timeout, this, &LoginOptionsWidget::updatePixmap); + } + m_waitingPixmap = QIcon::fromTheme("ukui-loading-0-symbolic").pixmap(24, 24); + if(m_curLoginOptType == LOGINOPT_TYPE_QRCODE) { + m_labelQRCodeTip->setPixmap(m_waitingPixmap); + m_labelQRCodeTip->show(); + m_labelQRCodeMsg->hide(); + } else if(m_curLoginOptType == LOGINOPT_TYPE_FACE) { + m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(230,230,230,0.39);").arg(77)); + m_labelFace->setPixmap(QPixmap("")); + m_labelFaceLoad->setPixmap(m_waitingPixmap); + m_labelFaceLoad->show(); + } + w_timer->start(); m_biomericProxy->startAuth(m_uid, m_curDevInfo); } @@ -386,6 +420,18 @@ void LoginOptionsWidget::stopAuth() setFaceImg(img); } +void LoginOptionsWidget::updatePixmap() +{ + QMatrix matrix; + matrix.rotate(90.0); + m_waitingPixmap = m_waitingPixmap.transformed(matrix, Qt::FastTransformation); + if(m_curLoginOptType == LOGINOPT_TYPE_QRCODE) + m_labelQRCodeTip->setPixmap(m_waitingPixmap); + else if(m_curLoginOptType == LOGINOPT_TYPE_FACE) { + m_labelFaceLoad->setPixmap(m_waitingPixmap); + } +} + void LoginOptionsWidget::onIdentifyComplete(int uid, bool ret, int retErrNo) { if(m_isStopped == true) @@ -414,6 +460,10 @@ void LoginOptionsWidget::onIdentifyComplete(int uid, bool ret, int retErrNo) if(ret.result == 0 && (ret.opsStatus == 404 || ret.opsStatus == 304 || ret.opsStatus == 8)) { // 304认证超时, 8网络异常 Q_EMIT authComplete(uid, false, 1); + } else if (ret.opsStatus == OPS_IDENTIFY_STOP_BY_USER || ret.opsStatus == OPS_VERIFY_STOP_BY_USER) { + Q_EMIT authComplete(uid, false, -2); // 主动停止,直接重试 + } else if (ret.opsStatus == OPS_OPEN_FAIL || ret.opsStatus == OPS_OPEN_ERROR) { // 无法打开设备(设备是坏的/被占用),直接禁用 + Q_EMIT authComplete(uid, false, 5); } else { Q_EMIT authComplete(uid, false, 2); } @@ -518,6 +568,7 @@ void LoginOptionsWidget::onFrameWritten(int drvid) m_labelQRCode->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,100%);").arg(6)); setQRCode(srcQImage); m_labelQRCode->show(); + m_labelQRCodeTip->hide(); m_labelFace->hide(); } else { m_labelFace->hide(); @@ -527,6 +578,10 @@ void LoginOptionsWidget::onFrameWritten(int drvid) m_labelFace->hide(); m_labelQRCode->hide(); } + if(w_timer && w_timer->isActive()) + { + w_timer->stop(); + } Q_EMIT updateImage(srcQImage); } @@ -544,11 +599,17 @@ void LoginOptionsWidget::setQRCodeMsg(QString strMsg) { if (strMsg.isEmpty()) { m_labelQRCodeMsg->hide(); - m_labelQRCodeTip->hide(); + //m_labelQRCodeTip->hide(); } else { + //一开始认证时就没有网,直接停止加载状态 + if(w_timer && w_timer->isActive()) + { + w_timer->stop(); + } m_labelQRCodeMsg->setText(strMsg); m_labelQRCodeMsg->show(); m_labelQRCodeTip->show(); + m_labelQRCodeTip->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(QSize(22,22))); } } @@ -563,15 +624,22 @@ void LoginOptionsWidget::setFaceImg(QImage& imgFace, int nStatus) switch(nStatus) { case 1: faceImage = loadSvg(QString("%1/images/ukui-loginopt-lose.svg").arg(GET_STR(UKUI_BIOMETRIC)),"black",48); + m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(230,230,230,40%);").arg(77)); + break; + case 2: + faceImage = loadSvg(QString("%1/images/ukui-loginopt-smile.svg").arg(GET_STR(UKUI_BIOMETRIC)),"gray",48); + m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(230,230,230,100%);").arg(77)); break; default: faceImage = loadSvg(QString("%1/images/ukui-loginopt-smile.svg").arg(GET_STR(UKUI_BIOMETRIC)),"black",48); + m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(230,230,230,40%);").arg(77)); break; } } m_labelFace->setAlignment(Qt::AlignCenter); m_labelFace->setPixmap(faceImage); + m_labelFaceLoad->hide(); } void LoginOptionsWidget::onStatusChanged(int drvid, const QString &message) @@ -646,24 +714,10 @@ DeviceInfoPtr LoginOptionsWidget::findDeviceByName(const QString &name) QString LoginOptionsWidget::GetDefaultDevice(uid_t uid) { - QString defaultDeviceName; - - struct passwd *pwd = getpwuid(uid); - QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; - QSettings userConfig(userConfigFile, QSettings::IniFormat); - qDebug() << userConfig.fileName(); - defaultDeviceName = userConfig.value(DEFAULT_DEVICE).toString(); - qDebug() << defaultDeviceName; - - if(defaultDeviceName.isEmpty() || !findDeviceByName(defaultDeviceName)) { - QSettings sysConfig(GET_STR(CONFIG_FILE), QSettings::IniFormat); - defaultDeviceName = sysConfig.value(DEFAULT_DEVICE).toString(); - } - - if(defaultDeviceName.isEmpty() || !findDeviceByName(defaultDeviceName)){ - QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; - QSettings userConfig(userConfigFile, QSettings::IniFormat); - defaultDeviceName = userConfig.value(DEFAULT_DEVICE).toString(); + QString defaultDeviceName = ""; + DeviceInfoPtr pDeviceInfo = m_bioDevices->getDefaultDevice(uid); + if (pDeviceInfo) { + defaultDeviceName = pDeviceInfo->device_shortname; } qDebug() << "default device: " << defaultDeviceName; @@ -691,13 +745,6 @@ void LoginOptionsWidget::onUSBDeviceCountChange(int newNum) updateUIStatus(false); } -bool LoginOptionsWidget::getAuthDouble() -{ - QSettings settings("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); - bool distribId = settings.value("DoubleAuth").toBool(); - return distribId; -} - void LoginOptionsWidget::updateUIStatus(bool update) { if (m_mapOptBtns.contains(-1)) { @@ -810,6 +857,17 @@ bool LoginOptionsWidget::isDeviceDisable(int nDevId) return false; } +void LoginOptionsWidget::lockStatusChanged(bool locked) +{ + if(locked){ + is_Lock = true; + stopAuth(); + } else { + is_Lock = false; + readDevicesInfo(); + } +} + QPixmap LoginOptionsWidget::loadSvg(QString path, QString color, int size) { int origSize = size; diff --git a/bioauth/src/uniauthservice.cpp b/bioauth/src/uniauthservice.cpp new file mode 100644 index 0000000..4f327af --- /dev/null +++ b/bioauth/src/uniauthservice.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ +#include "uniauthservice.h" +#include +#include + +#define UNIAUTH_DBUS_SERVICE "org.ukui.UniauthBackend" +#define UNIAUTH_DBUS_PATH "/org/ukui/UniauthBackend" +#define UNIAUTH_DBUS_INTERFACE "org.ukui.UniauthBackend" + +#define FD_DBUS_SERVICE "org.freedesktop.DBus" +#define FD_DBUS_PATH "/org/freedesktop/DBus" +#define FD_DBUS_INTERFACE "org.freedesktop.DBus" + +UniAuthService::UniAuthService(QObject *parent) + : QDBusAbstractInterface(UNIAUTH_DBUS_SERVICE, + UNIAUTH_DBUS_PATH, + UNIAUTH_DBUS_INTERFACE, + QDBusConnection::systemBus(), + parent) + , m_isActivatable(false) +{ + setTimeout(2147483647); + QDBusInterface *dbusService = new QDBusInterface(FD_DBUS_SERVICE, + FD_DBUS_PATH, + FD_DBUS_INTERFACE, + QDBusConnection::systemBus()); + if (dbusService) { + QDBusReply result = dbusService->call(QStringLiteral("ListActivatableNames")); + if(!result.isValid()) { + qWarning() << "ListActivatableNames error:" << result.error().message(); + } else { + QStringList listNames = result.value(); + if (listNames.contains(UNIAUTH_DBUS_INTERFACE)) { + m_isActivatable = true; + } + } + } +} + +// 设置默认设备 +void UniAuthService::setDefaultDevice(int bioDevType, QString deviceName) +{ + qDebug() << " bioType : " << bioDevType << "deviceName : " << deviceName; + QDBusMessage result = call(QStringLiteral("setDefaultDevice"), bioDevType, deviceName); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "setDefaultDevice error:" << result.errorMessage(); + return ; + } + return ; +} + +// 获取默认设备 +QString UniAuthService::getDefaultDevice(QString userName, int bioDevType) +{ + QDBusMessage result = call(QStringLiteral("getDefaultDevice"), userName, bioDevType); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getDefaultDevice error:" << result.errorMessage(); + return ""; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + QString strDefDevice = varResult.takeFirst().toString(); + return strDefDevice; + } else { + return ""; + } +} + +// 获取所有默认设备 +QStringList UniAuthService::getAllDefaultDevice(QString userName) +{ + QStringList listDefDevices; + QDBusReply result = call(QStringLiteral("getAllDefaultDevice"), userName); + if(!result.isValid()) { + qWarning() << "getAllDefaultDevice error:" << result.error().message(); + } else { + listDefDevices = result.value(); + } + return listDefDevices; +} + +//生物特征开关接口 +bool UniAuthService::getBioAuthStatus(QString userName, int bioAuthType) +{ + QDBusMessage bioResult = call(QStringLiteral("getBioAuthStatus"), userName, bioAuthType); + if(bioResult.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getBioStatus error:" << bioResult.errorMessage(); + return false; + } + QList varResult = bioResult.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +void UniAuthService::setBioAuthStatus(int bioAuthType, bool status) +{ + qDebug() << "setBioAuthStatus bioAuthType : " << bioAuthType << "status : " << status; + QDBusMessage result = call(QStringLiteral("setBioAuthStatus"), bioAuthType, status); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "setBioAuthStatus error:" << result.errorMessage(); + return ; + } + return ; +} + +// 获取最大失败次数 +int UniAuthService::getMaxFailedTimes() +{ + QDBusMessage result = call(QStringLiteral("getMaxFailedTimes")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getMaxFailedTimes error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toInt(); + } else { + return 3; + } +} + +// 获取是否使能微信扫码登录 +bool UniAuthService::getQRCodeEnable() +{ + QDBusMessage result = call(QStringLiteral("getQRCodeEnable")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getQRCodeEnable error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否双认证 +bool UniAuthService::getDoubleAuth() +{ + QDBusMessage result = call(QStringLiteral("getDoubleAuth")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getDoubleAuth error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取用户绑定 +bool UniAuthService::getUserBind() +{ + QDBusMessage result = call(QStringLiteral("getUserBind")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getUserBind error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否在控制面板显示 +bool UniAuthService::getIsShownInControlCenter() +{ + QDBusMessage result = call(QStringLiteral("getIsShownInControlCenter")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getIsShownInControlCenter error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否使用第一个设备 +bool UniAuthService::getUseFirstDevice() +{ + QDBusMessage result = call(QStringLiteral("getUseFirstDevice")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getUseFirstDevice error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否隐藏切换按钮 +bool UniAuthService::getHiddenSwitchButton() +{ + QDBusMessage result = call(QStringLiteral("getHiddenSwitchButton")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getHiddenSwitchButton error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +bool UniAuthService::isActivatable() +{ + return m_isActivatable; +} diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..27af4bc --- /dev/null +++ b/debian/changelog @@ -0,0 +1,579 @@ +ukui-biometric-auth (3.20.0.11) v101; urgency=medium + + * BUG号:143415 【安全套件】卫士通Ukey绑定后授权提示信息乱码 + 139665 【人脸】【登录】摄像头运行时锁屏,人脸认证快速认证失败五次 + * 需求号:无 + * 其他修改说明:无 + * commit id:059adfb + + -- Yang Min Wed, 12 Oct 2022 14:02:41 +0800 + +ukui-biometric-auth (3.20.0.10) v101; urgency=medium + + * BUG号:140637 【2203自适应升级2209】【生物特征工具】生物设备权限开启后,生物识别未勾选,但仍可以使用生物识别。 + 140617 【2203自适应升级2209】【冒烟2级】【生物特征工具】生物设备权限开启后,生物识别默认未勾选 + * 需求号:无 + * 其他修改说明:无 + * commit id:44d276f + + -- Yang Min Thu, 29 Sep 2022 20:58:32 +0800 + +ukui-biometric-auth (3.20.0.9) v101; urgency=medium + + * BUG号:140646 【藏文】【生物特征工具】【需求 9380】启动指纹驱动授权弹窗,添加指纹授权弹窗,空密码确认,提示乱码 + 141830 【PTOF】【提权】输入空密码时提示显示为乱码 + * 需求号:无 + * 其他修改说明:无 + * commit id:9fa8ae8 + + -- Yang Min Fri, 23 Sep 2022 18:15:06 +0800 + +ukui-biometric-auth (3.20.0.8) v101; urgency=medium + + * BUG号:139865 【藏文】生物特征录入指纹完成界面未完全汉化 + 136746 【生物特诊管理工具】【藏文】生物特征管理工具关于、帮助、授权弹框等界面未完全翻译成藏文 + * 需求号:无 + * 其他修改说明:无 + * commit id:3a39662 + + -- Yang Min Sat, 17 Sep 2022 10:46:44 +0800 + +ukui-biometric-auth (3.20.0.7) v101; urgency=medium + + * BUG号:136689 【锁屏】锁屏界面长按ctrl+shift+esc 可直接进入系统 + * 需求号:无 + * 其他修改说明:无 + * commit id:653d02f + + -- Yang Min Wed, 14 Sep 2022 15:33:27 +0800 + +ukui-biometric-auth (3.20.0.6) v101; urgency=medium + + * BUG号:136306 【分区编辑器】藏文版本下提权窗口输入错误密码会闪退 + * 需求号:无 + * 其他修改说明:无 + * commit id:bb31691 + + -- Yang Min Wed, 24 Aug 2022 19:12:28 +0800 + +ukui-biometric-auth (3.20.0.5) v101; urgency=medium + + * BUG号:136128 【锁屏】同时连点ESC与Enter键和可跳过锁屏界面进入桌面 + 136689 【锁屏】锁屏界面长按ctrl+shift+esc 可直接进入系统 + * 需求号:无 + * 其他修改说明:无 + * commit id:87d3b01 + + -- Yang Min Mon, 22 Aug 2022 18:51:42 +0800 + +ukui-biometric-auth (3.20.0.4) v101; urgency=medium + + * BUG号:130082 【生物特征管理工具】连续关闭生物设备指纹驱动后,提示更改设备状态失败,切换侧边栏导航提示服务已关闭,关闭应用再次打开,服务未启动 + 128098 【U盘启动器】授权窗口切换另一个管理员用户,错误密码提示未清除 + 133204 【生物识别认证】【x100】【通有】授权窗口处拔掉摄像头,授权窗口直接退出 + * 需求号:无 + * 其他修改说明:无 + * commit id:563f201 + + -- Yang Min Fri, 12 Aug 2022 18:06:14 +0800 + +ukui-biometric-auth (3.20.0.3) v101; urgency=medium + + * BUG号:129220 【账户保护】多次输错登录密码不会提示账户锁定 + 129153 【安全中心】默认账户锁定策略不生效 + * 需求号:无 + * 其他修改说明:无 + * commit id:804cfde + + -- Yang Min Mon, 01 Aug 2022 10:49:14 +0800 + +ukui-biometric-auth (3.20.0.2) v101; urgency=medium + + * BUG号:128655 【设计】授权验证提示失败和验证状态与设计期望不符 + 128663 【设计】提权界面在等待后断反馈时,无提示 + 125394 【登录选项】绑定微信后,鼠标移入分区编辑器授权窗口提示语,提示语显示不完整 + * 需求号:无 + * 其他修改说明:替换调用libukui-common接口为libkysdk-sysinfo接口 + * commit id:6562cbd + + -- Yang Min Fri, 15 Jul 2022 20:20:21 +0800 + +ukui-biometric-auth (3.20.0.1) v101; urgency=medium + + * BUG号:126383 【控制面板】【时间和日期】密码隐藏时,第一次在授权框中输入密码样式为圆点;输入密码错误后第二次输入密码样式为星号(预期:授权窗口隐藏密码样式不变,始终为圆点); + 125358 【分区编辑器】再次输入密码,密码不是明文 + * 需求号:无 + * 其他修改说明:无 + * commit id:0ad2367 + + -- Yang Min Tue, 05 Jul 2022 09:43:40 +0800 + +ukui-biometric-auth (1.2.0-1kylin60update3) v101; urgency=medium + + * BUG号:117501 【屏幕键盘】平板模式,授权窗口点击输入密码,屏幕键盘无法自动弹出(手动调出屏幕键盘后也无法弹出 + 117557 【用户授权】授权弹窗样式与设计稿不符 + * 需求号:无 + * 其他修改说明:无 + * commit id:e116557 + + -- Yang Min Tue, 28 Jun 2022 16:55:07 +0800 + +ukui-biometric-auth (3.20.0.0) v101; urgency=medium + + * BUG号:121957 【2107升级到2203系统】【系统登录】升级前录入指纹,升级后登录界面没有指纹登录选项 + * 需求号:无 + * 其他修改说明:无 + * commit id:0b7c654 + + -- Yang Min Thu, 16 Jun 2022 20:06:36 +0800 + +ukui-biometric-auth (1.2.0-1kylin60update2) v101; urgency=medium + + * BUG号:121957 【2107升级到2203系统】【系统登录】升级前录入指纹,升级后登录界面没有指纹登录选项 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Tue, 07 Jun 2022 17:39:18 +0800 + +ukui-biometric-auth (1.2.0-1kylin60update1) v101; urgency=medium + + * BUG号:111548 【授权】使用错误微信扫描,授权窗口文字出现重叠 + 113434 【生物特征管理工具】终端提权时,关闭生物特征总开关,仍然可以提权成功 + 113465 【提权】英文环境和深色主题下,授权窗口的提示显示不全,且颜色与设计稿不符 + 113738 【时间和日期】系统已录入人脸,绑定微信,修改时间服务器,来回切换授权方式,“器”字会跳到下一行且遮挡住下行内容 + 113924 【生物特征管理工具】接入指纹后,打开分区编辑器,授权界面会向下方扩展 + 114209 【提权】指纹和微信扫码同时存在时,禁用指纹后,输入错误密码,微信扫码和指纹识别消失 + 114757 【设计】【授权认证】输入密码验证提示文案未显示 + 115401 【x100】【通有】【提权】已录入一个指纹后,在再次录入指纹的提权界面进行睡眠时,会自动进行指纹认证失败操作 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Sat, 07 May 2022 14:48:05 +0800 + +ukui-biometric-auth (1.2.0-1kylin60) v101; urgency=medium + + * BUG号:110712 【用户提权】当修改polkit认证使用root用户时,polkit授权窗口显示的用户名为空 + 111524 【安全】授权窗口的口令输入框明文密码可以复制、剪切 + 113215 【分区编辑器】打卡分区编辑器,第一次输入错误密码授权,授权窗口抖动 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Thu, 31 Mar 2022 11:33:56 +0800 + +ukui-biometric-auth (1.2.0-1kylin59) v101; urgency=medium + + * BUG号:111548 【授权】使用错误微信扫描,授权窗口文字出现重叠 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Fri, 25 Mar 2022 10:06:47 +0800 + +ukui-biometric-auth (1.2.0-1kylin58) v101; urgency=medium + + * BUG号:106042 【安全中心】修改密码强度位32位后在控制面板删除用户,授权认证无法通过 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Thu, 17 Mar 2022 19:23:34 +0800 + +ukui-biometric-auth (1.2.0-1kylin57) v101; urgency=medium + + * BUG号:107825 【生物识别认证】【登录界面】UI设计有更新,需同步更新,涉及登录、锁屏界面,细节见步骤描述 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Wed, 16 Mar 2022 10:09:48 +0800 + +ukui-biometric-auth (1.2.0-1kylin56) v101; urgency=medium + + * BUG号:108387 【生物特征管理-指纹】打开终端执行sudo su后,不进行生物识别认证,直接关掉终端窗口;再次打开终端执行sudo su 发现不会提示进行生物识别认证了 + 102000 【polkit提权】【必现】同时接入人脸指纹设备时,在提权界面拔掉再插入人脸摄像头,认证选项不更新,仍仅为指纹无人脸 + 109632 【统一认证】网络状况不好情况下进行微信认证时,二维码置灰不显示,输入密码也会清空 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Fri, 11 Mar 2022 19:18:07 +0800 + +ukui-biometric-auth (1.2.0-1kylin55) v101; urgency=medium + + * BUG号:107825 【生物识别认证】【登录界面】UI设计有更新,需同步更新,涉及登录、锁屏界面,细节见步骤描述 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Fri, 04 Mar 2022 16:05:55 +0800 + +ukui-biometric-auth (1.2.0-1kylin54) v101; urgency=medium + + * BUG号:103501 【设置】【安全中心】【Freetest】改变账户的密码强度后,管理员授权界面提示信息显示时间太短 + 103963 【登录选项】断开网络后,解绑微信授权窗口一直闪烁网络连接失败 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Tue, 01 Mar 2022 17:13:24 +0800 + +ukui-biometric-auth (1.2.0-1kylin53) v101; urgency=medium + + * BUG号:103471 【登录】用户锁定倒计时结束后,提示认证失败 + 103662 【授权】深色模式下,授权窗口的密码明文显示眼睛未做高亮显示 + 104660 【提权】用户锁定后,密码输入框变短 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Wed, 26 Jan 2022 18:07:46 +0800 + +ukui-biometric-auth (1.2.0-1kylin52) v101; urgency=medium + + * BUG号:100365 【登录/锁屏】微信二维码登录的文案提示与设计稿不符 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Fri, 14 Jan 2022 18:00:55 +0800 + +ukui-biometric-auth (1.2.0-1kylin51) v101; urgency=medium + + * BUG号:98470 【生物识别】【polkit提权】【必现】机器连接两个指纹设备(亚略特和ft笔记本自带的ft9328)且均已录入指纹特征,此时polkit提权界面无法切换为人脸认证 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Thu, 30 Dec 2021 21:12:43 +0800 + +ukui-biometric-auth (1.2.0-1kylin50) v101; urgency=medium + + * BUG号:96179 【授权窗口】开启生物识别后,提权界面的“提权介绍”信息处未调整显示存在遮挡,且随着生物识别认证失败次数增加,文字处宽度变窄 + 97812 【生物识别】【polkit提权】【必现】字体为15号的中文环境,polkit提权界面选择扫码登录,“等待扫描二维码”提示显示不全 + 93161 【分区编辑器】人脸认证时移除摄像头,仍可以点击重试按钮 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Wed, 22 Dec 2021 18:49:56 +0800 + +ukui-biometric-auth (1.2.0-1kylin48) v101; urgency=medium + + * BUG号:92975 【账户信息】【用例198950】修改系统字体选择,账户界面授权窗口字体未改变 + 91697 【账户信息】【用例198952】修改系统字体,账户信息界面授权弹窗字体没有变化 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Mon, 13 Dec 2021 10:04:24 +0800 + +ukui-biometric-auth (1.2.0-1kylin47) v101; urgency=medium + + * BUG号:94749 【需求-统一认证-9368】使用微信成功登录后,进入锁屏界面依旧默认人脸认证 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Fri, 10 Dec 2021 21:03:00 +0800 + +ukui-biometric-auth (1.2.0-1kylin46) v101; urgency=medium + + * BUG号:93971 【SP2 UI走查】【登录/锁屏】微信二维码登录的文案提示与设计稿不符 + 94143 【生物识别-需求-8987】【polkit提权】【必现】勾选指纹设备为默认设备且指纹特征为空时,同时打开人脸识别且存在人脸特征。polkit提权仍默认使用指纹认证 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Thu, 09 Dec 2021 18:35:32 +0800 + +ukui-biometric-auth (1.2.0-1kylin45) v101; urgency=medium + + * BUG号:93674 【提权】输入其他管理员用户最大的错误密码次数后,不会提示用户已锁定 + 92964 【polkit提权】授权窗口的密码输入框未汉化 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Tue, 07 Dec 2021 18:11:43 +0800 + +ukui-biometric-auth (1.2.0-1kylin44) v101; urgency=medium + + * BUG号:93003 【统一认证】【必现】登录/锁屏/提权认证时,一种生物或扫码认证方式次数达到上限后,无法切换其他认证方式,只能用密码认证 + 90467 【需求-统一认证-9368】开机等待二维码显示后断开网络,扫码,下方提示为指纹且次数显示不正确 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Mon, 06 Dec 2021 16:55:02 +0800 + +ukui-biometric-auth (1.2.0-1kylin37) v101; urgency=medium + + * BUG号:无 + * 需求号:#9368 微信认证、登录、解锁功能 + * 其他修改说明:无 + * 其他修改影响域:无 + + -- Yang Min Mon, 08 Nov 2021 09:35:07 +0800 + +ukui-biometric-auth (1.2.0-1kylin36) v101; urgency=medium + + * 同步pam,修改授权相关bug + + -- lilin Thu, 04 Nov 2021 13:53:28 +0800 + +ukui-biometric-auth (1.2.0-1kylin35) v101; urgency=medium + + * bug#82903 【授权】在授权框输入错误密码后,密码明文功能失效 + + -- liuyuanpeng Sun, 26 Sep 2021 18:45:42 +0800 + +ukui-biometric-auth (1.2.0-1kylin34) v101; urgency=medium + + * bug#77597 + + -- liuyuanpeng Mon, 13 Sep 2021 20:28:19 +0800 + +ukui-biometric-auth (1.2.0-1kylin33) v101; urgency=medium + + * bug号:79437 锁定时间1分钟,偶尔闪现2分钟计数 + * 需求号:无 + * 其他:无 + + -- lilin Sat, 11 Sep 2021 16:25:11 +0800 + +ukui-biometric-auth (1.2.0-1kylin32) v101; urgency=medium + + * bug#77620 + + -- liuyuanpeng Sat, 04 Sep 2021 10:19:02 +0800 + +ukui-biometric-auth (1.2.0-1kylin31) v101; urgency=medium + + * bug#77749 + + -- liuyuanpeng Thu, 02 Sep 2021 20:00:58 +0800 + +ukui-biometric-auth (1.2.0-1kylin30) v101; urgency=medium + + * bug号:75318,75138 + * 需求号:7690 + * 其他:无 + + -- liudun Tue, 24 Aug 2021 10:05:21 +0800 + +ukui-biometric-auth (1.2.0-1kylin29) v101; urgency=medium + + * bug号:无 + * 需求号:无 + * 其他:字符适配 + + -- lilin Tue, 17 Aug 2021 16:44:08 +0800 + +ukui-biometric-auth (1.2.0-1kylin28) v101; urgency=medium + + * bug号:无 + * 需求号:无 + * 其他:更新授权界面3.0 + + -- lilin Mon, 16 Aug 2021 20:38:40 +0800 + +ukui-biometric-auth (1.2.0-1kylin27) v101; urgency=medium + + * bug号:无 + * 需求号:7167 + * 其他:无 + + -- lilin Thu, 12 Aug 2021 22:20:43 +0800 + +ukui-biometric-auth (1.2.0-1kylin26) v101; urgency=medium + + * 需求号:7690 + * 改动说明:人脸透传 + + -- liuyuanpeng Thu, 05 Aug 2021 21:34:51 +0800 + +ukui-biometric-auth (1.2.0-1kylin25) v101; urgency=medium + + * bug#57593 + + -- liuyuanpeng Wed, 14 Jul 2021 08:52:40 +0800 + +ukui-biometric-auth (1.2.0-1kylin24) v101; urgency=medium + + *解决bug:63025 【用例110404】【控制面板|时间日期】修改服务器地址,输入错误的密码后提示信息未汉化 + *需求号:无 + *其他改动说明:无 + + -- lilin Tue, 13 Jul 2021 20:59:52 +0800 + +ukui-biometric-auth (1.2.0-1kylin23) v101; urgency=medium + + * bug#57593 ,bug#51914 + + -- liuyuanpeng Fri, 18 Jun 2021 20:57:16 +0800 + +ukui-biometric-auth (1.2.0-1kylin22) v101; urgency=medium + + * bug#48700 插入拔除指纹等生物识别设备,通知中心的消息生物特诊无图标 + + -- liuyuanpeng Thu, 22 Apr 2021 09:26:58 +0800 + +ukui-biometric-auth (1.2.0-1kylin21) v101; urgency=medium + + * rebuild + + -- liuyuanpeng Fri, 09 Apr 2021 21:15:52 +0800 + +ukui-biometric-auth (1.2.0-1kylin19) v101; urgency=medium + + * bug#31629 终端提权时,在“请按下手指”提示后按下ctrl+c,再录入正确指纹,提示认证成功但实际没有提权成功 + + -- liuyuanpeng Mon, 22 Mar 2021 10:16:58 +0800 + +ukui-biometric-auth (1.2.0-1kylin18) v101; urgency=medium + + * bug#31124 不存在虹膜特征时,提权窗口选择“更多”后,仍有虹膜选项,且可以进入虹膜识别 + + -- liuyuanpeng Thu, 18 Mar 2021 10:30:51 +0800 + +ukui-biometric-auth (1.2.0-1kylin17) v101; urgency=medium + + * 打开生物特征管理工具开关不再需要权限 + + -- liuyuanpeng Sun, 14 Mar 2021 18:54:17 +0800 + +ukui-biometric-auth (1.2.0-1kylin16) v101; urgency=medium + + * bug#22059 将生物设为默认设备,重启服务,切换到密码认证,再切换到生物认证失败 + + -- liuyuanpeng Tue, 09 Mar 2021 09:41:44 +0800 + +ukui-biometric-auth (1.2.0-1kylin15) v101; urgency=medium + + * 解决bug#39524 重启服务的授权框概率性出现在桌面左上角 + + -- liuyuanpeng Thu, 04 Mar 2021 09:53:33 +0800 + +ukui-biometric-auth (1.2.0-1kylin14) v101; urgency=medium + + * 修改重启服务提示 + + -- liuyuanpeng Tue, 02 Mar 2021 09:20:17 +0800 + +ukui-biometric-auth (1.2.0-1kylin13) v101; urgency=medium + + * 解决ukui-greeter-wayland无法使用生物特征认证的问题 + + -- liuyuanpeng Sat, 30 Jan 2021 18:21:21 +0800 + +ukui-biometric-auth (1.2.0-1kylin12) v101; urgency=medium + + * 解决编译出错 + + -- liuyuanpeng Sat, 30 Jan 2021 14:32:16 +0800 + +ukui-biometric-auth (1.2.0-1kylin11) v101; urgency=medium + + * 完善pam模块 + + -- liuyuanpeng Sat, 30 Jan 2021 11:54:29 +0800 + +ukui-biometric-auth (1.2.0-1kylin10) v101; urgency=medium + + * 添加同时认证生物特征和密码的配置方法 + + -- liuyuanpeng Sat, 30 Jan 2021 10:25:03 +0800 + +ukui-biometric-auth (1.2.0-1kylin9) v101; urgency=medium + + * bug#31648 终端提权时,关闭生物特征总开关,仍然可以提权成功 + + -- liuyuanpeng Wed, 27 Jan 2021 09:17:08 +0800 + +ukui-biometric-auth (1.2.0-1kylin8) v101; urgency=medium + + * bug#27407 200%缩放下,授权窗口内容显示不完整 + + -- liuyuanpeng Mon, 04 Jan 2021 14:19:30 +0800 + +ukui-biometric-auth (1.2.0-1kylin7) v101; urgency=medium + + * bug#31116 普通用户进行提权操作时,使用policy提权,建议窗口显示当前的管理员用户,即使只存在一个管理员用户 + * bug#26131 存在多个管理员用户,在系统授权窗口中,切换不用管理员用户,授权界面闪烁 + + -- liuyuanpeng Sun, 03 Jan 2021 11:46:34 +0800 + +ukui-biometric-auth (1.2.0-1kylin6) v101; urgency=medium + + * bug#23754 已存在指纹特征,再次录入特征时在录入指纹窗口异常关闭应用,再次打开应用,之前的特征消失 + + -- liuyuanpeng Sat, 19 Dec 2020 13:52:45 +0800 + +ukui-biometric-auth (1.2.0-1kylin5) v101; urgency=medium + + * 隐藏详细按钮 + * 修改授权窗口图标 + + -- liuyuanpeng Sat, 28 Nov 2020 03:26:27 +0800 + +ukui-biometric-auth (1.2.0-1kylin4) v101; urgency=medium + + * bug#20309 授权窗口在任务栏窗口没有图标 + + -- liuyuanpeng Tue, 29 Sep 2020 11:14:21 +0800 + +ukui-biometric-auth (1.2.0-1kylin3) v101; urgency=medium + + * bug#18011 【授权】窗口中详细内容显示不完整 + + -- liuyuanpeng Mon, 14 Sep 2020 17:21:59 +0800 + +ukui-biometric-auth (1.2.0-1kylin2) v101; urgency=medium + + * 修复第一次启动生物识别管理工具,打开生物识别开关后, + * 生物识别管理工具卡死的问题 + + -- liuyuanpeng Thu, 04 Jun 2020 14:49:23 +0800 + +ukui-biometric-auth (1.2.0-1kylin1) v101; urgency=medium + + * rebuild + + -- liuyuanpeng Sat, 16 May 2020 15:57:33 +0800 + +ukui-biometric-auth (1.2.0-1) unstable; urgency=medium + + * New upstream release. + * debian/control: + - Bump standards-vertion to 4.5.0. + + -- handsome_feng Mon, 24 Feb 2020 22:07:07 +0800 + +ukui-biometric-auth (1.0.4-1) unstable; urgency=medium + + * Upload to unstable. + * New upstream release. + * debian/control: + - Bump standards-version to 4.4.1. No changes needed. + * debian/{compat,control}: + - Use debhelper-compat notation. Bump to DH compat level + version 12. + + -- handsome_feng Sat, 30 Nov 2019 17:16:35 +0800 + +ukui-biometric-auth (1.0.3-2) experimental; urgency=medium + + * Debian/control: + - libpam-biometric: Breaks and Replaces ukui-polkit(<<1.0.3) + (Closes: #925377) + + -- handsome_feng Wed, 27 Mar 2019 11:58:32 +0800 + +ukui-biometric-auth (1.0.3-1) experimental; urgency=medium + + * The dialog of su or sudo is replaced by command output. + * Autorestart biometric authentication if authentication failed. + * Change the path of some config files. + * Add biodrvctl script to control driver status. + * Add fr/pt/ru/es translation. + * Add a series of biometric image. + * migrate to cmake. + * Fix the bug that polit can't load qm file. + * Fix the bug that polkit can't load icon. + * Fix the bug that polkit doesn't exit when logout. + * debian/control: + - Now ukui-polkit provides polkit-1-auto-agent. + - Bump standards-version to 4.3.0. + + -- handsome_feng Thu, 21 Mar 2019 10:55:27 +0800 + +ukui-biometric-auth (1.0.2-1) unstable; urgency=medium + + * Initial release. (Closes: #908469) + + -- handsome_feng Tue, 25 Sep 2018 15:37:06 +0800 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..717be64 --- /dev/null +++ b/debian/control @@ -0,0 +1,47 @@ +Source: ukui-biometric-auth +Section: admin +Priority: optional +Maintainer: Kylin Team +Uploaders: handsome_feng +Build-Depends: debhelper-compat (= 12), + cmake (>= 2.6), + qtbase5-dev, + libpam-dev, + libglib2.0-dev, + libopencv-dev, + libpolkit-qt5-1-dev, + qttools5-dev, + qttools5-dev-tools, + libqt5svg5-dev, + libgsettings-qt-dev, + pkg-config, + libkysdk-sysinfo-dev +Standards-Version: 4.5.0 +Rules-Requires-Root: no +Homepage: https://github.com/ukui/ukui-biometric-auth +Vcs-Git: https://github.com/ukui/ukui-biometric.git +Vcs-Browser: https://github.com/ukui/ukui-biometric-auth + +Package: libpam-biometric +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Suggests: biometric-auth +Breaks: ukui-polkit (<<1.0.3) +Replaces: ukui-polkit (<<1.0.3) +Description: Insertable authentication module for PAM + The indispensable part for biometric authentication in + ukui desktop environment. + This package contains a modules for PAM. + +Package: ukui-polkit +Architecture: any +Depends: policykit-1, + libpam-biometric(>=3.20.0.10), + ${shlibs:Depends}, + ${misc:Depends} +Suggests: biometric-auth +Provides: polkit-1-auth-agent +Description: UKUI authentication agent for PolicyKit-1 + The ukui-polkit package supports general authentication and + biometric authentication that the service is provided by the + biometric-auth package. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..c833905 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,23 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: ukui-biometric-auth +Upstream-Contact: yanghao@kylinos.cn +Source: https://github.com/ukui/ukui-biometric-auth + +Files: * +Copyright: 2018, yanghao +License: GPL-3+ + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Genaral Public License for more details. + . + You should have received a copy og the GNU General Public License + along with this program. If not, see + . + On Debian systems, the complete text of the GNU General + Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". diff --git a/debian/libpam-biometric.install b/debian/libpam-biometric.install new file mode 100644 index 0000000..775017f --- /dev/null +++ b/debian/libpam-biometric.install @@ -0,0 +1,10 @@ +/lib/security/* +/usr/bin/* +/usr/share/pam-configs/* +/usr/share/polkit-1/actions/*.policy +/usr/share/ukui-biometric/images/ +/usr/share/ukui-biometric/i18n_qm/*.qm +/usr/share/ukui-biometric/i18n_qm/bioauth-bin/*.qm +/usr/share/ukui-biometric/ukui-biometric.conf +/usr/share/dbus-1/system-services/org.ukui.UniauthBackend.service +/etc/dbus-1/system.d/org.ukui.UniauthBackend.conf diff --git a/debian/libpam-biometric.manpages b/debian/libpam-biometric.manpages new file mode 100644 index 0000000..df02218 --- /dev/null +++ b/debian/libpam-biometric.manpages @@ -0,0 +1,3 @@ +man/bioctl.1 +man/bioauth.1 +man/biodrvctl.1 diff --git a/debian/libpam-biometric.postinst b/debian/libpam-biometric.postinst new file mode 100644 index 0000000..46f1a0d --- /dev/null +++ b/debian/libpam-biometric.postinst @@ -0,0 +1,54 @@ +#!/bin/sh +set -e +#DEBHELPER# + +pam-auth-update --package + +#update default conf +config_file=/etc/biometric-auth/ukui-biometric.conf + +delimeter='=' + +get_opt(){ + file=$1 + section=$2 + key=$3 + val=$(awk -F "$delimeter" '/\['${section}'\]/{a=1}(a==1 && "'${key}'"==$1){print $2;exit}' ${file}) + echo ${val} +} + +is_key_exist(){ + file=$1 + section=$2 + key=$3 + is_exist=$(awk -F "$delimeter" '/\['${section}'\]/{a=1}(a==1 && "'${key}'"==$1){print '1';exit}' ${file}) + echo ${is_exist} +} + +set_opt(){ + file=$1 + section=$2 + key=$3 + val=$4 + contain_section=$(awk '/\['${section}'\]/ {print NR}' ${file}) + if [ ${#contain_section} -gt 0 ]; then + is_exist=$(is_key_exist $file $section $key) + if [ "${is_exist}" = "1" ]; then + awk -F "$delimeter" '/\['${section}'\]/{a=1}(a==1 && "'${key}'"==$1){gsub($2,"'${val}'");a=0} {print $0}' ${file} 1<>${file} + else + sed -i "s/\[${section}\]/\[${section}\]\n${key}\=${val}/g" ${file} + fi + else + echo -e "\n[${section}]\n${key}=${val}" >> ${file} + sed -i "s/\-e//g" ${file} + fi +} + +if [ ! -f ${config_file} ]; then + mkdir -p /etc/biometric-auth + cp /usr/share/ukui-biometric/ukui-biometric.conf ${config_file} +else + set_opt ${config_file} General UseFirstDevice true + set_opt ${config_file} General MaxFailedTimes 5 + set_opt ${config_file} Functions EnableQRCode true +fi diff --git a/debian/libpam-biometric.prerm b/debian/libpam-biometric.prerm new file mode 100644 index 0000000..f9e3f3a --- /dev/null +++ b/debian/libpam-biometric.prerm @@ -0,0 +1,6 @@ +#!/bin/sh +set -e + +#DEBHELPER# + +pam-auth-update --package --remove pam-biometric diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..ca7ef12 --- /dev/null +++ b/debian/rules @@ -0,0 +1,8 @@ +#!/usr/bin/make -f + +export DEB_BUILD_MAINT_OPTIONS = hardening=+all +export QT_SELECT := qt5 +export NO_PKG_MANGLE=1 + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/debian/source/include-binaries b/debian/source/include-binaries new file mode 100644 index 0000000..1b127ca --- /dev/null +++ b/debian/source/include-binaries @@ -0,0 +1,9 @@ +images/FingerPrint.gif +images/FingerPrint.png +images/FingerVein.gif +images/FingerVein.png +images/icon.png +images/Iris.gif +images/Iris.png +images/VoicePrint.gif +images/VoicePrint.png diff --git a/debian/ukui-polkit.install b/debian/ukui-polkit.install new file mode 100644 index 0000000..0f930a8 --- /dev/null +++ b/debian/ukui-polkit.install @@ -0,0 +1,3 @@ +/etc/xdg/* +/usr/lib/* +/usr/share/ukui-biometric/i18n_qm/polkit/*.qm diff --git a/debian/watch b/debian/watch new file mode 100644 index 0000000..b981626 --- /dev/null +++ b/debian/watch @@ -0,0 +1,3 @@ +version=4 +opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/ukui-biometric-auth-$1\.tar\.gz/ \ + https://github.com/ukui/ukui-biometric-auth/releases .*/v?(\d\S+)\.tar\.gz diff --git a/pam-biometric/CMakeLists.txt b/pam-biometric/CMakeLists.txt index b30abe0..2c82306 100644 --- a/pam-biometric/CMakeLists.txt +++ b/pam-biometric/CMakeLists.txt @@ -39,7 +39,7 @@ set_target_properties(pam_biometric PROPERTIES PREFIX "") install(TARGETS pam_biometric DESTINATION /lib/security) install(FILES pam-configs/pam-biometric DESTINATION /usr/share/pam-configs) -install(FILES data/ukui-biometric.conf DESTINATION /etc/biometric-auth) +install(FILES data/ukui-biometric.conf DESTINATION /usr/share/ukui-biometric) install(FILES ${PROJECT_BINARY_DIR}/data/org.freedesktop.plicykit.pkexec.bioctl-helper.policy ${PROJECT_BINARY_DIR}/data/org.freedesktop.plicykit.pkexec.biodrvctl.policy diff --git a/pam-biometric/data/org.freedesktop.plicykit.pkexec.bioctl-helper.policy.in b/pam-biometric/data/org.freedesktop.plicykit.pkexec.bioctl-helper.policy.in index f10b42a..62c21b6 100644 --- a/pam-biometric/data/org.freedesktop.plicykit.pkexec.bioctl-helper.policy.in +++ b/pam-biometric/data/org.freedesktop.plicykit.pkexec.bioctl-helper.policy.in @@ -7,8 +7,10 @@ Run the biometric authentication control tool 运行生物识别认证控制工具 + འཁོར་སྐྱོད་སྐྱེ་དངོས་ཀྱི་ངོས་འཛིན་ཁས་ལེན་ཚོད་འཛིན་ཡོ་བྱད།། Authentication is required to enable or disable biometric authentication 开启或关闭生物识别认证需要进行身份验证 + སྒོ་རྒྱག་པའམ་ཡང་ན་སྒོ་རྒྱག་པའི་སྐྱེ་དངོས་ངོས་འཛིན་བདེན་དཔངར་སྤྲོད་བྱེད་པར་ཐོབ་ཐང་གི་ཚོད་ལྟསར་སྤྲོད་བྱ་དགོས། stock_person no diff --git a/pam-biometric/data/org.freedesktop.plicykit.pkexec.biodrvctl.policy.in b/pam-biometric/data/org.freedesktop.plicykit.pkexec.biodrvctl.policy.in index 42487bd..aed20c3 100644 --- a/pam-biometric/data/org.freedesktop.plicykit.pkexec.biodrvctl.policy.in +++ b/pam-biometric/data/org.freedesktop.plicykit.pkexec.biodrvctl.policy.in @@ -7,8 +7,10 @@ Run the biometric device driver control tool 运行生物识别设备驱动控制工具 - Authentication is required to change the status of biometric device's driver - 改变生物识别设备驱动状态需要进行身份验证 + སྐྱ་དངོས་དབྱེ་འབྱེད་སྒྲག་ཆས་ཀྱི་ཁ་ལོ་བའི་ཚོད་འཛིན་ཡོ་བྱད་ + Authentication is required to change the status of biometric device's driver + 改变生物识别设备驱动状态需要进行身份验证 + སྐྱ་དངོས་དབྱེ་འབྱེད་སྒྲག་ཆས་ཀྱི་ཁ་ལོ་བའི་གནས་ཚུལ་ལ་འགྱུར་ལྡོག་གཏོང་བར་བདེན་དཔང་ར་སྤྲད་བྱ་དགོས། stock_person auth_admin diff --git a/pam-biometric/data/org.freedesktop.plicykit.pkexec.biorestart.policy.in b/pam-biometric/data/org.freedesktop.plicykit.pkexec.biorestart.policy.in index 3ca842b..cbad164 100644 --- a/pam-biometric/data/org.freedesktop.plicykit.pkexec.biorestart.policy.in +++ b/pam-biometric/data/org.freedesktop.plicykit.pkexec.biorestart.policy.in @@ -7,8 +7,10 @@ Restart Service 重启生物特征服务 - Authentication is required to restart biometric service - 重启生物特征服务需要身份验证 + བསྐྱར་དུ་ཞབས་འདེགས་ཞུ་བ + Authentication is required to restart biometric service + 重启生物特征服务需要身份验证 + སྐྱ་དངོས་དབྱེ་འབྱེད་ཞབས་ཞུ་སླར་གསོ་བྱེད་པར་བདེན་དཔང་ར་སྤྲད་བྱ་དགོས། stock_person auth_admin diff --git a/pam-biometric/data/ukui-biometric.conf b/pam-biometric/data/ukui-biometric.conf index 50e1c44..e96090b 100644 --- a/pam-biometric/data/ukui-biometric.conf +++ b/pam-biometric/data/ukui-biometric.conf @@ -1,5 +1,6 @@ [General] EnableAuth=false +EnableAuthApp=63 DefaultDevice= DoubleAuth=false UserBind=false diff --git a/pam-biometric/pam_biometric.c b/pam-biometric/pam_biometric.c index cb92642..066d2ff 100644 --- a/pam-biometric/pam_biometric.c +++ b/pam-biometric/pam_biometric.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,8 @@ #include #include +#define USER_CONFIG_FILE "/home/%s/.biometric_auth/ukui_biometric.conf" + /* Declare log function */ extern int enable_debug; extern char *log_prefix; @@ -50,28 +53,70 @@ static void signal_handler(int signo) logger("signal_handler is triggered\n"); } +int enable_biometric_authentication_app() +{ + char conf_file[] = GET_STR(CONFIG_FILE); + FILE *file; + char line[1024]; + int i; + int is_enable = 0; + + if((file = fopen(conf_file, "r")) == NULL){ + logger("open configure file failed: %s\n", strerror(errno)); + return 1; + } + + while(fgets(line, sizeof(line), file)) { + i = sscanf(line, "EnableAuthApp=%d\n", &is_enable); + if(i > 0) { + logger("EnableAuthApp=%d\n", is_enable); + break; + } + } + fclose(file); + return is_enable; +} + /* * Check if the service should use biometric authentication */ int service_filter(char *service) { + //int is_enable = enable_biometric_authentication_app(); + + //syslog(LOG_INFO,"is_enable = %d service = %s\n",is_enable,service); if (strcmp(service, "lightdm") == 0) { int ret = system("/bin/chmod -f a+wr /tmp/bio.log"); (void)ret; /* Suppress gcc ignoring return value warning */ + //if(is_enable & 1 == 0) + // return 0; + return 1; + } + if (strcmp(service, "ukui-screensaver-qt") == 0){ + //if((is_enable & (1<<1)) == 0) + // return 0; return 1; } - if (strcmp(service, "ukui-screensaver-qt") == 0) + if (strcmp(service, "polkit-1") == 0){ + //if((is_enable & (1<<2)) == 0) + // return 0; return 1; - if (strcmp(service, "sudo") == 0) - return 1; - if (strcmp(service, "login") == 0) + } + if (strcmp(service, "sudo") == 0){ + //if((is_enable & (1<<3)) == 0) + // return 0; return 1; - if (strcmp(service, "su") == 0) + } + if (strcmp(service, "su") == 0){ + //if((is_enable & (1<<4)) == 0) + // return 0; return 1; -// if (strcmp(service, "mate-screensaver") == 0) -// return 1; - if (strcmp(service, "polkit-1") == 0) + } + if (strcmp(service, "login") == 0){ + //if((is_enable & (1<<5)) == 0) + // return 0; return 1; + } #ifdef ENABLE_BIOTEST if (strcmp(service, "biotest") == 0) return 1; @@ -104,11 +149,11 @@ int call_conversation(pam_handle_t *pamh, int msg_style, char *msg, char *resp) status = conv_struct->conv(1, message, &response, conv_struct->appdata_ptr); logger("Finish conv callback function\n"); - if (resp) - strcpy(resp, response->resp); + if (resp && response->resp) + strcpy(resp, response->resp); /* Use typecast to suppress gcc warnings */ free((void *)message[0]); - if (response) + if (response->resp) free(response->resp); free(response); @@ -215,9 +260,9 @@ int parent(int pid, pam_handle_t *pamh, int need_call_conv) logger("The GUI-Child process terminate abnormally.\n"); if (bio_result == BIO_SUCCESS) { - if(!enable_biometric_authentication(pamh) && !enable_qrcode_authentication(pamh)) { - logger("disable biometric authentication.\n"); - return PAM_SYSTEM_ERR; + if(!enable_biometric_authentication(pamh) && !enable_qrcode_authentication(pamh)) { + logger("disable biometric authentication.\n"); + return PAM_SYSTEM_ERR; } logger("pam_biometric.so return PAM_SUCCESS\n"); return PAM_SUCCESS; @@ -395,18 +440,47 @@ int enable_by_polkit() int enable_biometric_authentication(pam_handle_t *pamh) { + char *username = NULL; + int is_found = 0; + int is_auth_enable = 0; + pam_get_item(pamh, PAM_USER, (const void **)&username); + if (username) { + char conf_file_user[256]; + snprintf(conf_file_user, 255, USER_CONFIG_FILE, username); + FILE *file = NULL; + char line[1024], is_enable[16]; + int i; + if((file = fopen(conf_file_user, "r")) == NULL){ + logger("open configure file failed: %s\n", strerror(errno)); + } else { + while(fgets(line, sizeof(line), file)) { + i = sscanf(line, "EnableAuth=%15s\n", is_enable); + if(i > 0) { + logger("EnableAuth=%s\n", is_enable); + is_found = 1; + break; + } + } + fclose(file); + if(!strcmp(is_enable, "true")) + is_auth_enable = 1; + } + } + if (is_found != 0) { + return is_auth_enable; + } + char conf_file[] = GET_STR(CONFIG_FILE); FILE *file; char line[1024], is_enable[16]; int i; - if((file = fopen(conf_file, "r")) == NULL){ logger("open configure file failed: %s\n", strerror(errno)); return 0; } while(fgets(line, sizeof(line), file)) { - i = sscanf(line, "EnableAuth=%s\n", is_enable); + i = sscanf(line, "EnableAuth=%15s\n", is_enable); if(i > 0) { logger("EnableAuth=%s\n", is_enable); break; @@ -421,18 +495,47 @@ int enable_biometric_authentication(pam_handle_t *pamh) int enable_qrcode_authentication(pam_handle_t *pamh) { + char *username = NULL; + int is_found = 0; + int is_auth_enable = 0; + pam_get_item(pamh, PAM_USER, (const void **)&username); + if (username) { + char conf_file_user[256]; + snprintf(conf_file_user, 255, USER_CONFIG_FILE, username); + FILE *file = NULL; + char line[1024], is_enable[16]; + int i; + if((file = fopen(conf_file_user, "r")) == NULL){ + logger("open configure file failed: %s\n", strerror(errno)); + } else { + while(fgets(line, sizeof(line), file)) { + i = sscanf(line, "EnableQRCode=%15s\n", is_enable); + if(i > 0) { + logger("EnableQRCode=%s\n", is_enable); + is_found = 1; + break; + } + } + fclose(file); + if(!strcmp(is_enable, "true")) + is_auth_enable = 1; + } + } + if (is_found != 0) { + return is_auth_enable; + } + char conf_file[] = GET_STR(CONFIG_FILE); FILE *file; char line[1024], is_enable[16]; int i; - if((file = fopen(conf_file, "r")) == NULL){ logger("open configure file failed: %s\n", strerror(errno)); return 0; } while(fgets(line, sizeof(line), file)) { - i = sscanf(line, "EnableQRCode=%s\n", is_enable); + i = sscanf(line, "EnableQRCode=%15s\n", is_enable); if(i > 0) { logger("EnableQRCode=%s\n", is_enable); break; @@ -502,8 +605,6 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, return PAM_IGNORE; } - - /* Different services use different processing function */ if (strcmp(service, "lightdm") == 0) { char buf[128]; diff --git a/pam-biometric/utils/bioctl b/pam-biometric/utils/bioctl index 7e2d806..0c15640 100755 --- a/pam-biometric/utils/bioctl +++ b/pam-biometric/utils/bioctl @@ -3,11 +3,11 @@ # Usage: bioctl status|enable|disable if [ "$1" = "enable" ]; then - pkexec /usr/bin/bioctl-helper enable + pkexec /usr/bin/bioctl-helper enable $2 elif [ "$1" = "disable" ]; then - pkexec /usr/bin/bioctl-helper disable + pkexec /usr/bin/bioctl-helper disable $2 elif [ "$1" = "status" ]; then - /usr/bin/bioctl-helper status + /usr/bin/bioctl-helper status $2 else echo "Usage: bioctl status|enable|disable" fi diff --git a/pam-biometric/utils/bioctl-helper b/pam-biometric/utils/bioctl-helper index 07095a3..ebba384 100755 --- a/pam-biometric/utils/bioctl-helper +++ b/pam-biometric/utils/bioctl-helper @@ -23,6 +23,13 @@ if [ ! -f $CONFIG_FILE ]; then fi contain_key=`grep -c "^EnableAuth=" $CONFIG_FILE` +contain_key_app=`grep -c "^EnableAuthApp=" $CONFIG_FILE` +greeter=1 +screensaver=$[1<<1] +polkit=$[1<<2] +sudo=$[1<<3] +su=$[1<<4] +login=$[1<<5] if [ "$1" = "enable" ]; then test_privilege @@ -34,25 +41,158 @@ if [ "$1" = "enable" ]; then #执行 pam-auth-update 了。 #pam-auth-update --package pam-biometric - - if [ "$contain_key" = "1" ]; then + if [[ $# > 1 ]] && [[ $2 = "greeter" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app | $greeter ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=63" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "screensaver" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app | $screensaver ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=63" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "sudo" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app | $sudo ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=63" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "polkit" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app | $polkit ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=63" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "su" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app | $su ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=63" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "login" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app | $login ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=63" >> $CONFIG_FILE + fi + elif [ "$contain_key" = "1" ]; then sed -i 's/^EnableAuth=[a-zA-Z0-9]*/EnableAuth=true/g' $CONFIG_FILE else echo "EnableAuth=true" >> $CONFIG_FILE fi elif [ "$1" = "disable" ]; then test_privilege - if [ "$contain_key" = "1" ]; then + if [[ $# > 1 ]] && [[ $2 = "greeter" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app & $[~$greeter] ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=0" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "screensaver" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app & $[ ~$screensaver ]] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=0" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "sudo" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app & $[ ~$sudo ] ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=0" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "polkit" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app & $[~$polkit] ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=0" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "su" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app & $[~$su] ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=0" >> $CONFIG_FILE + fi + elif [[ $# > 1 ]] && [[ $2 = "login" ]]; then + if [ "$contain_key_app" = "1" ]; then + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=$[ $cur_status_app & $[~$login] ] + sed -i "s/^EnableAuthApp=[a-zA-Z0-9]*/EnableAuthApp=$cur_status_app/g" $CONFIG_FILE + else + echo "EnableAuthApp=0" >> $CONFIG_FILE + fi + elif [ "$contain_key" = "1" ]; then sed -i 's/^EnableAuth=[a-zA-Z0-9]*/EnableAuth=false/g' $CONFIG_FILE else echo "EnableAuth=false" >> $CONFIG_FILE fi elif [ "$1" = "status" ]; then - cur_status=`sed '/^EnableAuth/!d;s/.*=//' $CONFIG_FILE` - if [ "$cur_status" = "true" ]; then - echo "enable" + cur_status=`sed '/^EnableAuth=/!d;s/.*=//' $CONFIG_FILE` + cur_status_app=`sed '/^EnableAuthApp=/!d;s/.*=//' $CONFIG_FILE` + + if [[ $# > 1 ]] && [[ $2 = "greeter" ]];then + if [ $[ $[cur_status_app] & $[greeter] ] = $greeter ]; then + echo "enable" + else + echo "disable" + fi + elif [[ $# > 1 ]] && [[ $2 = "screensaver" ]];then + if [ $[$cur_status_app & $screensaver] = $screensaver ]; then + echo "enable" + else + echo "disable" + fi + elif [[ $# > 1 ]] && [[ $2 = "sudo" ]];then + if [ $[$cur_status_app & $sudo] = $sudo ]; then + echo "enable" + else + echo "disable" + fi + elif [[ $# > 1 ]] && [[ $2 = "polkit" ]];then + if [ $[$cur_status_app & $polkit] = $polkit ]; then + echo "enable" + else + echo "disable" + fi + elif [[ $# > 1 ]] && [[ $2 = "su" ]];then + if [ $[$cur_status_app & $su] = $su ]; then + echo "enable" + else + echo "disable" + fi + elif [[ $# > 1 ]] && [[ $2 = "login" ]];then + if [ $[$cur_status_app & $login] = $login ]; then + echo "enable" + else + echo "disable" + fi + elif [ "$cur_status" = "true" ]; then + echo "enable" else - echo "disable" + echo "disable" fi else echo "Usage: bioctl status|enable|disable" diff --git a/pam-biometric/utils/biodrvctl b/pam-biometric/utils/biodrvctl index 383788d..9e4454b 100755 --- a/pam-biometric/utils/biodrvctl +++ b/pam-biometric/utils/biodrvctl @@ -35,6 +35,7 @@ else fi if [ $? -eq 0 ]; then + systemctl reset-failed biometric-authentication.service systemctl restart biometric-authentication.service fi diff --git a/polkit-agent/CMakeLists.txt b/polkit-agent/CMakeLists.txt index 8b7d6f0..bdfcbf4 100644 --- a/polkit-agent/CMakeLists.txt +++ b/polkit-agent/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.6) project(ukui-polkit-agent) pkg_check_modules(QGS REQUIRED gsettings-qt) +pkg_check_modules(KDKINFO REQUIRED kysdk-sysinfo) find_package(PolkitQt5-1 REQUIRED 0.103.0) find_package(Qt5 COMPONENTS Core Widgets DBus X11Extras Xml Network Svg) @@ -18,11 +19,17 @@ configure_file( include_directories( ${QGS_INCLUDE_DIRS} + ${KDKINFO_INCLUDE_DIRS} ) +link_directories( + ${KDKINFO_LIBRARY_DIRS} + ) + set(EXTRA_LIBS ${EXTRA_LIBS} ${QGS_LIBRARIES} + ${KDKINFO_LIBRARIES} ) include_directories( @@ -42,6 +49,7 @@ set(polkit_SRCS src/users.cpp src/pam-tally.c src/modeButton.cpp + src/kalabel.cpp ../common/generic.cpp ) diff --git a/polkit-agent/i18n_ts/bo.ts b/polkit-agent/i18n_ts/bo.ts index 2ec7e24..e29f1bf 100644 --- a/polkit-agent/i18n_ts/bo.ts +++ b/polkit-agent/i18n_ts/bo.ts @@ -9,180 +9,185 @@ - - - + + + Biometric - + use password - - + + Cancel - - + + Authenticate - + Authentication - - + + Failed to verify %1, please enter password to unlock - - + + Unable to verify %1, please enter password to unlock - + Failed to verify %1, you still have %2 verification opportunities - - NET Exception - - - - + Please enter your password or enroll your fingerprint - + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + + + + A program is attempting to perform an action that requires privileges.It requires authorization to perform the action. - + Password: - + _Password: - + _Password: - - - - + + + + Account locked, - + days left - + hours left - + minutes left - + seconds left - - + + Password cannot be empty - - + + Use password - - - + + + Please try again in %1 minutes. - - - + + + Please try again in %1 seconds. - - - - + + + + Account locked permanently. - + Verify face recognition or enter password to unlock - + Press fingerprint or enter password to unlock - + Verify voiceprint or enter password to unlock - + Verify finger vein or enter password to unlock - + Verify iris or enter password to unlock - + Use the bound wechat scanning code or enter the password to unlock - + Input Password - + + Abnormal network + + + + Authentication failed, please try again. @@ -190,17 +195,17 @@ PolkitListener - + Another client is already authenticating, please try again later. - + Authentication failure, please try again. - + Password input error! diff --git a/polkit-agent/i18n_ts/bo_CN.ts b/polkit-agent/i18n_ts/bo_CN.ts index b038161..59dbbc7 100644 --- a/polkit-agent/i18n_ts/bo_CN.ts +++ b/polkit-agent/i18n_ts/bo_CN.ts @@ -1,194 +1,421 @@ + + BioAuthWidget + + Retry + 重试 + + + %1 too many unsuccessful attempts,please enter password. + %1验证失败达最大次数,请使用密码登录 + + + %1 authentication failure,there are still %2 remaining opportunities + %1认证失败,还剩%2次尝试机会 + + + Please use wechat to scan the code + 请使用微信扫码 + + + + BioDevices + + FingerPrint + 指纹 + + + FingerVein + 指静脉 + + + Iris + 虹膜 + + + Face + 人脸 + + + VoicePrint + 声纹 + + + Wechat + 微信 + + + QRCode + 二维码 + + + + LoginOptionsWidget + + Login Options + 登录选项 + + + Wechat + 微信 + + MainWindow - Form - ནས་འོང་བ། - - - days left - ཟྭ་འབྱེད་པ། - - - Please enter your password or enroll your fingerprint - གསང་ཨང་མནོན་པའམ་མཛུབ་རིམ་མནོན་རོགས། - - - Authenticate - ར་སྤྲོད། - - - in authentication, please wait... - བདེན་དཔང་ངོས་འཛིན་སྒང་ཡིན། ཁྱུག་ཙམ་སྒུག་དང་། - - + Authentication - གསལ་འབྱེད་ར་སྤྲོད། - - - Cancel - མེད་པར་བཟོ་བ - - - Description: - གསལ་བཤད།: - - - Biometric - སྐྱེ་དངོས་བརྟག་དཔྱད་སྤྱོད་པ། - - - Too many unsuccessful attempts,please enter password. - མཛུབ་རིས་ར་སྤྲོད་ཕམ་ཉེས་ཚད་ཆེས་ཆེ་ལས་བརྒལ་བ། ཁྱོས་གསང་ཨང་བཀོལ་ནས་ཟྭ་འབྱེད་རོགས། - - - Action: - འགུལ་སྟངས།: + བདེན་དཔང་ར་སྤྲོད་ Fingerprint authentication failed, you still have %1 verification opportunities - མཛུབ་རིས་ར་སྤྲོད་ཕམ་ཉེས་བྱུང་། ཁྱོད་ལ་ད་དུང་གོ་སྐབས་གཅིག་ཡོད། + 指纹验证失败,您还有%1次尝试机会 - Polkit.caller-pid: - Polkit.caller-pid: + + Form + + + + More + 更多 + + + Restart + 重新开始 + + + Password + 密码 + + + + + + Biometric + སྐྱེ་དངོས་རིག་པ། + + + + use password + གསང་གྲངས་བེད་སྤྱོད་བྱ་དགོས + + + DeviceType: + 设备类型: + + + Back + 返回 + + + Details + 详细 + + + Action Id: + 动作: + + + Description: + 描述: Polkit.subject-pid: Polkit.subject-pid: - Account locked, - རྩིས་ཐེམ་ཟྭ་བརྒྱབ་ཟིན། + Retry + 重试 - hours left - ཆུ་ཚོད་གཅིག་རྗེས་ནས་ཟྭ་འབྱེད་པ། - - - An application is attempting to perform an action that requires privileges. Authentication is required to perform this action. - བྱ་རིམ་ཞིག་གིས་ཁྱད་དབང་དགོས་པའི་འགུལ་སྟངས་ཤིག་ལག་བསྟར་བྱེད་ཚོད་བྱེད་པ། དབང་སྤྲད་ནས་འགུལ་སྟངས་འདི་ལག་བསྟར་བྱ། - - - Details - ཆ་འཕྲིན་ཞིབ་ཕྲ། - - - Password: - གསང་ཨང་། - - - minutes left - སྐར་མ་གཅིག་རྗེས་ནས་ཟྭ་འབྱེད་པ། - - - Authentication failed, please try again. - བདེན་དཔང་ངོས་འཛིན་ཕམ་ཉེས་བྱུང་། ཡང་བསྐྱར་ཚོད་ལྟ་བྱོས། + Device types: + 设备类型: Vendor: - བཟོ་གྲྭ: + 发行商: - seconds left - སྐར་ཆའི་རྗེས་ནས་ཟྭ་འབྱེད་པ། + Action: + 动作: - Password cannot be empty - གསང་གྲངས་སྟོང་པ་ཡིན་མི་རུང་། + Polkit.caller-pid: + Polkit.caller-pid: - use password - + + + Cancel + ཕྱིར་འཐེན། + + + Authenticate + བདེན་དཔང་ར་སྤྲོད་བྱ་དགོས + + + + Use password - + གསང་གྲངས་བེད་སྤྱོད་བྱ་དགོས + Auth + 授权 + + + Too many unsuccessful attempts,please enter password. + 指纹验证失败达最大次数,请使用密码解锁 + + + %1 authentication failure,there are still %2 remaining opportunities + %1认证失败,还剩%2次尝试机会 + + + %1 too many unsuccessful attempts,please enter password. + %1验证失败达最大次数,请使用密码登录 + + + in authentication, please wait... + 认证中,请稍等... + + + + + Please try again in %1 minutes. - + ཁྱོད་ཀྱིས་ཡང་བསྐྱར་ཐེངས་གཅིག་ལ་ཚོད་ལྟ་ཞིག་བྱེད་རོགས། + + + Please try again in %1 seconds. - + ཁྱོད་ཀྱིས་དུས་ཚོད་སྐར་ཆ་གཅིག་གི་ནང་དུ་ཡང་བསྐྱར་ཚོད་ལྟ་ཞིག་བྱེད་རོགས། + + + + Account locked permanently. - + དུས་གཏན་དུ་ཟྭ་བརྒྱབ་པའི་རྩིས་ཐོ། + + + + + Password cannot be empty + གསང་གྲངས་སྟོང་པ་ཡིན་མི་སྲིད། + + + Failed to verify %1, please enter password. + 验证%1失败,请输入密码. + + + Unable to verify %1, please enter password. + 无法验证%1,请输入密码. + + + + Failed to verify %1, you still have %2 verification opportunities + %1ལ་ཞིབ་བཤེར་བྱེད་མ་ཐུབ་ན། ཁྱེད་ཚོར་ད་དུང་%2ལ་ཞིབ་བཤེར་བྱེད་པའི་གོ་སྐབས་ཡོད། + + + An application is attempting to perform an action that requires privileges. Authentication is required to perform this action. + 一个程序正试图执行一个需要特权的动作。要求授权以执行该动作。 + + + + Password: + གསང་གྲངས་ནི། + + + + Please enter your password or enroll your fingerprint + ཁྱེད་ཀྱི་གསང་གྲངས་ནང་འཇུག་བྱེད་པའམ་ཡང་ན་ཁྱེད་ཀྱི་མཛུབ་རིས + + + + Abnormal network + རྒྱུན་ལྡན་མིན་པའི་དྲ་ + + + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + བྱ་སྤྱོད་འདི་ལ་དོ་དམ་པས་དབང་ཆ་སྤྲོད་དགོས། ཁྱེད་ཀྱི་གསང་གྲངས་ནང་དུ་བཅུག་ནས་གཤག་བཅོས་འདི་བྱེད་དུ་འཇུག་རོགས། + + + + _Password: + _Password་ནི། + + + + _Password: + _Password་ནི། + + + + Authentication failed, please try again. + བདེན་དཔང་ར་སྤྲོད་བྱེད་མ་ཐུབ་པས་ཁྱེད་ཀྱིས་ཡང་བསྐྱར་ཚོད་ལྟ་ཞིག་བྱེད་ + + + + days left + ཉིན་ཁ་ཤས་ལས་ལྷག་མེད + + + Biometric/code scan authentication failed too many times, please enter the password. + 生物/扫码验证失败达最大次数,请使用密码解锁. + + + Bioauth/code scan authentication failed, you still have %1 verification opportunities + 生物/扫码验证失败,您还有%1次尝试机会 + + + + + Failed to verify %1, please enter password to unlock + %1ལ་ཞིབ་བཤེར་བྱེད་མ་ཐུབ་ན། གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག་རོགས། + + + + + Unable to verify %1, please enter password to unlock + %1ལ་ཞིབ་བཤེར་བྱེད་ཐབས་བྲལ་བ་དང་། གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག་རོགས། NET Exception - - - - Verify face recognition or enter password to unlock - - - - Press fingerprint or enter password to unlock - - - - Verify voiceprint or enter password to unlock - - - - Verify finger vein or enter password to unlock - - - - Verify iris or enter password to unlock - - - - Failed to verify %1, you still have %2 verification opportunities - - - - Input Password - - - - Use the bound wechat scanning code or enter the password to unlock - - - - Failed to verify %1, please enter password to unlock - - - - Unable to verify %1, please enter password to unlock - + 网络异常 + A program is attempting to perform an action that requires privileges.It requires authorization to perform the action. - + གོ་རིམ་ཞིག་གིས་དམིགས་བསལ་དབང་ཆ་དགོས་པའི་བྱ་སྤྱོད་ཅིག་སྤེལ་རྩིས་བྱེད་བཞིན་ཡོད། དེས་བྱ་སྤྱོད་སྤེལ་བའི་དབང་ཆ་སྤྲོད་དགོས། - _Password: - + + Input Password + ནང་འཇུག་གི་གསང་གྲངས། - _Password: - + + hours left + དུས་ཚོད་འགའ་ལས་ལྷག་མེད + + + + minutes left + སྐར་མ་འགའ་ལས་ལྷག་མེད + + + + seconds left + གཡོན་ཕྱོགས་ཀྱི་དུས་ཚོད་སྐར་ཆ + + + + Verify face recognition or enter password to unlock + ངོ་གདོང་ངོས་འཛིན་ལ་ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་ + + + + Press fingerprint or enter password to unlock + མཛུབ་རིས་མནན་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ + + + + Verify voiceprint or enter password to unlock + སྒྲ་པར་ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག + + + + Verify finger vein or enter password to unlock + མཛུབ་མོའི་ནང་དུ་ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ + + + + Verify iris or enter password to unlock + iris ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་ + + + + Use the bound wechat scanning code or enter the password to unlock + འབྲེལ་མཐུད་ཀྱི་འཕྲིན་ཕྲན་ཞིབ་བཤེར་ཨང་གྲངས་སམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག་པ། + + + Use the bound wechat scanning code or enter the password to log in + 使用绑定的微信扫码或输入密码登录 + + + + + + + Account locked, + རྩིས་ཐོ་ཟྭ་བརྒྱབ་པ། + + + Authentication failed, please try again + 认证失败,请重试 PolkitListener - Authentication failure, please try again. - བདེན་དཔང་ངོས་འཛིན་ཕམ་ཉེས་བྱུང་། ཡང་བསྐྱར་ཚོད་ལྟ་བྱོས། - - + Another client is already authenticating, please try again later. - ཚོང་མགྲོན་སྣེ་གཞན་ཞིག་ནས་བདེན་དཔང་ངོས་འཛིན་བྱེད་སྒང་ཡིན། ཁྱུག་ཙམ་ནས་ཡང་བསྐྱར་ཚོད་ལྟ་བྱ་རོགས། + མངགས་བཅོལ་བྱེད་མཁན་གཞན་ཞིག་གིས་བདེན་དཔང་ར་སྤྲོད་བྱེད་བཞིན་ཡོད། ཅུང་ཙམ་འགོར་རྗེས་ཡང་བསྐྱར་ཚོད་ལྟ + + Authentication failure, please try again. + བདེན་དཔང་ར་སྤྲོད་བྱེད་མ་ཐུབ་ན་ཁྱེད་ཀྱིས་ཡང་བསྐྱར་ཚོད་ལྟ་ + + + Password input error! - + གསང་གྲངས་ནང་འཇུག་ནོར་འཁྲུལ་བྱུང་བ་རེད + + + Account locked %1 minutes due to %2 fail attempts + 账户锁定%1分钟由于%2次错误尝试 + + + Authentication failure,there are still %1 remaining opportunities + 认证失败,还剩余%1次尝试机会 + + + + QObject + + FingerPrint + 指纹 + + + FingerVein + 指静脉 + + + Iris + 虹膜 + + + Face + 人脸 + + + VoicePrint + 声纹 + + + Cancel + 取消 diff --git a/polkit-agent/i18n_ts/es.ts b/polkit-agent/i18n_ts/es.ts index 9a038a3..ac1ddd7 100644 --- a/polkit-agent/i18n_ts/es.ts +++ b/polkit-agent/i18n_ts/es.ts @@ -145,10 +145,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -181,6 +177,14 @@ _Password: + + Abnormal network + + + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + + PolkitListener diff --git a/polkit-agent/i18n_ts/fr.ts b/polkit-agent/i18n_ts/fr.ts index 4b4cd3e..87ca0d5 100644 --- a/polkit-agent/i18n_ts/fr.ts +++ b/polkit-agent/i18n_ts/fr.ts @@ -145,10 +145,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -181,6 +177,14 @@ _Password: + + Abnormal network + + + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + + PolkitListener diff --git a/polkit-agent/i18n_ts/pt.ts b/polkit-agent/i18n_ts/pt.ts index d528c7c..b24dbb2 100644 --- a/polkit-agent/i18n_ts/pt.ts +++ b/polkit-agent/i18n_ts/pt.ts @@ -145,10 +145,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -181,6 +177,14 @@ _Password: + + Abnormal network + + + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + + PolkitListener diff --git a/polkit-agent/i18n_ts/ru.ts b/polkit-agent/i18n_ts/ru.ts index 65f4480..6ceb7d7 100644 --- a/polkit-agent/i18n_ts/ru.ts +++ b/polkit-agent/i18n_ts/ru.ts @@ -145,10 +145,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -181,6 +177,14 @@ _Password: + + Abnormal network + + + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + + PolkitListener diff --git a/polkit-agent/i18n_ts/tr.ts b/polkit-agent/i18n_ts/tr.ts index 7336231..33848d7 100644 --- a/polkit-agent/i18n_ts/tr.ts +++ b/polkit-agent/i18n_ts/tr.ts @@ -34,131 +34,136 @@ MainWindow - + Authentication Kimlik Doğrulama - - + + Failed to verify %1, please enter password to unlock - - + + Unable to verify %1, please enter password to unlock - + Failed to verify %1, you still have %2 verification opportunities - - NET Exception + + Abnormal network - + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + + + + A program is attempting to perform an action that requires privileges.It requires authorization to perform the action. - + Input Password - - - - + + + + Account locked, - + days left - + hours left - + minutes left - + seconds left - - + + Password cannot be empty - - + + Use password - - - + + + Please try again in %1 minutes. - - - + + + Please try again in %1 seconds. - - - - + + + + Account locked permanently. - + Verify face recognition or enter password to unlock - + Press fingerprint or enter password to unlock - + Verify voiceprint or enter password to unlock - + Verify finger vein or enter password to unlock - + Verify iris or enter password to unlock - + Use the bound wechat scanning code or enter the password to unlock @@ -180,9 +185,9 @@ Parola - - - + + + Biometric Biyometrik @@ -231,19 +236,19 @@ Polkit.caller-pid: - - + + Cancel İptal - - + + Authenticate Kimlik Doğrulaması - + use password @@ -252,7 +257,7 @@ Kimlik Doğrulaması - + Please enter your password or enroll your fingerprint @@ -265,22 +270,22 @@ Bir uygulama, ayrıcalıklar gerektiren bir eylem gerçekleştirmeye çalışıyor. Bu işlemi gerçekleştirmek için kimlik doğrulaması gerekiyor. - + Password: Parola: - + _Password: _Parola: - + _Password: _Parola: - + Authentication failed, please try again. Kimlik doğrulama başarısız, lütfen tekrar deneyin. @@ -292,17 +297,17 @@ PolkitListener - + Another client is already authenticating, please try again later. Başka bir hesap zaten kimlik doğrulaması yapıyor, lütfen daha sonra tekrar deneyin. - + Authentication failure, please try again. Kimlik doğrulama hatalı, lütfen tekrar deneyin. - + Password input error! diff --git a/polkit-agent/i18n_ts/zh_CN.ts b/polkit-agent/i18n_ts/zh_CN.ts index 3b9346c..7f79e26 100644 --- a/polkit-agent/i18n_ts/zh_CN.ts +++ b/polkit-agent/i18n_ts/zh_CN.ts @@ -65,7 +65,7 @@ MainWindow - + Authentication 授权 @@ -91,14 +91,14 @@ 密码 - - - + + + Biometric 使用生物识别 - + use password 使用密码验证 @@ -147,20 +147,20 @@ Polkit.caller-pid: - - + + Cancel 取消 - - + + Authenticate 授权 - - + + Use password 使用密码验证 @@ -185,30 +185,30 @@ 认证中,请稍等... - - - + + + Please try again in %1 minutes. 请%1分钟后再试 - - - + + + Please try again in %1 seconds. 请%1秒后再试 - - - - + + + + Account locked permanently. 账号已被永久锁定 - - + + Password cannot be empty 密码不能为空 @@ -221,7 +221,7 @@ 无法验证%1,请输入密码. - + Failed to verify %1, you still have %2 verification opportunities 验证%1失败,您还有%2次尝试机会 @@ -230,32 +230,42 @@ 一个程序正试图执行一个需要特权的动作。要求授权以执行该动作。 - + Password: 密码: - + Please enter your password or enroll your fingerprint 请输入密码或者录入指纹 - + + Abnormal network + 网络异常 + + + + This operation requires the administrator's authorization. Please enter your password to allow this operation. + 本次操作需要通过管理员的授权才能继续执行,请输入密码以允许本次操作。 + + + _Password: 密码: - + _Password: 密码: - + Authentication failed, please try again. 认证失败,请重试。 - + days left 天后解锁 @@ -268,74 +278,73 @@ 生物/扫码验证失败,您还有%1次尝试机会 - - + + Failed to verify %1, please enter password to unlock 验证%1失败,请输入密码解锁 - - + + Unable to verify %1, please enter password to unlock 无法验证%1,请输入密码解锁 - NET Exception - 网络异常 + 网络异常 - + A program is attempting to perform an action that requires privileges.It requires authorization to perform the action. 一个程序正试图执行一个需要特权的动作,要求授权以执行该动作。 - + Input Password 输入密码 - + hours left 小时后解锁 - + minutes left 分钟后解锁 - + seconds left 秒后解锁 - + Verify face recognition or enter password to unlock 验证人脸识别或输入密码解锁 - + Press fingerprint or enter password to unlock 按压指纹或输入密码解锁 - + Verify voiceprint or enter password to unlock 验证声纹或输入密码解锁 - + Verify finger vein or enter password to unlock 验证指静脉或输入密码解锁 - + Verify iris or enter password to unlock 验证虹膜或输入密码解锁 - + Use the bound wechat scanning code or enter the password to unlock 使用绑定的微信扫码或输入密码解锁 @@ -344,10 +353,10 @@ 使用绑定的微信扫码或输入密码登录 - - - - + + + + Account locked, 账户已锁定, @@ -359,17 +368,17 @@ PolkitListener - + Another client is already authenticating, please try again later. 有另外一个客户端正在认证,请稍后重试。 - + Authentication failure, please try again. 认证失败,请重试。 - + Password input error! 密码输入错误! diff --git a/polkit-agent/src/PolkitAgent.cpp b/polkit-agent/src/PolkitAgent.cpp index e5c9cf9..ef68e02 100644 --- a/polkit-agent/src/PolkitAgent.cpp +++ b/polkit-agent/src/PolkitAgent.cpp @@ -73,6 +73,7 @@ int main(int argc, char *argv[]) BioDevices devices; devices.setIsShowHotPlug(true); + devices.setUId(getuid()); agent.exec(); return EXIT_SUCCESS; } diff --git a/polkit-agent/src/PolkitListener.cpp b/polkit-agent/src/PolkitListener.cpp index 9196982..1642cca 100644 --- a/polkit-agent/src/PolkitListener.cpp +++ b/polkit-agent/src/PolkitListener.cpp @@ -35,6 +35,7 @@ #include "PolkitListener.h" #include "mainwindow.h" #include "generic.h" +#include PolkitListener::PolkitListener(QObject *parent) : Listener(parent), @@ -42,12 +43,40 @@ PolkitListener::PolkitListener(QObject *parent) currentIdentity(0), mainWindow(nullptr) { + m_isSupportTableMode = isSupportTableMode(); + m_isMavis = isMavis(); + qDebug()<<"isSupportTableMode:"<setWindowMotifHint(mainWindow->winId(), hints); mainWindow->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint); mainWindow->setIcon(iconName); + mainWindow->setCurProject(m_isMavis); mainWindow->setHeader(message); mainWindow->setUsers(usersList); + mainWindow->setEditInputMethod(m_isSupportTableMode); /* mainWindow->setDetails(subjectPid, callerPid, actionDesc.actionId(), diff --git a/polkit-agent/src/PolkitListener.h b/polkit-agent/src/PolkitListener.h index 49e3fec..0f2420e 100644 --- a/polkit-agent/src/PolkitListener.h +++ b/polkit-agent/src/PolkitListener.h @@ -32,6 +32,10 @@ public: PolkitListener(QObject *parent = 0); virtual ~PolkitListener(); +private: + bool isSupportTableMode(); + bool isMavis(); + public slots: void initiateAuthentication(const QString &actionId, const QString &message, @@ -58,6 +62,8 @@ private: QString cookie; MainWindow *mainWindow; bool unacknowledged_messages = false; + bool m_isSupportTableMode = false; + bool m_isMavis = false; private slots: diff --git a/polkit-agent/src/kalabel.cpp b/polkit-agent/src/kalabel.cpp new file mode 100644 index 0000000..2666f0b --- /dev/null +++ b/polkit-agent/src/kalabel.cpp @@ -0,0 +1,44 @@ +#include "kalabel.h" + + +KALabel::KALabel(QWidget *parent) + : QLabel(parent) +{ + m_strText = ""; +} + +KALabel::KALabel(QString strText, QWidget *parent) + : QLabel(strText, parent) +{ + m_strText = strText; +} + +void KALabel::setText(const QString &strText) +{ + m_strText = strText; + QLabel::setText(strText); +} + +void KALabel::paintEvent(QPaintEvent *event) +{ + QString strEText = getElidedText(font(), width() ,m_strText); + if (strEText != m_strText) { + QLabel::setText(strEText); + setToolTip(m_strText); + } else { + QLabel::setText(m_strText); + setToolTip(""); + } + QLabel::paintEvent(event); +} + +QString KALabel::getElidedText(QFont font,int width,QString strInfo) +{ + QFontMetrics fontMetrics(font); + //如果当前字体下,字符串长度大于指定宽度 + if(fontMetrics.width(strInfo) > width) + { + strInfo= QFontMetrics(font).elidedText(strInfo, Qt::ElideRight, width); + } + return strInfo; +} diff --git a/polkit-agent/src/kalabel.h b/polkit-agent/src/kalabel.h new file mode 100644 index 0000000..f2678ac --- /dev/null +++ b/polkit-agent/src/kalabel.h @@ -0,0 +1,23 @@ +#ifndef KALABEL_H +#define KALABEL_H + +#include + +class KALabel : public QLabel +{ + Q_OBJECT +public: + KALabel(QWidget *parent = nullptr); + KALabel(QString strText, QWidget *parent = nullptr); + QString getElidedText(QFont font,int width,QString strInfo); +public slots: + void setText(const QString &); + +protected: + void paintEvent(QPaintEvent *event); + +private: + QString m_strText; +}; + +#endif // KALABEL_H diff --git a/polkit-agent/src/mainwindow.cpp b/polkit-agent/src/mainwindow.cpp index 29602b0..0c25ba2 100644 --- a/polkit-agent/src/mainwindow.cpp +++ b/polkit-agent/src/mainwindow.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include "bioauthwidget.h" #include #include @@ -54,10 +55,10 @@ MainWindow::MainWindow(QWidget *parent) : authMode(UNDEFINED), useDoubleAuth(false), m_timer(nullptr), + w_timer(nullptr), isLockingFlg(false), m_nCurLockMin(0), - isbioSuccess(false), - useFirstDevice(false) + isbioSuccess(false) { ui->setupUi(this); setWindowTitle(tr("Authentication")); @@ -87,7 +88,7 @@ MainWindow::MainWindow(QWidget *parent) : // headerLayout->addWidget(closeBtn); // 登录选项 - m_labelTip = new QLabel(); + m_labelTip = new KALabel(); m_labelTip->setText(""); m_labelTip->hide(); m_loginOptsWidget = new LoginOptionsWidget(); @@ -98,7 +99,6 @@ MainWindow::MainWindow(QWidget *parent) : maxFailedTimes = bioDevices.getFailedTimes(); isHiddenSwitchButton = bioDevices.GetHiddenSwitchButton(); - useFirstDevice = bioDevices.getUseFirstDevice(); connect(m_loginOptsWidget, &LoginOptionsWidget::optionSelected, this, [&](unsigned uCurLoginOptType, const DeviceInfoPtr &deviceInfo){ @@ -143,7 +143,13 @@ MainWindow::MainWindow(QWidget *parent) : emit switchToBiometric(); authMode = UNDEFINED; } else { - if (nStatus >= 2) { + if (nStatus == 5 && m_deviceInfo) { + if(w_timer && w_timer->isActive()) + w_timer->stop(); + QImage imgFailed; + m_loginOptsWidget->setFaceImg(imgFailed, 2); + return; + } else if (nStatus >= 2 && nStatus != 5)if (nStatus >= 2) { if (m_deviceInfo) { uid_t curUid = getUid(userName); if(m_failMap.contains(curUid) && m_failMap[curUid].contains(m_deviceInfo->device_id)){ @@ -157,6 +163,7 @@ MainWindow::MainWindow(QWidget *parent) : m_loginOptsWidget->setFaceImg(imgFailed, 1); } if(m_failMap[curUid][m_deviceInfo->device_id] >= maxFailedTimes){ + no_changes = true; if (m_deviceInfo->biotype == REMOTE_QRCODE_TYPE) { setLoginTypeTip(tr("Failed to verify %1, please enter password to unlock").arg(BioDevices::bioTypeToString_tr(m_deviceInfo->biotype))); QImage nullImage; @@ -168,6 +175,7 @@ MainWindow::MainWindow(QWidget *parent) : useDoubleAuth = false; return ; } + no_changes = false; setLoginTypeTip(tr("Failed to verify %1, you still have %2 verification opportunities") .arg(BioDevices::bioTypeToString_tr(m_deviceInfo->biotype)) .arg(maxFailedTimes-m_failMap[curUid][m_deviceInfo->device_id])); @@ -180,7 +188,7 @@ MainWindow::MainWindow(QWidget *parent) : } if (m_uCurLoginOptType == LOGINOPT_TYPE_QRCODE && nStatus == 1) { m_isNetworkErr = true; - m_loginOptsWidget->setQRCodeMsg(tr("NET Exception")); + m_loginOptsWidget->setQRCodeMsg(tr("Abnormal network")); startBioAuth(10000); } else { startBioAuth(); @@ -221,6 +229,16 @@ MainWindow::MainWindow(QWidget *parent) : fontSize = settings->get("system-font-size").toInt(); connect(settings, &QGSettings::changed, this, &MainWindow::onConfigurationChanged); + + QDBusInterface *interfaceScreensaver = new QDBusInterface( + "org.ukui.ScreenSaver", + "/", + "org.ukui.ScreenSaver", + QDBusConnection::sessionBus()); + connect(interfaceScreensaver, SIGNAL(lock()), + this, SLOT(onLockStatus())); + connect(interfaceScreensaver, SIGNAL(unlock()), + this, SLOT(onUnlockStatus())); } MainWindow::~MainWindow() @@ -337,6 +355,7 @@ void MainWindow::on_cmbUsers_currentTextChanged(const QString &userName) m_deviceInfo = DeviceInfoPtr(); ui->lblMessage->clear(); ui->lblMessage->setToolTip(""); + setMessage(""); isLockingFlg = false; emit userChanged(this->userName); } @@ -390,6 +409,19 @@ void MainWindow::on_btnAuth_clicked() on_lePassword_returnPressed(); } +void MainWindow::onLockStatus() +{ + //m_loginOptsWidget->stopAuth(); + m_loginOptsWidget->lockStatusChanged(true); +} + +void MainWindow::onUnlockStatus() +{ + //m_loginOptsWidget->readDevicesInfo(); + m_loginOptsWidget->lockStatusChanged(false); + startBioAuth(); +} + /*** pagePassword ***/ void MainWindow::editIcon() { @@ -414,6 +446,17 @@ void MainWindow::on_lePassword_returnPressed() { emit accept(ui->lePassword->text()); ui->btnAuth->hide(); + ui->btnLoading->show(); + if(!w_timer) + { + w_timer = new QTimer(this); + w_timer->setInterval(150); + connect(w_timer, &QTimer::timeout, this, &MainWindow::updatePixmap); + } + m_waitingPixmap = QIcon::fromTheme("ukui-loading-0-symbolic").pixmap(24, 24); + ui->btnLoading->setIcon(QIcon(m_waitingPixmap)); + + w_timer->start(); // switchWidget(UNDEFINED); // setMessage(tr("in authentication, please wait...")); } @@ -469,7 +512,11 @@ void MainWindow::setIcon(const QString &iconName) void MainWindow::setHeader(const QString &text) { - ui->lblHeader->setText(text); + if(is_Mavis) + ui->lblHeader->setText(tr("This operation requires the administrator's authorization. " + "Please enter your password to allow this operation.")); + else + ui->lblHeader->setText(text); ui->lblHeader->adjustSize(); ui->lblHeader->height(); ui->lblContent->setText(tr("A program is attempting to perform an action that requires privileges." @@ -566,17 +613,17 @@ QString MainWindow::check_is_pam_message(QString text) textdomain("Linux-PAM"); char* str; QString strTrans = ""; - QByteArray ba = text.toLatin1(); // must + QByteArray ba = text.toLocal8Bit(); // must str=ba.data(); - + char l_str[1024]; int a,b; //兼容旧版本翻译,以及适配新版本翻译 if(text.contains("attemps",Qt::CaseSensitive) && sscanf(str,"Authenticated failed, %d login attemps left",&a)) - sprintf(str,_("Authenticated failed, %d login attemps left"),a); + snprintf(l_str,1024,_("Authenticated failed, %d login attemps left"),a); else if(text.contains("attempts",Qt::CaseSensitive) && sscanf(str,"Authenticated failed, %d login attempts left",&a)) - sprintf(str,_("Authenticated failed, %d login attempts left"),a); + snprintf(l_str,1024,_("Authenticated failed, %d login attempts left"),a); else if(text.contains("attempt",Qt::CaseSensitive) && sscanf(str,"Authenticated failed, %d login attempt left",&a)) - sprintf(str,_("Authenticated failed, %d login attempt left"),a); + snprintf(l_str,1024,_("Authenticated failed, %d login attempt left"),a); else if(text.contains("days",Qt::CaseSensitive) && sscanf(str,"Account locked, %d days left",&a)){ strTrans = tr("Account locked,") + QString("%1 ").arg(a) + tr("days left"); return strTrans; @@ -594,12 +641,11 @@ QString MainWindow::check_is_pam_message(QString text) return strTrans; } else{ - str = _(str); + return _(str); } - qDebug()<<"str = "<lePassword->setStyleSheet("QLineEdit{background-color: palette(Button);" +// "border-radius: 6px;border: 1px solid #F3222D;}"); }else if(situat == TRUE){ QColor color = palette().color(QPalette::WindowText); QPalette pal(this->palette()); @@ -649,12 +695,14 @@ void MainWindow::setAuthResult(bool result, const QString &text) message = tr("Authentication failed, please try again."); } - if(authMode == PASSWORD) - setMessage(message,ERROR); + if(authMode == PASSWORD) { + switchWidget(PASSWORD); + //setMessage(message,ERROR); + } else if(authMode == BIOMETRIC) setMessage(message,ERROR); - switchWidget(PASSWORD); + } void MainWindow::clearEdit() @@ -705,6 +753,7 @@ void MainWindow::switchAuthMode(Mode mode) break; case BIOMETRIC: { + authMode = mode; qDebug() << "switch to biometric"; if (m_deviceInfo) { if (!m_loginOptsWidget->findDeviceById(m_deviceInfo->device_id) @@ -712,10 +761,10 @@ void MainWindow::switchAuthMode(Mode mode) m_deviceInfo = DeviceInfoPtr(); } } - if(authMode == PASSWORD) { + /*if(authMode == PASSWORD) { emit accept(BIOMETRIC_IGNORE); return; - }else if(!enableBioAuth){ + }else */if(!enableBioAuth){ qDebug() << "It doesn't meet the condition for enabling biometric authentication, switch to password."; emit accept(BIOMETRIC_IGNORE); return; @@ -725,19 +774,13 @@ void MainWindow::switchAuthMode(Mode mode) if(strDeviceName.isEmpty() && !m_deviceInfo) { qDebug() << "No default device"; - if(useFirstDevice == true){ - m_deviceInfo = m_loginOptsWidget->getFirstDevInfo(); - } else { - emit accept(BIOMETRIC_IGNORE); - return; - } + emit accept(BIOMETRIC_IGNORE); + return; } //第一次,获取默认设备的设备信息,之后使用的则是从设备选择窗口传出的设备信息 if(!m_deviceInfo) { m_deviceInfo = m_loginOptsWidget->findDeviceByName(strDeviceName); - if (!m_deviceInfo) - m_deviceInfo = m_loginOptsWidget->getFirstDevInfo(); } if(!m_deviceInfo){ emit accept(BIOMETRIC_IGNORE); @@ -751,7 +794,7 @@ void MainWindow::switchAuthMode(Mode mode) startBioAuth(); emit accept(BIOMETRIC_IGNORE); return; - } else if(authMode == UNDEFINED){ + } /*else if(authMode == UNDEFINED){ authMode = BIOMETRIC; if(enableBioAuth) { @@ -787,13 +830,13 @@ void MainWindow::switchAuthMode(Mode mode) startBioAuth(); emit accept(BIOMETRIC_IGNORE); return; - } else { + } else {*/ /* pass biometric's pam module if there are not available devices */ - qDebug() << "It doesn't meet the condition for enabling biometric authentication, switch to password."; - emit accept(BIOMETRIC_IGNORE); - return; - } - } +// qDebug() << "It doesn't meet the condition for enabling biometric authentication, switch to password."; +// emit accept(BIOMETRIC_IGNORE); +// return; +// } +// } } break; default: @@ -831,6 +874,7 @@ void MainWindow::switchWidget(Mode mode) { ui->widgetPasswdAuth->hide(); ui->btnAuth->hide(); + ui->btnLoading->hide(); ui->btnAuth->setText(tr("Authenticate")); ui->btnAuth->adjustSize(); ui->btnBioAuth->setText(tr("Biometric")); @@ -838,7 +882,14 @@ void MainWindow::switchWidget(Mode mode) ui->btnCancel->setText(tr("Cancel")); ui->btnCancel->adjustSize(); ui->returnButton->setText(tr("Use password")); + ui->btnLoading->setDisabled(true); ui->returnButton->adjustSize(); + if(is_Mavis){ + ui->cmbUsers->setFixedHeight(48); + ui->lePassword->setFixedHeight(48); + ui->btnAuth->setFixedHeight(48); + ui->btnCancel->setFixedHeight(48); + } switch(mode){ case PASSWORD: { @@ -878,15 +929,17 @@ void MainWindow::switchWidget(Mode mode) + ui->cmbUsers->height() + ui->lePassword->height() + ui->lblMessage->height() + ui->btnAuth->height(); } + if (m_loginOptsWidget->isHidden()) { + height -= 20 ; + } + unsigned uOptsWidgetHeight = m_loginOptsWidget->height(); if (m_loginOptsWidget->isHidden()) { uOptsWidgetHeight = 0; height -= 20 ; } - ui->lblContent->adjustSize(); - ui->lblHeader->adjustSize(); - setMinimumHeight(height + uOptsWidgetHeight); - setMaximumHeight(height + uOptsWidgetHeight); + setMinimumHeight(height + uOptsWidgetHeight + 10); + setMaximumHeight(height + uOptsWidgetHeight + 10); //m_loginOptsWidget->updateUIStatus(); ui->btnBioAuth->setStyleSheet("QPushButton{font-size:14px;}QPushButton:hover{border:none;color:#3E6CE5;}QPushButton:pressed{border:none;}"); ui->btnBioAuth->setFlat(true); @@ -895,10 +948,19 @@ void MainWindow::switchWidget(Mode mode) ui->btnBioAuth->adjustSize(); ui->widgetPasswdAuth->show(); ui->lePassword->setFocus(); - ui->lePassword->setContextMenuPolicy(Qt::NoContextMenu); //禁用右键菜单 - ui->lePassword->setAttribute(Qt::WA_InputMethodEnabled, false); - ui->lePassword->setEchoMode(QLineEdit::Password); + //ui->lePassword->setAttribute(Qt::WA_InputMethodEnabled, false); + if (m_modeButton && m_modeButton->isShowPwd()) { + ui->lePassword->setEchoMode(QLineEdit::Normal); + } else { + ui->lePassword->setEchoMode(QLineEdit::Password); + } ui->btnAuth->show(); + ui->btnLoading->hide(); + ui->lePassword->setDisabled(false); + if(w_timer && w_timer->isActive()) + { + w_timer->stop(); + } ui->btnCancel->show(); //ui->lblContent->show(); ui->returnButton->hide(); @@ -909,11 +971,10 @@ void MainWindow::switchWidget(Mode mode) case BIOMETRIC: setMinimumWidth(420); setMaximumWidth(420); - if(bioDevices.count()<1||bioDevices.count()==1){ + if(m_loginOptsWidget->getLoginOptCount() <= 1){ setMinimumHeight(392+ui->cmbUsers->height()+ui->lblHeader->height()); setMaximumHeight(392+ui->cmbUsers->height()+ui->lblHeader->height()); - } - if(bioDevices.count()>1){ + } else { setMinimumHeight(482+ui->cmbUsers->height()+ui->lblHeader->height()); setMaximumHeight(482+ui->cmbUsers->height()+ui->lblHeader->height()); } @@ -934,7 +995,7 @@ void MainWindow::switchWidget(Mode mode) default: break; } - adjustSize(); +// adjustSize(); } void MainWindow::unlock_countdown() @@ -1107,6 +1168,7 @@ void MainWindow::switchLoginOptType(unsigned uLoginOptType) QImage imgFailed; m_loginOptsWidget->setFaceImg(imgFailed, 1); } + no_changes = true; if (m_deviceInfo->biotype == REMOTE_QRCODE_TYPE) { setLoginTypeTip(tr("Failed to verify %1, please enter password to unlock").arg(BioDevices::bioTypeToString_tr(m_deviceInfo->biotype))); } else { @@ -1114,6 +1176,7 @@ void MainWindow::switchLoginOptType(unsigned uLoginOptType) } m_loginOptsWidget->setDeviceDisable(m_deviceInfo->device_id, true); } else { + no_changes = false; if (uLoginOptType != m_uCurLoginOptType || (m_deviceInfo && m_deviceInfo->device_id != m_nLastDeviceId)) { switch(uLoginOptType) { case LOGINOPT_TYPE_PASSWORD: @@ -1171,22 +1234,21 @@ void MainWindow::setLoginTypeTip(QString strLoginTypeTip) if (m_strLoginTypeTip.isEmpty()) { m_labelTip->hide(); } else { - QFontMetrics font(m_labelTip->font()); - //返回字符串末尾带省略号的字符串 - QString strDisplay = font.elidedText(m_strLoginTypeTip, Qt::ElideRight, m_labelTip->width()-8); QPalette pe; - pe.setColor(QPalette::WindowText,Qt::blue); + if(no_changes) + pe.setColor(QPalette::WindowText,Qt::red); + else + pe.setColor(QPalette::WindowText,QColor(55, 144, 250, 255)); m_labelTip->setPalette(pe); - m_labelTip->setText(strDisplay); - m_labelTip->setToolTip(m_strLoginTypeTip); + m_labelTip->setText(m_strLoginTypeTip); m_labelTip->show(); } } void MainWindow::startBioAuthDelay() { - m_loginOptsWidget->startAuth(m_deviceInfo, getUid(userName)); if (m_deviceInfo) { + m_loginOptsWidget->startAuth(m_deviceInfo, getUid(userName)); switchLoginOptType(m_loginOptsWidget->convertDeviceType(m_deviceInfo->biotype)); } else { switchLoginOptType(LOGINOPT_TYPE_PASSWORD); @@ -1211,6 +1273,17 @@ void MainWindow::onUpdateBioAuthMsg(QString strMsg) setMessage(strMsg, TRUE); } +void MainWindow::updatePixmap() +{ + ui->btnAuth->hide(); + ui->btnLoading->show(); + ui->lePassword->setDisabled(true); + QMatrix matrix; + matrix.rotate(90.0); + m_waitingPixmap = m_waitingPixmap.transformed(matrix, Qt::FastTransformation); + ui->btnLoading->setIcon(m_waitingPixmap); +} + void MainWindow::onUpdateWndSize(unsigned uLoginOptType, unsigned uLoginOptSize) { ui->lblContent->hide(); @@ -1230,7 +1303,7 @@ void MainWindow::onUpdateWndSize(unsigned uLoginOptType, unsigned uLoginOptSize) uOptsWidgetHeight = m_loginOptsWidget->height() + 10 ; } // ui->lblContent->adjustSize(); - ui->lblHeader->adjustSize(); +// ui->lblHeader->adjustSize(); int height; if(fontSize = 10){ height = 120 + ui->lblHeader->height() /*+ ui->lblContent->height()*/ @@ -1264,4 +1337,19 @@ void MainWindow::onUpdateWndSize(unsigned uLoginOptType, unsigned uLoginOptSize) setMaximumHeight(height + uOptsWidgetHeight); } +void MainWindow::setEditInputMethod(bool bEnable) +{ + qDebug()<<"setEditInputMethod:"<lePassword->setAttribute(Qt::WA_InputMethodEnabled, true); + } else { + ui->lePassword->setAttribute(Qt::WA_InputMethodEnabled, false); + } +} + +void MainWindow::setCurProject(bool isMavis) +{ + is_Mavis = isMavis; +} + /*** end of private member ***/ diff --git a/polkit-agent/src/mainwindow.h b/polkit-agent/src/mainwindow.h index 01c3deb..894e938 100644 --- a/polkit-agent/src/mainwindow.h +++ b/polkit-agent/src/mainwindow.h @@ -30,6 +30,7 @@ #include "bioauthwidget.h" #include "loginoptionswidget.h" #include "modeButton.h" +#include "kalabel.h" namespace Ui { class MainWindow; } @@ -61,6 +62,8 @@ public: void stopDoubleAuth(); QString check_is_pam_message(QString text); void switchLoginOptType(unsigned uLoginOptType); + void setEditInputMethod(bool bEnable); + void setCurProject(bool isMavis); private: uid_t getUid(const QString &userName); @@ -75,6 +78,8 @@ private: void unlock_countdown(); void editIcon(); void setLoginTypeTip(QString strLoginTypeTip); + void setMavisSheel(); + void updatePixmap(); public slots: void onUpdateBioAuthMsg(QString strMsg); @@ -91,6 +96,8 @@ private slots: void restart_bio_identify(); void startBioAuthDelay(); void onConfigurationChanged(QString key); + void onLockStatus(); + void onUnlockStatus(); signals: void accept(const QString &text); @@ -123,13 +130,12 @@ private: bool isLockingFlg; //判断当前是否正在锁定倒计时 int m_nCurLockMin; //当前锁定的分钟数 // 登录选项 - QLabel *m_labelTip = nullptr; + KALabel *m_labelTip = nullptr; LoginOptionsWidget *m_loginOptsWidget = nullptr; unsigned m_uCurLoginOptType = LOGINOPT_TYPE_PASSWORD; // 当前登录验证方式 QString m_strLoginTypeTip = ""; QTimer *m_bioTimer = nullptr; DeviceInfoPtr m_deviceInfo = nullptr; - bool useFirstDevice; bool m_isNetworkErr = false; //标题栏 QHBoxLayout *headerLayout; @@ -142,6 +148,12 @@ private: QString app_IconName; int m_nLastDeviceId = -1; + bool no_changes = false; + + bool is_Mavis = false; + + QTimer *w_timer; + QPixmap m_waitingPixmap; }; #endif // MAINWINDOW_H diff --git a/polkit-agent/src/mainwindow.ui b/polkit-agent/src/mainwindow.ui index 7d7eb36..22b4aa5 100644 --- a/polkit-agent/src/mainwindow.ui +++ b/polkit-agent/src/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 459 - 419 + 432 @@ -96,6 +96,9 @@ + + true + 0 @@ -172,7 +175,7 @@ - + 0 @@ -351,6 +354,16 @@ + + + + + + + true + + + @@ -365,6 +378,13 @@ + + + KALabel + QLabel +
./src/kalabel.h
+
+
diff --git a/polkit-agent/src/modeButton.cpp b/polkit-agent/src/modeButton.cpp index b9e75e4..53d0ffc 100644 --- a/polkit-agent/src/modeButton.cpp +++ b/polkit-agent/src/modeButton.cpp @@ -147,3 +147,8 @@ QPixmap ModeButton::drawSymbolicColoredPixmap(QPixmap &source, QString cgColor) } return QPixmap::fromImage(img); } + +bool ModeButton::isShowPwd() +{ + return pwdShow; +} diff --git a/polkit-agent/src/modeButton.h b/polkit-agent/src/modeButton.h index be772ce..b8fa08f 100644 --- a/polkit-agent/src/modeButton.h +++ b/polkit-agent/src/modeButton.h @@ -17,6 +17,7 @@ public: QPixmap drawSymbolicColoredPixmap(QPixmap &source, QString cgColor); void initUI(); void setModeIcon(); + bool isShowPwd(); protected: bool eventFilter(QObject *obj, QEvent *event) override; //事件过滤 diff --git a/polkit-agent/src/pam-tally.c b/polkit-agent/src/pam-tally.c index d32f578..50a3055 100644 --- a/polkit-agent/src/pam-tally.c +++ b/polkit-agent/src/pam-tally.c @@ -357,13 +357,19 @@ pam_modutil_read(int fd, char *buffer, int count) void get_tally(uid_t uid, int *tfile, struct tallylog *tally) { - char filename[50]={0}; - sprintf(filename,"%s","/tmp/.tallylog"); + char filename[50]={0}; + sprintf(filename,"/tmp/.tallylog.d/.%d",uid); + fprintf(stderr,"new_filename = :%s \n",filename); + void *void_tally = tally; - void *void_tally = tally; - if ((*tfile = open(filename, O_RDONLY)) == -1){ - fprintf(stderr, "open tallylog failed \n"); - return ; + if ((*tfile = open(filename, O_RDONLY)) == -1){ + fprintf(stderr, "lseek tallylog failed,Re-open the new file, uid = %d \n",uid); + sprintf(filename,"/tmp/.tallylog"); + fprintf(stderr,"old_filename = :%s \n",filename); + if ((*tfile = open(filename, O_RDONLY)) == -1){ + fprintf(stderr, "open tallylog failed \n"); + return ; + } } if (lseek(*tfile, (off_t)uid*(off_t)sizeof(*tally), SEEK_SET) == (off_t)-1) { diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..61cd01d --- /dev/null +++ b/readme.txt @@ -0,0 +1,7 @@ +bioctl status 获取生物特征总开关状态 +bioctl status greeter|screensaver|polkit|sudo|su|login 获取应用开关状态 + +bioctl enable|disable 打开|关闭 生物特征总开关 +bioctl enable|disable greeter|screensaver|polkit|sudo|su|login 打开|关闭 应用生物特征开关 + + diff --git a/uniauth-backend/CMakeLists.txt b/uniauth-backend/CMakeLists.txt new file mode 100644 index 0000000..330a65e --- /dev/null +++ b/uniauth-backend/CMakeLists.txt @@ -0,0 +1,26 @@ +project(uniauth-backend) + +set(CMAKE_AUTOMOC ON) + +include_directories( + ${Qt5Core_INCLUDE_DIRS} + ${Qt5DBus_INCLUDE_DIRS} + ) + +set(bin_SRCS + ${bin_SRCS} + src/main.cpp + src/biodeviceinfo.h + src/biodeviceinfo.cpp + src/serviceinterface.h + src/serviceinterface.cpp + src/servicemanager.h + src/servicemanager.cpp + ) + +add_executable(uniauth-backend ${bin_SRCS}) +target_link_libraries(uniauth-backend Qt5::Core Qt5::DBus) + +install(TARGETS uniauth-backend DESTINATION bin) +install(FILES org.ukui.UniauthBackend.conf DESTINATION /etc/dbus-1/system.d/) +install(FILES org.ukui.UniauthBackend.service DESTINATION /usr/share/dbus-1/system-services/) diff --git a/uniauth-backend/org.ukui.UniauthBackend.conf b/uniauth-backend/org.ukui.UniauthBackend.conf new file mode 100644 index 0000000..49ea12f --- /dev/null +++ b/uniauth-backend/org.ukui.UniauthBackend.conf @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/uniauth-backend/org.ukui.UniauthBackend.service b/uniauth-backend/org.ukui.UniauthBackend.service new file mode 100644 index 0000000..38a3585 --- /dev/null +++ b/uniauth-backend/org.ukui.UniauthBackend.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.ukui.UniauthBackend +Exec=/usr/bin/uniauth-backend +User=root diff --git a/uniauth-backend/src/biodeviceinfo.cpp b/uniauth-backend/src/biodeviceinfo.cpp new file mode 100644 index 0000000..d386d2b --- /dev/null +++ b/uniauth-backend/src/biodeviceinfo.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ + +#include "biodeviceinfo.h" + +void registerCustomTypes() +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); +} + +QDBusArgument &operator<<(QDBusArgument &argument, const DeviceInfo &deviceInfo) +{ + argument.beginStructure(); + argument << deviceInfo.device_id << deviceInfo.device_shortname + << deviceInfo.device_fullname << deviceInfo.driver_enable + << deviceInfo.device_available + << deviceInfo.biotype << deviceInfo.stotype + << deviceInfo.eigtype << deviceInfo.vertype + << deviceInfo.idtype << deviceInfo.bustype + << deviceInfo.dev_status << deviceInfo.ops_status; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceInfo &deviceInfo) +{ + argument.beginStructure(); + argument >> deviceInfo.device_id >> deviceInfo.device_shortname + >> deviceInfo.device_fullname >> deviceInfo.driver_enable + >> deviceInfo.device_available + >> deviceInfo.biotype >> deviceInfo.stotype + >> deviceInfo.eigtype >> deviceInfo.vertype + >> deviceInfo.idtype >> deviceInfo.bustype + >> deviceInfo.dev_status >> deviceInfo.ops_status; + argument.endStructure(); + return argument; +} diff --git a/uniauth-backend/src/biodeviceinfo.h b/uniauth-backend/src/biodeviceinfo.h new file mode 100644 index 0000000..994bb17 --- /dev/null +++ b/uniauth-backend/src/biodeviceinfo.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ +#ifndef BIODEVICEINFO_H +#define BIODEVICEINFO_H + +#include +#include +#include + +struct DeviceInfo { + int device_id; + QString device_shortname; /* aka driverName */ + QString device_fullname; + int driver_enable; /* The corresponding driver is enabled/disabled */ + int device_available; /* The driver is enabled and the device is connected */ + int biotype; + int stotype; + int eigtype; + int vertype; + int idtype; + int bustype; + int dev_status; + int ops_status; +}; + +enum BioType { + BIOTYPE_FINGERPRINT, + BIOTYPE_FINGERVEIN, + BIOTYPE_IRIS, + BIOTYPE_FACE, + BIOTYPE_VOICEPRINT, + __MAX_NR_BIOTYPES +}; + +#define REMOTE_QRCODE_TYPE (8) + +Q_DECLARE_METATYPE(DeviceInfo) +Q_DECLARE_METATYPE(QList) +void registerCustomTypes(); +QDBusArgument &operator<<(QDBusArgument &argument, const DeviceInfo &deviceInfo); +const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceInfo &deviceInfo); + +#endif // BIODEVICEINFO_H diff --git a/uniauth-backend/src/main.cpp b/uniauth-backend/src/main.cpp new file mode 100644 index 0000000..dae33a6 --- /dev/null +++ b/uniauth-backend/src/main.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ +#include +#include "serviceinterface.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + ServiceInterface serviveInterface; + Q_UNUSED(serviveInterface); + + return a.exec(); +} diff --git a/uniauth-backend/src/serviceinterface.cpp b/uniauth-backend/src/serviceinterface.cpp new file mode 100644 index 0000000..3862868 --- /dev/null +++ b/uniauth-backend/src/serviceinterface.cpp @@ -0,0 +1,766 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ +#include "serviceinterface.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "servicemanager.h" + +#define COMM_CONFIG_PATH "/etc/biometric-auth/ukui-biometric.conf" +#define USER_CONFIG_PATH "/home/%1/.biometric_auth/ukui_biometric.conf" + +ServiceInterface::ServiceInterface() +{ + bool res = QDBusConnection::systemBus().registerService("org.ukui.UniauthBackend"); + if(!res){ + qInfo()<<"registerService org.ukui.UniauthBackend failed!!"; + exit(0); + } + res = QDBusConnection::systemBus().registerObject("/org/ukui/UniauthBackend", "org.ukui.UniauthBackend", + this, QDBusConnection::ExportAllSlots|QDBusConnection::ExportAllSignals); + if(!res){ + qInfo()<<"registerObject /org/ukui/UniauthBackend failed!!"; + exit(0); + } + + registerCustomTypes(); + m_serviceInterface = new QDBusInterface(DBUS_SERVICE, DBUS_PATH, + DBUS_INTERFACE, + QDBusConnection::systemBus()); + + m_serviceInterface->setTimeout(2147483647); + connect(m_serviceInterface, SIGNAL(USBDeviceHotPlug(int, int, int)), + this, SLOT(onUSBDeviceHotPlug(int,int,int))); + updateCommDefaultDevice(-1); + initData(); + + ServiceManager *sm = ServiceManager::instance(); + connect(sm, &ServiceManager::serviceStatusChanged, + this, &ServiceInterface::onBiometricDbusChanged); +} + +void ServiceInterface::setDefaultDevice(QString userName, int bioDevType, QString deviceName) +{ + QString configPath = QString(USER_CONFIG_PATH).arg(userName); + qDebug() << configPath << bioDevType ; + QSettings settings(configPath, QSettings::IniFormat); + switch (bioDevType) { + case BIOTYPE_FACE: + settings.setValue("FC_DefaultDevice", deviceName); + break; + case BIOTYPE_FINGERPRINT: + settings.setValue("FP_DefaultDevice", deviceName); + break; + case BIOTYPE_FINGERVEIN: + settings.setValue("FV_DefaultDevice", deviceName); + break; + case BIOTYPE_IRIS: + settings.setValue("IR_DefaultDevice", deviceName); + break; + case BIOTYPE_VOICEPRINT: + settings.setValue("VP_DefaultDevice", deviceName); + break; + case REMOTE_QRCODE_TYPE: + settings.setValue("WC_DefaultDevice", deviceName); + break; + default: + break; + } + settings.sync(); + qDebug()<<"setDefaultDevice:"<serviceUid(msg.service()).value(); + struct passwd *pwinfo = getpwuid(uid); + if (pwinfo && pwinfo->pw_name) { + setDefaultDevice(pwinfo->pw_name, bioDevType, deviceName); + } else { + qInfo()<<"GetPWInfo failed!!"; + } +} + +QString ServiceInterface::getDefaultDevice(QString userName, int bioDevType) +{ + QString defaultDevice = ""; + QString configPath = QString(USER_CONFIG_PATH).arg(userName); + QSettings settings(configPath, QSettings::IniFormat); + // 获取用户旧的默认设备 + if (settings.contains("DefaultDevice")) { + QString strOldDefDev = settings.value("DefaultDevice").toString(); + if (!strOldDefDev.isEmpty()) { + for (auto devInfo : m_listDeviceInfos) { + if (devInfo && devInfo->device_shortname == strOldDefDev) { + QString strBioDefType = ""; + switch(devInfo->biotype) { + case BIOTYPE_FINGERPRINT: + strBioDefType = "FP_DefaultDevice"; + break; + case BIOTYPE_FINGERVEIN: + strBioDefType = "FV_DefaultDevice"; + break; + case BIOTYPE_IRIS: + strBioDefType = "IR_DefaultDevice"; + break; + case BIOTYPE_FACE: + strBioDefType = "FC_DefaultDevice"; + break; + case BIOTYPE_VOICEPRINT: + strBioDefType = "VP_DefaultDevice"; + break; + case REMOTE_QRCODE_TYPE: + strBioDefType = "WC_DefaultDevice"; + break; + default: + break; + } + if (!strBioDefType.isEmpty() && !settings.contains(strBioDefType)) { + settings.setValue(strBioDefType, strOldDefDev); + settings.setValue("DefaultDevice", ""); + settings.sync(); + } + if (bioDevType == devInfo->biotype) { + return strOldDefDev; + } + break; + } + } + } + } + switch (bioDevType) { + case BIOTYPE_FACE: + defaultDevice = settings.value("FC_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERPRINT: + defaultDevice = settings.value("FP_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERVEIN: + defaultDevice = settings.value("FV_DefaultDevice").toString(); + break; + case BIOTYPE_IRIS: + defaultDevice = settings.value("IR_DefaultDevice").toString(); + break; + case BIOTYPE_VOICEPRINT: + defaultDevice = settings.value("VP_DefaultDevice").toString(); + break; + case REMOTE_QRCODE_TYPE: + defaultDevice = settings.value("WC_DefaultDevice").toString(); + break; + default: + defaultDevice = settings.value("DefaultDevice").toString(); + break; + } + if(defaultDevice.isEmpty()) { + QSettings settings2(COMM_CONFIG_PATH, QSettings::IniFormat); + switch (bioDevType) { + case BIOTYPE_FACE: + defaultDevice = settings2.value("FC_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERPRINT: + defaultDevice = settings2.value("FP_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERVEIN: + defaultDevice = settings2.value("FV_DefaultDevice").toString(); + break; + case BIOTYPE_IRIS: + defaultDevice = settings2.value("IR_DefaultDevice").toString(); + break; + case BIOTYPE_VOICEPRINT: + defaultDevice = settings2.value("VP_DefaultDevice").toString(); + break; + case REMOTE_QRCODE_TYPE: + defaultDevice = settings2.value("WC_DefaultDevice").toString(); + break; + default: + defaultDevice = settings2.value("DefaultDevice").toString(); + break; + } + } + return defaultDevice; +} + +QStringList ServiceInterface::getAllDefaultDevice(QString userName) +{ + QStringList listDefDevice; + QString configPath = QString(USER_CONFIG_PATH).arg(userName); + QSettings settings(configPath, QSettings::IniFormat); + int nOldDefType = -1; + // 获取用户旧的默认设备 + if (settings.contains("DefaultDevice")) { + QString strOldDefDev = settings.value("DefaultDevice").toString(); + if (!strOldDefDev.isEmpty()) { + for (auto devInfo : m_listDeviceInfos) { + if (devInfo && devInfo->device_shortname == strOldDefDev) { + QString strBioDefType = ""; + switch(devInfo->biotype) { + case BIOTYPE_FINGERPRINT: + strBioDefType = "FP_DefaultDevice"; + break; + case BIOTYPE_FINGERVEIN: + strBioDefType = "FV_DefaultDevice"; + break; + case BIOTYPE_IRIS: + strBioDefType = "IR_DefaultDevice"; + break; + case BIOTYPE_FACE: + strBioDefType = "FC_DefaultDevice"; + break; + case BIOTYPE_VOICEPRINT: + strBioDefType = "VP_DefaultDevice"; + break; + case REMOTE_QRCODE_TYPE: + strBioDefType = "WC_DefaultDevice"; + break; + default: + break; + } + if (!strBioDefType.isEmpty() && !settings.contains(strBioDefType)) { + nOldDefType = devInfo->biotype; + listDefDevice.push_back(strOldDefDev); + settings.setValue(strBioDefType, strOldDefDev); + settings.setValue("DefaultDevice", ""); + settings.sync(); + } + break; + } + } + } + } + QSettings settings2(COMM_CONFIG_PATH, QSettings::IniFormat); + for (int nBioType = 0; nBioType <= REMOTE_QRCODE_TYPE; nBioType++) { + QString defaultDevice = ""; + if (nBioType == nOldDefType) + continue; + switch (nBioType) { + case BIOTYPE_FACE: + defaultDevice = settings.value("FC_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERPRINT: + defaultDevice = settings.value("FP_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERVEIN: + defaultDevice = settings.value("FV_DefaultDevice").toString(); + break; + case BIOTYPE_IRIS: + defaultDevice = settings.value("IR_DefaultDevice").toString(); + break; + case BIOTYPE_VOICEPRINT: + defaultDevice = settings.value("VP_DefaultDevice").toString(); + break; + case REMOTE_QRCODE_TYPE: + defaultDevice = settings.value("WC_DefaultDevice").toString(); + break; + default: + break; + } + if(defaultDevice.isEmpty()) { + switch (nBioType) { + case BIOTYPE_FACE: + defaultDevice = settings2.value("FC_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERPRINT: + defaultDevice = settings2.value("FP_DefaultDevice").toString(); + break; + case BIOTYPE_FINGERVEIN: + defaultDevice = settings2.value("FV_DefaultDevice").toString(); + break; + case BIOTYPE_IRIS: + defaultDevice = settings2.value("IR_DefaultDevice").toString(); + break; + case BIOTYPE_VOICEPRINT: + defaultDevice = settings2.value("VP_DefaultDevice").toString(); + break; + case REMOTE_QRCODE_TYPE: + defaultDevice = settings2.value("WC_DefaultDevice").toString(); + break; + default: + break; + } + } + if (!defaultDevice.isEmpty()) { + listDefDevice.push_back(defaultDevice); + } + } + return listDefDevice; +} + +//设置通用默认设备 +void ServiceInterface::setCommDefaultDevice(int bioDevType, QString deviceName) +{ + QSettings settings(COMM_CONFIG_PATH, QSettings::IniFormat); + switch (bioDevType) { + case BIOTYPE_FACE: + settings.setValue("FC_DefaultDevice", deviceName); + break; + case BIOTYPE_FINGERPRINT: + settings.setValue("FP_DefaultDevice", deviceName); + break; + case BIOTYPE_FINGERVEIN: + settings.setValue("FV_DefaultDevice", deviceName); + break; + case BIOTYPE_IRIS: + settings.setValue("IR_DefaultDevice", deviceName); + break; + case BIOTYPE_VOICEPRINT: + settings.setValue("VP_DefaultDevice", deviceName); + break; + case REMOTE_QRCODE_TYPE: + settings.setValue("WC_DefaultDevice", deviceName); + break; + default: + break; + } + settings.sync(); + qDebug()<<"setCommDefaultDevice:"<serviceUid(msg.service()).value(); + struct passwd *pwinfo = getpwuid(uid); + if (pwinfo && pwinfo->pw_name) { + QString configPath = QString(USER_CONFIG_PATH).arg(pwinfo->pw_name); + QSettings settings(configPath, QSettings::IniFormat); + switch (bioAuthType) { + case ENABLETYPE_BIO: + settings.setValue("EnableAuth", status); + break; + case ENABLETYPE_SAVER: + settings.setValue("SaverEnable", status); + break; + case ENABLETYPE_GREETER: + settings.setValue("GreeterEnable", status); + break; + case ENABLETYPE_POLKIT: + settings.setValue("PolkitEnable", status); + break; + case ENABLETYPE_SU: + settings.setValue("SuEnable", status); + break; + case ENABLETYPE_SUDO: + settings.setValue("SudoEnable", status); + break; + case ENABLETYPE_LOGIN: + settings.setValue("LoginEnable", status); + break; + default: + break; + } + settings.sync(); + emit bioAuthStatusChanged(pwinfo->pw_name, bioAuthType, status); + qDebug()<<"setBioAuthStatus:"<pw_name<<","< 0) { + qDebug()<<"onUSBDeviceHotPlug in:"< bioPath = iface.call("GetUnit","biometric-authentication.service"); + if(!bioPath.isValid()){ + return ; + } + + QDBusInterface bioface("org.freedesktop.systemd1", bioPath.value().path(), + "org.freedesktop.DBus.Properties", QDBusConnection::systemBus()); + QDBusReply sessionReply = bioface.call("Get", "org.freedesktop.systemd1.Unit", "UnitFileState"); + if(!sessionReply.isValid()) + qWarning() << sessionReply.error(); + else { + QString res = sessionReply.value().variant().toString(); + if(res == "disable") + return; + } + + qDebug()<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ get activeState"; + int times = 0; + while(times<20){ + QDBusReply sessionReply = bioface.call("Get", "org.freedesktop.systemd1.Unit", "ActiveState"); + if(!sessionReply.isValid()){ + qWarning() << sessionReply.error(); + return ; + } + else { + QString res = sessionReply.value().variant().toString(); + if(res == "activating"){ + times ++; + usleep(100000); + }else{ + break; + } + } + } + qDebug()<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ times = "< qlist; + QDBusVariant item; + DeviceInfo *deviceInfo; + + /* 返回值为 i -- int 和 av -- array of variant */ + QDBusPendingReply > reply = m_serviceInterface->call("GetDrvList"); + reply.waitForFinished(); + if (reply.isError()) { + qDebug() << "GUI:" << reply.error(); + deviceCount = 0; + return; + } + + /* 解析 DBus 返回值,reply 有两个返回值,都是 QVariant 类型 */ + variant = reply.argumentAt(0); /* 得到第一个返回值 */ + deviceCount = variant.value(); /* 解封装得到设备个数 */ + variant = reply.argumentAt(1); /* 得到第二个返回值 */ + argument = variant.value(); /* 解封装,获取QDBusArgument对象 */ + argument >> qlist; /* 使用运算符重载提取 argument 对象里面存储的列表对象 */ + + if (nDriId != -1) { // 指定设备接入 + for (int i = 0; i < deviceCount; i++) { + item = qlist[i]; /* 取出一个元素 */ + variant = item.variant(); /* 转为普通QVariant对象 */ + /* 解封装得到 QDBusArgument 对象 */ + argument = variant.value(); + deviceInfo = new DeviceInfo(); + argument >> *deviceInfo; /* 提取最终的 DeviceInfo 结构体 */ + if (nDriId == deviceInfo->device_id) { + if (getCommDefaultDevice(deviceInfo->biotype).isEmpty()) { + setCommDefaultDevice(deviceInfo->biotype, deviceInfo->device_shortname); + } + break; + } + } + } else { + for (auto devInfo : m_listDeviceInfos) { + if (devInfo) { + delete devInfo; + devInfo = nullptr; + } + } + m_listDeviceInfos.clear(); + for (int i = 0; i < deviceCount; i++) { + item = qlist[i]; /* 取出一个元素 */ + variant = item.variant(); /* 转为普通QVariant对象 */ + /* 解封装得到 QDBusArgument 对象 */ + argument = variant.value(); + deviceInfo = new DeviceInfo(); + argument >> *deviceInfo; /* 提取最终的 DeviceInfo 结构体 */ + m_listDeviceInfos.push_back(deviceInfo); + } + } +} + +void ServiceInterface::initData() +{ + // 沿用旧app enable + QSettings sysSettings(COMM_CONFIG_PATH, QSettings::IniFormat); + if(sysSettings.contains("EnableAuthApp") || sysSettings.contains("Functions/EnableAuthApp")) { + int nAppOldStatus = 0; + if (sysSettings.contains("Functions/EnableAuthApp")) { + nAppOldStatus = sysSettings.value("Functions/EnableAuthApp").toInt(); + } else { + nAppOldStatus = sysSettings.value("EnableAuthApp").toInt(); + } + if ((nAppOldStatus&0x01) && !sysSettings.contains("GreeterEnable")) { // greeter + sysSettings.setValue("GreeterEnable", true); + } + if ((nAppOldStatus&0x02) && !sysSettings.contains("SaverEnable")) { // saver + sysSettings.setValue("SaverEnable", true); + } + if ((nAppOldStatus&0x04) && !sysSettings.contains("PolkitEnable")) { // polkit + sysSettings.setValue("PolkitEnable", true); + } + if ((nAppOldStatus&0x08) && !sysSettings.contains("SudoEnable")) { // sudo + sysSettings.setValue("SudoEnable", true); + } + if ((nAppOldStatus&0x10) && !sysSettings.contains("SuEnable")) { // su + sysSettings.setValue("SuEnable", true); + } + if ((nAppOldStatus&0x20) && !sysSettings.contains("LoginEnable")) { // login + sysSettings.setValue("LoginEnable", true); + } + } + // 沿用旧的默认设备 + if(sysSettings.contains("DefaultDevice")) { + QString strOldDefDev = sysSettings.value("DefaultDevice").toString(); + if (!strOldDefDev.isEmpty()) { + for (auto devInfo : m_listDeviceInfos) { + if (devInfo && devInfo->device_shortname == strOldDefDev) { + QString strBioDefType = ""; + switch(devInfo->biotype) { + case BIOTYPE_FINGERPRINT: + strBioDefType = "FP_DefaultDevice"; + break; + case BIOTYPE_FINGERVEIN: + strBioDefType = "FV_DefaultDevice"; + break; + case BIOTYPE_IRIS: + strBioDefType = "IR_DefaultDevice"; + break; + case BIOTYPE_FACE: + strBioDefType = "FC_DefaultDevice"; + break; + case BIOTYPE_VOICEPRINT: + strBioDefType = "VP_DefaultDevice"; + break; + case REMOTE_QRCODE_TYPE: + strBioDefType = "WC_DefaultDevice"; + break; + default: + break; + } + if (!strBioDefType.isEmpty() && !sysSettings.contains(strBioDefType)) { + sysSettings.setValue(strBioDefType, strOldDefDev); + sysSettings.setValue("DefaultDevice", ""); + } + break; + } + } + } + } + // 设置未设置过默认设备的类型,如果驱动已打开且已连接 + for (auto devInfo : m_listDeviceInfos) { + if (devInfo && devInfo->device_available > 0 && devInfo->driver_enable > 0) { + QString strBioDefType = ""; + switch(devInfo->biotype) { + case BIOTYPE_FINGERPRINT: + strBioDefType = "FP_DefaultDevice"; + break; + case BIOTYPE_FINGERVEIN: + strBioDefType = "FV_DefaultDevice"; + break; + case BIOTYPE_IRIS: + strBioDefType = "IR_DefaultDevice"; + break; + case BIOTYPE_FACE: + strBioDefType = "FC_DefaultDevice"; + break; + case BIOTYPE_VOICEPRINT: + strBioDefType = "VP_DefaultDevice"; + break; + case REMOTE_QRCODE_TYPE: + strBioDefType = "WC_DefaultDevice"; + break; + default: + break; + } + if (!strBioDefType.isEmpty() && !sysSettings.contains(strBioDefType)) { + sysSettings.setValue(strBioDefType, devInfo->device_shortname); + } + } + } + sysSettings.sync(); +} + +void ServiceInterface::onBiometricDbusChanged(bool bActive) +{ + qDebug()<<"BiometricDbus:"<. + * +**/ +#ifndef SERVICEINTERFACE_H +#define SERVICEINTERFACE_H + +#include "biodeviceinfo.h" +#include +#include +#include +#include + +#define DBUS_SERVICE "org.ukui.Biometric" +#define DBUS_PATH "/org/ukui/Biometric" +#define DBUS_INTERFACE "org.ukui.Biometric" + +enum authEnableType { + ENABLETYPE_BIO, // 全局总使能 + ENABLETYPE_SAVER, // 锁屏 + ENABLETYPE_GREETER, // 登录 + ENABLETYPE_POLKIT, // 授权 + ENABLETYPE_SU, // 暂保留 + ENABLETYPE_SUDO, // 暂保留 + ENABLETYPE_LOGIN, // 暂保留 +}; + +class ServiceInterface : public QObject, protected QDBusContext +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.ukui.UniauthBackend") +public: + ServiceInterface(); + +public slots: + // 设置默认设备 + void setDefaultDevice(int bioDevType, QString deviceName); + // 获取默认设备 + QString getDefaultDevice(QString userName, int bioDevType); + // 获取所有默认设备 + QStringList getAllDefaultDevice(QString userName); + //生物特征开关接口 + bool getBioAuthStatus(QString userName, int bioAuthType); + void setBioAuthStatus(int bioAuthType, bool status); + // 获取最大失败次数 + int getMaxFailedTimes(); + // 获取是否使能微信扫码登录 + bool getQRCodeEnable(); + // 获取是否双认证 + bool getDoubleAuth(); + // 获取用户绑定 + bool getUserBind(); + // 获取是否在控制面板显示 + bool getIsShownInControlCenter(); + // 获取是否使用第一个设备 + bool getUseFirstDevice(); + // 获取是否隐藏切换按钮 + bool getHiddenSwitchButton(); + +private slots: + void onUSBDeviceHotPlug(int drvid, int action, int deviceNum); + void onBiometricDbusChanged(bool bActive); + +signals: + //默认设备改变 + void defaultDeviceChanged(QString userName, int bioDevType, QString deviceName); + //开关状态改变 + void bioAuthStatusChanged(QString userName, int type, bool status); + +private: + //设置默认设备 + void setDefaultDevice(QString userName, int bioDevType, QString deviceName); + //设置通用默认设备 + void setCommDefaultDevice(int bioDevType, QString deviceName); + //获取通用默认设备 + QString getCommDefaultDevice(int bioDevType); + // 获取旧版app使能值 + int getOldAppStatus(); + // 初始化数据 + void initData(); + // 更新通用默认设备 + void updateCommDefaultDevice(int nDriId); + // 等待生物识别服务 + void waitBiometricServiceStatus(); + +private: + QDBusInterface *m_serviceInterface = nullptr; + QList m_listDeviceInfos; + int deviceCount = 0; +}; + +#endif // SERVICEINTERFACE_H diff --git a/uniauth-backend/src/servicemanager.cpp b/uniauth-backend/src/servicemanager.cpp new file mode 100644 index 0000000..7219d32 --- /dev/null +++ b/uniauth-backend/src/servicemanager.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ + +#include "servicemanager.h" +#include +#include + +#define SERVICE "biometric-authentication.service" +#define DBUS_SERVICE "org.ukui.Biometric" +#define DBUS_PATH "/org/ukui/Biometric" +#define DBUS_INTERFACE "org.ukui.Biometric" + +#define FD_DBUS_SERVICE "org.freedesktop.DBus" +#define FD_DBUS_PATH "/org/freedesktop/DBus" +#define FD_DBUS_INTERFACE "org.freedesktop.DBus" + +ServiceManager *ServiceManager::instance_ = nullptr; + +ServiceManager::ServiceManager(QObject *parent) + : QObject(parent), + dbusService(nullptr), + bioService(nullptr) +{ + init(); +} + +void ServiceManager::init() +{ + if(!dbusService) + { + dbusService = new QDBusInterface(FD_DBUS_SERVICE, + FD_DBUS_PATH, + FD_DBUS_INTERFACE, + QDBusConnection::systemBus()); + connect(dbusService, SIGNAL(NameOwnerChanged(QString, QString, QString)), + this, SLOT(onDBusNameOwnerChanged(QString,QString,QString))); + } +} + +ServiceManager *ServiceManager::instance() +{ + if(!instance_) + { + instance_ = new ServiceManager; + } + return instance_; +} + +bool ServiceManager::connectToService() +{ + if(!bioService) + { + bioService = new QDBusInterface(DBUS_SERVICE, + DBUS_PATH, + DBUS_INTERFACE, + QDBusConnection::systemBus()); + } + return bioService->isValid(); +} + +void ServiceManager::onDBusNameOwnerChanged(const QString &name, + const QString &oldOwner, + const QString &newOwner) +{ + if(name == DBUS_SERVICE) + { + qDebug() << "service status changed:" + << (newOwner.isEmpty() ? "inactivate" : "activate"); + Q_EMIT serviceStatusChanged(!newOwner.isEmpty()); + } +} + +/*! + * \brief checkServiceExist + * 检查生物识别后台服务是否已启动 + */ +bool ServiceManager::serviceExists() +{ + QDBusReply reply = dbusService->call("NameHasOwner", DBUS_SERVICE); + if(!reply.isValid()) + { + qDebug() << "check service exists error:" << reply.error(); + return false; + } + return reply.value(); +} diff --git a/uniauth-backend/src/servicemanager.h b/uniauth-backend/src/servicemanager.h new file mode 100644 index 0000000..0128b38 --- /dev/null +++ b/uniauth-backend/src/servicemanager.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ + +#ifndef SERVICEMANAGER_H +#define SERVICEMANAGER_H + +#include +#include + +class ServiceManager : public QObject +{ + Q_OBJECT +public: + static ServiceManager *instance(); + bool serviceExists(); + +private: + explicit ServiceManager(QObject *parent = nullptr); + void init(); + bool connectToService(); + +Q_SIGNALS: + void serviceStatusChanged(bool activate); + +public Q_SLOTS: + void onDBusNameOwnerChanged(const QString &name, + const QString &oldOwner, + const QString &newOwner); + +private: + static ServiceManager *instance_; + QDBusInterface *dbusService; + QDBusInterface *bioService; + bool serviceStatus; +}; + +#endif // SERVICEMANAGER_H