From 9234037bda8171712106b3dd920c1040aaf4b678 Mon Sep 17 00:00:00 2001 From: huayadong Date: Thu, 9 Dec 2021 17:44:44 +0800 Subject: [PATCH] sssss --- data/org.ukui.screensaver.gschema.xml | 2 +- data/ukui-screensaver-qt | 15 +- debian/changelog | 18 -- debian/control | 5 +- debian/copyright | 1 + debian/source/format | 2 +- screensaver/language/screensaver-zh_CN.ini | 4 +- screensaver/screensaver.cpp | 2 +- screensaver/sleeptime.cpp | 6 +- screensaver/sleeptime.h | 1 + src/CMakeLists.txt | 14 +- src/authdialog.cpp | 7 +- src/authdialog.h | 3 +- src/configuration.cpp | 4 - src/fullbackgroundwidget.cpp | 21 +- src/interface.cpp | 99 +------ src/interface.h | 9 - src/lockwidget.cpp | 14 +- src/lockwidget.h | 1 - src/org.ukui.ScreenSaver.xml | 2 - src/pam-tally.c | 323 +++++++++++++++++++++ src/pam-tally.h | 54 ++-- src/screensaver.cpp | 1 - src/screensaverwidget.cpp | 11 +- src/ukui-screensaver-backend.cpp | 19 ++ src/ukui-screensaver-dialog.cpp | 6 +- 26 files changed, 423 insertions(+), 221 deletions(-) create mode 100644 src/pam-tally.c diff --git a/data/org.ukui.screensaver.gschema.xml b/data/org.ukui.screensaver.gschema.xml index daf72b7..1fd0c86 100755 --- a/data/org.ukui.screensaver.gschema.xml +++ b/data/org.ukui.screensaver.gschema.xml @@ -99,7 +99,7 @@ Allow the session status message to be displayed when the screen is locked. - '/usr/share/backgrounds/warty-final-ubuntukylin.jpg' + '' the background iamge of lockscreen Allow the user to set the background iamge of lockscreen. diff --git a/data/ukui-screensaver-qt b/data/ukui-screensaver-qt index ae19643..6af045a 100755 --- a/data/ukui-screensaver-qt +++ b/data/ukui-screensaver-qt @@ -1,4 +1,11 @@ -auth include system-auth -account include system-auth -password include system-auth -session include system-auth \ No newline at end of file +@include common-auth +auth optional pam_gnome_keyring.so + + +#If you are using Arch,comment out the +#above and use the following. + +#auth include system-auth +#account include system-auth +#password include system-auth +#session include system-auth diff --git a/debian/changelog b/debian/changelog index 843e20c..60f2269 100755 --- a/debian/changelog +++ b/debian/changelog @@ -1,21 +1,3 @@ -ukui-screensaver (3.0.2-1~0804) unstable; urgency=medium - - * New upstream release. - - -- handsome_feng Thu, 05 Aug 2021 14:22:40+0800 - -ukui-screensaver (3.0.1-1) unstable; urgency=medium - - * New upstream bugfix release. - - -- handsome_feng Sun, 27 Sep 2020 14:47:09 +0800 - -ukui-screensaver (3.0.0-1+1031) focal; urgency=medium - - * Daily build. - - -- liuliang Mon, 27 May 2019 15:48:18 +0800 - ukui-screensaver (3.0.0-1) unstable; urgency=medium * New upstream release. diff --git a/debian/control b/debian/control index d5fcc83..cdfa10f 100755 --- a/debian/control +++ b/debian/control @@ -12,12 +12,9 @@ Build-Depends: debhelper-compat (= 12), qttools5-dev, qttools5-dev-tools, libglib2.0-dev, - libopencv-dev, libx11-dev, libxtst-dev, - libgsettings-qt-dev, - libkf5windowsystem-dev, - libmatemixer-dev + libgsettings-qt-dev Standards-Version: 4.5.0 Rules-Requires-Root: no Homepage: https://www.github.com/ukui/ukui-screensaver diff --git a/debian/copyright b/debian/copyright index a79795b..9920bbb 100755 --- a/debian/copyright +++ b/debian/copyright @@ -10,6 +10,7 @@ Files: CMakeLists.txt debian/* screensaver/* Common/* + .gitmodules Copyright: 2018, Tianjin KYLIN Information Technology Co., Ltd. License: GPL-3+ diff --git a/debian/source/format b/debian/source/format index 89ae9db..163aaf8 100755 --- a/debian/source/format +++ b/debian/source/format @@ -1 +1 @@ -3.0 (native) +3.0 (quilt) diff --git a/screensaver/language/screensaver-zh_CN.ini b/screensaver/language/screensaver-zh_CN.ini index 0b1b594..aefa4d5 100755 --- a/screensaver/language/screensaver-zh_CN.ini +++ b/screensaver/language/screensaver-zh_CN.ini @@ -136,13 +136,13 @@ OL=我将永远忠于自己,披星戴月的奔向理想与自由。 author=佚名 [41] OL=有一天,我看了43次日落! -author=《小王子》 +author=佚名 [42] OL=当太阳升到最高点的时候,影子就不见了。 author=佚名 [43] OL=拯救地球好累,虽然有些疲惫但我还是会。 -author=《超人不会飞》 +author=佚名 [44] OL=陌上花开,可缓缓归矣 author=佚名 diff --git a/screensaver/screensaver.cpp b/screensaver/screensaver.cpp index 1739afd..5a7deaa 100755 --- a/screensaver/screensaver.cpp +++ b/screensaver/screensaver.cpp @@ -57,7 +57,6 @@ Screensaver::Screensaver(QWidget *parent): m_timer(nullptr) { installEventFilter(this); - setWindowFlags(Qt::X11BypassWindowManagerHint); setUpdateCenterWidget(); initUI(); m_background = new MBackground(); @@ -408,6 +407,7 @@ void Screensaver::setSleeptime() { sleepTime = new SleepTime(this); sleepTime->adjustSize(); + sleepTime->setInitTime(QDateTime::currentDateTime()); updateDate(); } diff --git a/screensaver/sleeptime.cpp b/screensaver/sleeptime.cpp index cc92fa4..2cf1f63 100755 --- a/screensaver/sleeptime.cpp +++ b/screensaver/sleeptime.cpp @@ -74,7 +74,11 @@ void SleepTime::init() layout->addWidget(restTime); - initTime = QDateTime::currentDateTime(); +} + +int SleepTime::setInitTime(QDateTime time) +{ + initTime = time; } int SleepTime::setTime(QDateTime time) diff --git a/screensaver/sleeptime.h b/screensaver/sleeptime.h index 7ed618a..5bc6d7a 100755 --- a/screensaver/sleeptime.h +++ b/screensaver/sleeptime.h @@ -33,6 +33,7 @@ public: explicit SleepTime(QWidget *parent = nullptr); ~SleepTime(); int setTime(QDateTime time); + int setInitTime(QDateTime time); private: QLabel *restTime; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f2e32c..62bb23e 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,7 @@ qt5_add_resources(dialog_SRC # 头文件中包含了Xlib.h,需要单独拿出来处理,不知道原因 qt5_wrap_cpp(dialog_SRC + pam-tally.h fullbackgroundwidget.h lockwidget.h authdialog.h @@ -47,16 +48,16 @@ qt5_wrap_cpp(dialog_SRC xeventmonitor.h monitorwatcher.h configuration.h - users.h - displaymanager.h + users.h + displaymanager.h iconedit.h powermanager.h - logind.h - pam-tally.h + logind.h ) set(dialog_SRC ${dialog_SRC} + pam-tally.c ukui-screensaver-dialog.cpp fullbackgroundwidget.cpp lockwidget.cpp @@ -72,8 +73,7 @@ set(dialog_SRC users.cpp displaymanager.cpp iconedit.cpp - logind.cpp - pam-tally.cpp + logind.cpp ) add_executable(ukui-screensaver-dialog ${dialog_SRC}) @@ -83,7 +83,7 @@ target_link_libraries(ukui-screensaver-dialog Qt5::DBus Qt5::X11Extras ${EXTRA_LIBS} - BiometricAuth + BiometricAuth VirtualKeyboard Common ) diff --git a/src/authdialog.cpp b/src/authdialog.cpp index d94f775..bf25009 100755 --- a/src/authdialog.cpp +++ b/src/authdialog.cpp @@ -31,7 +31,6 @@ #include "biometricproxy.h" #include "biometricauthwidget.h" #include "biometricdeviceswidget.h" -#include "pam-tally.h" AuthDialog::AuthDialog(const UserItem &user, QWidget *parent) : QWidget(parent), @@ -42,11 +41,12 @@ AuthDialog::AuthDialog(const UserItem &user, QWidget *parent) : m_biometricProxy(nullptr), m_biometricAuthWidget(nullptr), m_biometricDevicesWidget(nullptr), - pamTally(PamTally::instance(this)), m_buttonsWidget(nullptr) { initUI(); + pam_tally_init(); + connect(auth, &Auth::showMessage, this, &AuthDialog::onShowMessage); connect(auth, &Auth::showPrompt, this, &AuthDialog::onShowPrompt); connect(auth, &Auth::authenticateComplete, this, &AuthDialog::onAuthComplete); @@ -251,8 +251,7 @@ void AuthDialog::onAuthComplete() } else { - if(pamTally->getDeny() == 0) - onShowMessage(tr("Password Incorrect, Please try again"), + onShowMessage(tr("Password Incorrect, Please try again"), Auth::MessageTypeError); //认证失败,重新认证 diff --git a/src/authdialog.h b/src/authdialog.h index 6572152..837c6dd 100755 --- a/src/authdialog.h +++ b/src/authdialog.h @@ -27,6 +27,7 @@ #include "types.h" #include "users.h" #include "biometricdeviceinfo.h" +#include "pam-tally.h" namespace Ui { @@ -40,7 +41,6 @@ class Auth; class BiometricProxy; class BiometricAuthWidget; class BiometricDevicesWidget; -class PamTally; extern float scale; class AuthDialog : public QWidget @@ -129,7 +129,6 @@ private: QWidget *m_passwdWidget; //放置密码输入框和信息列表 IconEdit *m_passwordEdit; //密码输入框 QLabel *m_messageLabel; //PAM消息显示 - PamTally *pamTally; }; #endif // AUTHDIALOG_H diff --git a/src/configuration.cpp b/src/configuration.cpp index f67f844..6590172 100755 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -141,10 +141,6 @@ ScreenSaver *Configuration::getScreensaver() break; } case SAVER_SINGLE: - if(themes.count()==0){ - saver->path = "/usr/lib/ukui-screensaver/ukui-screensaver-default"; - break; - } saver->path = getXScreensaverPath(themes[0]); break; case SAVER_IMAGE: diff --git a/src/fullbackgroundwidget.cpp b/src/fullbackgroundwidget.cpp index d7bccb5..46795d0 100755 --- a/src/fullbackgroundwidget.cpp +++ b/src/fullbackgroundwidget.cpp @@ -165,7 +165,7 @@ FullBackgroundWidget::FullBackgroundWidget(QWidget *parent) init(); qApp->installNativeEventFilter(this); - installEventFilter(this); + QTimer::singleShot(500,this,SLOT(switchToLinux())); } @@ -213,7 +213,7 @@ bool FullBackgroundWidget::eventFilter(QObject *obj, QEvent *event) if(event->type() == QEvent::WindowDeactivate){ QTimer::singleShot(50,this,SLOT(laterActivate())); }else if(event->type() == QEvent::WindowActivate){ - QTimer::singleShot(200,this,SLOT(setLockState())); + QTimer::singleShot(500,this,SLOT(setLockState())); } return false; } @@ -516,10 +516,7 @@ void FullBackgroundWidget::onGlobalButtonDrag(int xPos, int yPos) ScreenSaver *saver = configuration->getScreensaver(); if(saver->path == "/usr/lib/ukui-screensaver/ukui-screensaver-default") return ; - if(screenStatus & SCREEN_SAVER) - { - clearScreensavers(); - } + clearScreensavers(); } } @@ -529,11 +526,8 @@ void FullBackgroundWidget::onScreenCountChanged(int) QSize newSize = monitorWatcher->getVirtualSize(); setGeometry(0, 0, newSize.width(), newSize.height()); //repaint(); - if(screenStatus & SCREEN_SAVER) - { - clearScreensavers(); - } update(); + clearScreensavers(); } void FullBackgroundWidget::onDesktopResized() @@ -542,11 +536,8 @@ void FullBackgroundWidget::onDesktopResized() setGeometry(desktop->geometry()); if(lockWidget) onCursorMoved(cursor().pos()); - if(screenStatus & SCREEN_SAVER) - { - clearScreensavers(); - } - //repaint(); +// clearScreensavers(); + //repaint(); update(); } diff --git a/src/interface.cpp b/src/interface.cpp index 37de99b..5801ec9 100755 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -19,16 +19,11 @@ #include #include #include -#include -#include #include -#include #include Interface::Interface(QObject *parent) - : QObject(parent), - m_timerCount(0), - m_timer(nullptr) + : QObject(parent) { lockState = false; m_logind = new LogindIntegration(this); @@ -43,13 +38,6 @@ Interface::Interface(QObject *parent) } ); - QDBusInterface *iface = new QDBusInterface("org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - QDBusConnection::systemBus(), - this); - connect(iface, SIGNAL(PrepareForSleep(bool)), this, SLOT(onPrepareForSleep(bool))); - inhibit(); } bool Interface::GetLockState() @@ -62,52 +50,37 @@ void Interface::SetLockState() lockState = true; } -void Interface::emitLockState() -{ - QDBusMessage message = QDBusMessage::createSignal(SS_DBUS_PATH, - SS_DBUS_INTERFACE, - "lock"); - QDBusConnection::sessionBus().send(message); -} - void Interface::Lock() { - if(process.state() != QProcess::NotRunning) - return ; qDebug() << "Lock requested"; lockState = false; QString cmd = QString("/usr/bin/ukui-screensaver-dialog --lock"); qDebug() << cmd; process.start(cmd); - emitLockState(); + } void Interface::onSessionIdleReceived() { - if(process.state() != QProcess::NotRunning) - return ; - qDebug() << "emit SessionIdle"; lockState = false; QString cmd = QString("/usr/bin/ukui-screensaver-dialog --session-idle"); qDebug() << cmd; + process.start(cmd); - emitLockState(); + } void Interface::onShowScreensaver() { - if(process.state() != QProcess::NotRunning) - return ; - qDebug() << "lock and show screensaver"; lockState = false; QString cmd = QString("/usr/bin/ukui-screensaver-dialog --screensaver"); qDebug() << cmd; process.start(cmd); - emitLockState(); + } bool Interface::checkExistChild() @@ -136,65 +109,3 @@ void Interface::onNameLost(const QString &serviceName) if(serviceName == "cn.kylinos.ScreenSaver") exit(0); } - -void Interface::onPrepareForSleep(bool sleep) -{ - - if(sleep) - { - if(GetLockState()){ - uninhibit(); - return; - } - - this->Lock(); - - if(!m_timer){ - m_timer = new QTimer(this); - connect(m_timer, &QTimer::timeout, this, [&]{ - m_timerCount+=1; - - if(GetLockState() || m_timerCount>20){ - m_timer->stop(); - m_timerCount = 0; - uninhibit(); - } - }); - } - m_timer->start(100); - } - else - { - inhibit(); - } -} - -void Interface::inhibit() -{ - if (m_inhibitFileDescriptor.isValid()) { - return; - } - - QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - QStringLiteral("Inhibit")); - message.setArguments(QVariantList({QStringLiteral("sleep"), - "Screen Locker Backend", - "Ensuring that the screen gets locked before going to sleep", - QStringLiteral("delay")})); - QDBusPendingReply reply = QDBusConnection::systemBus().call(message); - if (!reply.isValid()) { - return; - } - reply.value().swap(m_inhibitFileDescriptor); -} - -void Interface::uninhibit() -{ - if (!m_inhibitFileDescriptor.isValid()) { - return; - } - - m_inhibitFileDescriptor = QDBusUnixFileDescriptor(); -} diff --git a/src/interface.h b/src/interface.h index 38209c8..f6889d9 100755 --- a/src/interface.h +++ b/src/interface.h @@ -21,8 +21,6 @@ #include #include #include -#include -#include #include "types.h" #include "logind.h" @@ -48,17 +46,10 @@ public Q_SLOTS: void onSessionIdleReceived(); void onShowScreensaver(); void onNameLost(const QString&); - void onPrepareForSleep(bool sleep); private: bool checkExistChild(); - void inhibit(); - void uninhibit(); bool lockState; - void emitLockState(); - int m_timerCount; - QTimer *m_timer; - QDBusUnixFileDescriptor m_inhibitFileDescriptor; private: QProcess process; diff --git a/src/lockwidget.cpp b/src/lockwidget.cpp index 0b75b6d..3ab66a5 100755 --- a/src/lockwidget.cpp +++ b/src/lockwidget.cpp @@ -52,10 +52,6 @@ LockWidget::LockWidget(QWidget *parent) authDialog, &AuthDialog::onCapsLockChanged); this->installEventFilter(this); initUI(); - - if(users->getUsers().count() < 2){ - ui->btnSwitchUser->hide(); - } } LockWidget::~LockWidget() @@ -191,7 +187,7 @@ void LockWidget::showPowerManager() authDialog->show(); powermanager->hide(); } - else{ + else{ authDialog->hide(); powermanager->show(); powermanager->setGeometry((width()-ITEM_WIDTH*5)/2, @@ -282,14 +278,6 @@ void LockWidget::initUserMenu() } } -void LockWidget::keyReleaseEvent(QKeyEvent *e) -{ - if(e->key() == Qt::Key_K){ - if(e->modifiers() & Qt::ControlModifier) - showVirtualKeyboard(); - } -} - /* lockscreen follows cursor */ void LockWidget::resizeEvent(QResizeEvent *event) { diff --git a/src/lockwidget.h b/src/lockwidget.h index 0e8d586..311b872 100755 --- a/src/lockwidget.h +++ b/src/lockwidget.h @@ -69,7 +69,6 @@ private Q_SLOTS: protected: bool eventFilter(QObject *obj, QEvent *event); void resizeEvent(QResizeEvent *event); - void keyReleaseEvent(QKeyEvent *e); private: Ui::LockWidget *ui; diff --git a/src/org.ukui.ScreenSaver.xml b/src/org.ukui.ScreenSaver.xml index 85d08c2..cd4fa9e 100755 --- a/src/org.ukui.ScreenSaver.xml +++ b/src/org.ukui.ScreenSaver.xml @@ -3,8 +3,6 @@ - - diff --git a/src/pam-tally.c b/src/pam-tally.c new file mode 100644 index 0000000..53bd377 --- /dev/null +++ b/src/pam-tally.c @@ -0,0 +1,323 @@ +/* + * 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 "pam-tally.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +//#include "gs-debug.h" + +char shm_tally_real[128]; + +#define FILE_MODE (S_IRUSR | S_IWUSR) + +#define CONFIG_FILE "/usr/share/lightdm/lightdm.conf.d/96-kylin-setting.conf" + + + +static +int get_is_open_other_authentication() +{ + char buf[128]; + FILE *config_file; + + if( (config_file = fopen(CONFIG_FILE, "r")) == NULL) + { + //gs_debug("open %s failed", CONFIG_FILE); + return 0; + } + + int open_other_authentication = 0; + while(fgets(buf, sizeof(buf), config_file)) { + if(strlen(buf) == 0 || buf[0] == '#') + { + memset(buf, sizeof(buf), 0); + continue; + } + if(buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = '\0'; + + char *p = strchr(buf, '='); + if(!p) + continue; + *p = '\0'; + + size_t len = strlen(buf); + if(len == 0) + continue; + //去掉=之前的空格 + while(len--) + if(buf[len] == ' ' || buf[len] == '\t') + buf[len] = '\0'; + if(strcmp(buf, "open-other-authentication") != 0) + continue; + + p++; + len = strlen(p); + if(len == 0) + break; + //去掉等号之后的空格 + while(*p == ' ' || *p == '\t') + { + p++; + len--; + } + //去掉尾部空格 + while(len--) + if(*(p+len) == ' ' || *(p+len) == '\t') + *(p+len) = '\0'; + + if(*p == '0') + break; + if(*p == '1') + { + open_other_authentication = 1; + break; + } + } + fclose(config_file); + //gs_debug("--------------------------%d", open_other_authentication); + return open_other_authentication; +} + +static +int get_pam_tally(int *deny, int *unlock_time) +{ + char buf[128]; + FILE *auth_file; + + if( (auth_file = fopen("/etc/pam.d/common-auth", "r")) == NULL) + return -1; + + while(fgets(buf, sizeof(buf), auth_file)) { + if(strlen(buf) == 0 || buf[0] == '#') + continue; + if(!strstr(buf, "deny")) + continue; + + char *ptr = strtok(buf, " \t"); + while(ptr) { + if(strncmp(ptr, "deny=", 5)==0){ + sscanf(ptr, "deny=%d", deny); + //gs_debug("-------------------- deny=%d", *deny); + } + if(strncmp(ptr, "unlock_time=", 12)==0){ + sscanf(ptr, "unlock_time=%d", unlock_time); + //gs_debug("-------------------- unlock_time=%d", *unlock_time); + } + ptr = strtok(NULL, " \t"); + } + return 1; + } + return 0; +} + +static +void set_shm_tally_real() +{ + sprintf(shm_tally_real, "%s_%d", SHM_TALLY, getuid()); +} + +int pam_tally_init() +{ + int fd; + int deny = 0, unlock_time = 0; + pam_tally *tally_ptr; + + set_shm_tally_real(); + + printf("shm path =========== : %s\n", shm_tally_real); + + shm_unlink(shm_tally_real); + + if(get_is_open_other_authentication()) + { + //gs_debug("open other authentication, disable pam_tally."); + return 0; + } + if(!get_pam_tally(&deny, &unlock_time)) + { + //gs_debug("get pam_tally configuration failed, disable pam_tally."); + return 0; + } + + /* if(deny <= 0) + deny = 3; + if(unlock_time <= 0) + unlock_time = 1800; +*/ + if( (fd = shm_open(shm_tally_real, O_RDWR | O_CREAT, FILE_MODE)) == -1) + { + printf("shm_open error: %s\n", strerror(errno)); + return -1; + } + + ftruncate(fd, sizeof(pam_tally)); + + if( (tally_ptr = mmap(NULL, sizeof(pam_tally), + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) + { + //gs_debug("mmap error: %s", strerror(errno)); + close(fd); + return -1; + } + close(fd); + + tally_ptr->deny = deny; + tally_ptr->unlock_time = unlock_time; + tally_ptr->failed = 0; + tally_ptr->lock_start_time = 0; + + return 1; +} + +static +pam_tally* pam_tally_memory() +{ + int fd; + pam_tally *tally_ptr; + + set_shm_tally_real(); + + if( (fd = shm_open(shm_tally_real, O_RDWR, FILE_MODE)) == -1) + { + //gs_debug("shm_open error: %s", strerror(errno)); + return NULL; + } + + if( (tally_ptr = mmap(NULL, sizeof(pam_tally), + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) + { + //gs_debug("mmap error: %s", strerror(errno)); + close(fd); + return NULL; + } + close(fd); + return tally_ptr; +} + +int pam_tally_is_enbled() +{ + int fd; + + set_shm_tally_real(); + + if( (fd = shm_open(shm_tally_real, O_RDONLY, FILE_MODE)) == -1) + { + printf("shm_open error: %s\n", strerror(errno)); + return 0; + } + + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + if(tally_ptr->deny == 0 || tally_ptr->unlock_time == 0) + return 0; + return 1; +} + +int pam_tally_add_failed() +{ + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + tally_ptr->failed++; + + //如果失败次数达到上限,开始计时 + if(tally_ptr->failed >= tally_ptr->deny) + tally_ptr->lock_start_time = time(NULL); + + return 0; +} + +int pam_tally_clear_failed() +{ + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + tally_ptr->failed = 0; + tally_ptr->lock_start_time = 0; + return 0; +} + +int pam_tally_failure_is_out() +{ + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + return (tally_ptr->failed >= tally_ptr->deny ? 1 : 0); +} + +int pam_tally_deny() +{ + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + return tally_ptr->deny; +} + +int pam_tally_failed_count() +{ + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + return tally_ptr->failed; +} + +int pam_tally_unlock_time() +{ + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + printf("########################### unlock time = %d\n", tally_ptr->unlock_time); + return tally_ptr->unlock_time; +} + +int pam_tally_is_canUnlock() +{ + pam_tally *tally_ptr; + + if((tally_ptr = pam_tally_memory()) == NULL) + return -1; + + if(tally_ptr->failed >= tally_ptr->deny && + time(NULL) - tally_ptr->lock_start_time < tally_ptr->unlock_time) + return 0; + return 1; +} diff --git a/src/pam-tally.h b/src/pam-tally.h index 07708c5..19c52d6 100755 --- a/src/pam-tally.h +++ b/src/pam-tally.h @@ -1,9 +1,9 @@ -/* configuration.h +/* * 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 2, or (at your option) + * 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, @@ -12,34 +12,38 @@ * 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, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with this program; if not, see . + * **/ #ifndef PAM_TALLY_H #define PAM_TALLY_H -#include - -class PamTally : public QObject -{ - Q_OBJECT -private: - explicit PamTally(QObject *parent = nullptr); +#include -public: - static PamTally *instance(QObject *parent = nullptr); - int getDeny(); - unsigned long long getUnlockTime(); - unsigned long long getRootUnlockTime(); +#ifdef __cplusplus +extern "C" { +#endif -private: - int deny; - unsigned long long unlock_time; - unsigned long long root_unlock_time; - static PamTally *instance_; - - int parsePamConfig(); +#define SHM_TALLY "/shm_tally" +struct _pam_tally { + int deny; //失败次数上限 + int unlock_time; //失败次数达到上限后,多少秒之后才能解锁 + int failed; //当前失败的次数 + time_t lock_start_time; //失败次数达到上限后,开始计时 }; +typedef struct _pam_tally pam_tally; + +int pam_tally_init(); +int pam_tally_add_failed(); +int pam_tally_clear_failed(); +int pam_tally_falure_is_out(); +int pam_tally_deny(); +int pam_tally_failed_count(); +int pam_tally_unlock_time(); +int pam_tally_is_enbled(); +int pam_tally_is_canUnlock(); +#ifdef __cplusplus +} +#endif -#endif // CONFIGURATION_H +#endif // PAM_TALLY_H diff --git a/src/screensaver.cpp b/src/screensaver.cpp index 8e35ab1..601b325 100755 --- a/src/screensaver.cpp +++ b/src/screensaver.cpp @@ -63,7 +63,6 @@ bool ScreenSaver::exists() case SAVER_IMAGE: return QDir(path).exists(); } - return false; } void ScreenSaver::startSwitchImages() diff --git a/src/screensaverwidget.cpp b/src/screensaverwidget.cpp index d691786..8f9efd3 100755 --- a/src/screensaverwidget.cpp +++ b/src/screensaverwidget.cpp @@ -37,15 +37,10 @@ ScreenSaverWidget::ScreenSaverWidget(ScreenSaver *screensaver, QWidget *parent) setFocus(); this->installEventFilter(this); - //QPalette plt; - //plt.setBrush(QPalette::Window, Qt::black); - //setPalette(plt); - QPalette pal(palette()); - pal.setColor(QPalette::Background, Qt::black); //设置背景黑色 - + QPalette plt; + plt.setBrush(QPalette::Window, Qt::black); + setPalette(plt); setAutoFillBackground(true); - setPalette(pal); - switch(screensaver->mode) { case SAVER_RANDOM: case SAVER_SINGLE: diff --git a/src/ukui-screensaver-backend.cpp b/src/ukui-screensaver-backend.cpp index ccf4e3a..b333fd4 100755 --- a/src/ukui-screensaver-backend.cpp +++ b/src/ukui-screensaver-backend.cpp @@ -60,7 +60,25 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + // 如果已经有实例在运行则kill, 主要是针对注销后重新登录时之前的实例没有被kill掉 + char cmd[128] = {0}; + char str[16]; FILE *fp; + int pid; + + int n = sprintf(cmd, "ps aux | grep ukui-screensaver-backend | grep %s | grep -v grep | awk '{print $2}'", getenv("USER")); + Q_UNUSED(n) + + fp = popen(cmd, "r"); + while(fgets(str, sizeof(str)-1, fp)) { + pid = atoi(str); + + if(pid > 0 && pid != getpid()) { + qDebug() << "existing instance pid: " << pid; + kill(pid, SIGKILL); + } + } + pclose(fp); // for PowerManager fp = popen("xset s 0 0", "r"); @@ -101,5 +119,6 @@ int main(int argc, char *argv[]) QObject::connect(checkInterface, SIGNAL(NameLost(QString)), interface, SLOT(onNameLost(QString))); + return a.exec(); } diff --git a/src/ukui-screensaver-dialog.cpp b/src/ukui-screensaver-dialog.cpp index 237b377..d78dafb 100755 --- a/src/ukui-screensaver-dialog.cpp +++ b/src/ukui-screensaver-dialog.cpp @@ -78,8 +78,7 @@ void checkIsRunning() struct flock lock; const QString PID_DIR = QString("/var/run/user/%1").arg(QString::number(getuid())); - QString env = qgetenv("DISPLAY"); - const QString PID_FILE = PID_DIR + QString("/ukui-screensaver%1.pid").arg(env); + const QString PID_FILE = PID_DIR + "/ukui-screensaver.pid"; qDebug() << PID_DIR; QDir dir(PID_DIR); @@ -174,8 +173,7 @@ int main(int argc, char *argv[]) if(parser.isSet(lockOption)) { - // window->lock(); - window->onScreensaver(); + window->onScreensaver(); } if(parser.isSet(sessionIdleOption)) -- 2.30.0