diff --git a/CMakeLists.txt b/CMakeLists.txt index 22e5ac2f31a36f73efeeba70b503cd27fbf3b48c..a77f4b3cfa8f8c98fc46cefe07d966ecc49fa6b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,11 @@ find_package(Qt5 COMPONENTS Core DBus LinguistTools) pkg_search_module(KLOG_QT5 REQUIRED klog-qt5) pkg_search_module(SYSTEMD REQUIRED systemd) pkg_search_module(KIRAN_CC_DAEMON REQUIRED kiran-cc-daemon) -pkg_search_module(PAM REQUIRED pam) +pkg_search_module(PAM QUIET pam) +if(NOT DEFINED ${PAM_FOUND}) + set(PAM_INCLUDE_DIRS /usr/include/security) + set(PAM_LIBRARIES pam) +endif() pkg_search_module(LIBSYSTEMD REQUIRED libsystemd) configure_file(config.h.in ${PROJECT_BINARY_DIR}/config.h) diff --git a/src/daemon/auth-manager.cpp b/src/daemon/auth-manager.cpp index 3d7aaf0f4bfcf5d111f8b4a1c708a835cbb95c80..a03089716ff08044b28d6f5419c6788c8155e641 100644 --- a/src/daemon/auth-manager.cpp +++ b/src/daemon/auth-manager.cpp @@ -276,7 +276,12 @@ int32_t AuthManager::generateSessionID() // 最多生成10次,超过次数则返回失败 for (int i = 0; i <= 10; ++i) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) auto sessionID = this->m_randomGenerator.bounded(1, MAX_SESSION_ID); +#else + qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); + auto sessionID = qrand() % MAX_SESSION_ID + 1; +#endif auto session = this->m_sessions.value(sessionID, nullptr); // KLOG_DEBUG() << "session: " << session << ", sessionID: " << sessionID; RETURN_VAL_IF_TRUE(session == nullptr, sessionID); diff --git a/src/daemon/auth-manager.h b/src/daemon/auth-manager.h index e707e0bda32f3335e8f8427f3e2944604989a560..b6f2446f4debf8fc87c9899068d9f7cfc7d3a451 100644 --- a/src/daemon/auth-manager.h +++ b/src/daemon/auth-manager.h @@ -16,7 +16,9 @@ #include #include #include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) #include +#endif #include "kas-authentication-i.h" class AuthManagerAdaptor; @@ -118,7 +120,9 @@ private: // <会话ID,会话> QMap m_sessions; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) QRandomGenerator m_randomGenerator; +#endif QDBusServiceWatcher *m_serviceWatcher; }; diff --git a/src/daemon/device/device-adaptor-factory.cpp b/src/daemon/device/device-adaptor-factory.cpp index 531e0d926c3056cd3e6ba92c4d1aa75e78796e52..590214c9d4fcf4b784b7bfbbc33e7b7bc60856ad 100644 --- a/src/daemon/device/device-adaptor-factory.cpp +++ b/src/daemon/device/device-adaptor-factory.cpp @@ -206,8 +206,8 @@ void DeviceAdaptorFactory::onAuthDeviceManagerLost(const QString &service) // 设备管理服务消失,认证设备无效,应清理所有无效的设备及其请求 for (auto iter = m_devices.begin(); iter != m_devices.end();) { - KLOG_DEBUG() << "auth device manager lost,remove device:" << iter->get()->getDeviceID(); - iter->get()->removeAllRequest(); + KLOG_DEBUG() << "auth device manager lost,remove device:" << iter.value().data()->getDeviceID(); + iter.value().data()->removeAllRequest(); iter = m_devices.erase(iter); } } @@ -217,10 +217,10 @@ void DeviceAdaptorFactory::onDeviceDeleted(int deviceType, const QString &device // 认证设备拔出,认证设备变成无效,清理该设备下请求,从缓存中删除该设备 for (auto iter = m_devices.begin(); iter != m_devices.end(); iter++) { - if (iter->get()->getDeviceID() == deviceID) + if (iter.value().data()->getDeviceID() == deviceID) { - KLOG_DEBUG() << "auth device deleted,remove device:" << iter->get()->getDeviceID(); - iter->get()->removeAllRequest(); + KLOG_DEBUG() << "auth device deleted,remove device:" << iter.value().data()->getDeviceID(); + iter.value().data()->removeAllRequest(); m_devices.erase(iter); break; } diff --git a/src/daemon/device/device-adaptor.cpp b/src/daemon/device/device-adaptor.cpp index 369554de8301b3ec6b3a73b26475b70af2471b1b..cef646f7095d3b074eeff584697aedc53f0350aa 100644 --- a/src/daemon/device/device-adaptor.cpp +++ b/src/daemon/device/device-adaptor.cpp @@ -41,7 +41,7 @@ DeviceAdaptor::DeviceAdaptor(QSharedPointer dbusDeviceProxy) connect(&m_deviceOccupyTimer,&QTimer::timeout,this,&DeviceAdaptor::onDeviceOccupyTimeout); auto defaultSeat = Login1SeatProxy::getDefault(); - connect(defaultSeat.get(), SIGNAL(activeSessionChanged(const Login1SessionItem &)), this, SLOT(onActiveSessionChanged(const Login1SessionItem &))); + connect(defaultSeat.data(), SIGNAL(activeSessionChanged(const Login1SessionItem &)), this, SLOT(onActiveSessionChanged(const Login1SessionItem &))); this->updateDBusDeviceProxy(dbusDeviceProxy); } @@ -76,8 +76,8 @@ void DeviceAdaptor::removeAllRequest() // 清空/结束所有认证,不再参与调度 for (auto iter = this->m_requests.begin(); iter != this->m_requests.end();) { - iter->get()->source->cancel(); - iter->get()->source->end(); + iter.value().data()->source->cancel(); + iter.value().data()->source->end(); iter = this->m_requests.erase(iter); } } @@ -107,8 +107,8 @@ void DeviceAdaptor::updateDBusDeviceProxy(QSharedPointer dbusDe this->interruptRequest(); - connect(this->m_dbusDeviceProxy.get(), &AuthDeviceProxy::EnrollStatus, this, &DeviceAdaptor::onEnrollStatus); - connect(this->m_dbusDeviceProxy.get(), &AuthDeviceProxy::IdentifyStatus, this, &DeviceAdaptor::onIdentifyStatus); + connect(this->m_dbusDeviceProxy.data(), &AuthDeviceProxy::EnrollStatus, this, &DeviceAdaptor::onEnrollStatus); + connect(this->m_dbusDeviceProxy.data(), &AuthDeviceProxy::IdentifyStatus, this, &DeviceAdaptor::onIdentifyStatus); DEVICE_DEBUG() << "update auth device finished"; this->schedule(); @@ -134,7 +134,7 @@ void DeviceAdaptor::wakeRequest(QSharedPointer request) { RETURN_IF_FALSE(request); // 请求未变化,直接返回 - RETURN_IF_TRUE(this->m_currentRequest && this->m_currentRequest.get() == request.get()); + RETURN_IF_TRUE(this->m_currentRequest && this->m_currentRequest.data() == request.data()); // 中断当前的请求 this->interruptRequest(); diff --git a/src/pam/authentication-graphical.cpp b/src/pam/authentication-graphical.cpp index 2f104ac4a38662ca761c268b379e325c9a493bba..4a31b77b89a45aabe9d85e48ba7953a4b23c7c9d 100644 --- a/src/pam/authentication-graphical.cpp +++ b/src/pam/authentication-graphical.cpp @@ -52,12 +52,22 @@ bool AuthenticationGraphical::requestLoginUserSwitchable() // 请求失败的情况下使用默认值 if (retval != PAM_SUCCESS) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) auto errorMsg = jsonReqDoc[KAP_PJK_KEY_HEAD][KAP_PJK_KEY_ERROR].toString(); +#else + QJsonValue val = jsonReqDoc.object()[KAP_PJK_KEY_HEAD]; + auto errorMsg = val.toObject()[KAP_PJK_KEY_ERROR].toString(); +#endif this->m_pamHandle->syslog(LOG_WARNING, QString("Request login user switchable failed: %1").arg(errorMsg)); return false; } +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) return jsonRspDoc[KAP_PJK_KEY_BODY][KAP_PJK_KEY_LOGIN_USER_SWITCHABLE].toBool(); +#else + QJsonValue val = jsonRspDoc.object()[KAP_PJK_KEY_BODY]; + return val.toObject()[KAP_PJK_KEY_LOGIN_USER_SWITCHABLE].toBool(); +#endif } void AuthenticationGraphical::notifySupportAuthType() @@ -90,11 +100,21 @@ int32_t AuthenticationGraphical::requestAuthType() // 请求失败的情况下使用默认认证类型 if (retval != PAM_SUCCESS) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) auto errorMsg = jsonReqDoc[KAP_PJK_KEY_HEAD][KAP_PJK_KEY_ERROR].toString(); +#else + QJsonValue val = jsonReqDoc.object()[KAP_PJK_KEY_HEAD]; + auto errorMsg = val.toObject()[KAP_PJK_KEY_ERROR].toString(); +#endif this->m_pamHandle->syslog(LOG_WARNING, QString("Request auth type failed: %1").arg(errorMsg)); return KADAuthType::KAD_AUTH_TYPE_NONE; } +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) return jsonRspDoc[KAP_PJK_KEY_BODY][KAP_PJK_KEY_AUTH_TYPE].toInt(); +#else + QJsonValue val = jsonRspDoc.object()[KAP_PJK_KEY_BODY]; + return val.toObject()[KAP_PJK_KEY_AUTH_TYPE].toInt(); +#endif } void AuthenticationGraphical::notifyAuthType(int authType)