Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,6 @@ write_basic_package_version_file(
COMPATIBILITY SameMajorVersion
)

# Configure Auth config file
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/data/AuthConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/data/AuthConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/DDM
PATH_VARS CMAKE_INSTALL_PREFIX
)

# Configure Common config file
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/data/CommonConfig.cmake.in"
Expand All @@ -269,7 +261,6 @@ install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/data/DDMConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/data/DDMConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/data/AuthConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/data/CommonConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/DDM
)
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SPDX-FileCopyrightText = "None"
SPDX-License-Identifier = "GPL-2.0-or-later"

[[annotations]]
path = ["releng/prepare-relnotes", "src/daemon/Auth.cpp", "src/daemon/Auth.h", "src/common/ConfigReader.cpp", "src/common/ConfigReader.h", "src/common/Configuration.cpp", "src/common/Configuration.h", "src/common/MessageHandler.h", "src/common/Messages.h", "src/common/SafeDataStream.cpp", "src/common/SafeDataStream.h", "src/common/Session.cpp", "src/common/Session.h", "src/common/SignalHandler.cpp", "src/common/SignalHandler.h", "src/common/SocketWriter.cpp", "src/common/SocketWriter.h", "src/common/ThemeConfig.cpp", "src/common/ThemeConfig.h", "src/common/ThemeMetadata.cpp", "src/common/ThemeMetadata.h", "src/common/VirtualTerminal.cpp", "src/common/VirtualTerminal.h", "src/common/XAuth.cpp", "src/common/XAuth.h", "src/daemon/DaemonApp.cpp", "src/daemon/DaemonApp.h", "src/daemon/Display.cpp", "src/daemon/Display.h", "src/daemon/DisplayManager.cpp", "src/daemon/DisplayManager.h", "src/daemon/DisplayServer.cpp", "src/daemon/DisplayServer.h", "src/daemon/Greeter.cpp", "src/daemon/Greeter.h", "src/daemon/PowerManager.cpp", "src/daemon/PowerManager.h", "src/daemon/Seat.cpp", "src/daemon/Seat.h", "src/daemon/SeatManager.cpp", "src/daemon/SeatManager.h", "src/daemon/SocketServer.cpp", "src/daemon/SocketServer.h", "src/daemon/TreelandConnector.cpp", "src/daemon/TreelandConnector.h", "src/daemon/Utils.h", "src/daemon/WaylandDisplayServer.cpp", "src/daemon/WaylandDisplayServer.h", "src/daemon/XorgDisplayServer.cpp", "src/daemon/XorgDisplayServer.h", "src/daemon/XorgUserDisplayServer.cpp", "src/daemon/XorgUserDisplayServer.h", "src/greeter/GreeterApp.h", "src/greeter/GreeterProxy.cpp", "src/greeter/GreeterProxy.h", "src/greeter/SessionModel.cpp", "src/greeter/SessionModel.h", "src/greeter/UserModel.cpp", "src/greeter/UserModel.h", "src/daemon/Pam.cpp", "src/daemon/Pam.h", "src/daemon/UserSession.cpp", "src/daemon/UserSession.h", "src/common/LogindDBusTypes.cpp", "src/common/LogindDBusTypes.h", "src/greeter/GreeterApp.cpp"]
path = ["releng/prepare-relnotes", "src/daemon/Auth.cpp", "src/daemon/Auth.h", "src/common/ConfigReader.cpp", "src/common/ConfigReader.h", "src/common/Configuration.cpp", "src/common/Configuration.h", "src/common/MessageHandler.h", "src/common/Messages.h", "src/common/SafeDataStream.cpp", "src/common/SafeDataStream.h", "src/common/Session.cpp", "src/common/Session.h", "src/common/SignalHandler.cpp", "src/common/SignalHandler.h", "src/common/SocketWriter.cpp", "src/common/SocketWriter.h", "src/common/ThemeConfig.cpp", "src/common/ThemeConfig.h", "src/common/ThemeMetadata.cpp", "src/common/ThemeMetadata.h", "src/common/VirtualTerminal.cpp", "src/common/VirtualTerminal.h", "src/common/XAuth.cpp", "src/common/XAuth.h", "src/daemon/DaemonApp.cpp", "src/daemon/DaemonApp.h", "src/daemon/Display.cpp", "src/daemon/Display.h", "src/daemon/DisplayManager.cpp", "src/daemon/DisplayManager.h", "src/daemon/PowerManager.cpp", "src/daemon/PowerManager.h", "src/daemon/Seat.cpp", "src/daemon/Seat.h", "src/daemon/SeatManager.cpp", "src/daemon/SeatManager.h", "src/daemon/SocketServer.cpp", "src/daemon/SocketServer.h", "src/daemon/TreelandConnector.cpp", "src/daemon/TreelandConnector.h", "src/daemon/Utils.h", "src/daemon/XorgDisplayServer.cpp", "src/daemon/XorgDisplayServer.h", "src/greeter/GreeterApp.h", "src/greeter/GreeterProxy.cpp", "src/greeter/GreeterProxy.h", "src/greeter/SessionModel.cpp", "src/greeter/SessionModel.h", "src/greeter/UserModel.cpp", "src/greeter/UserModel.h", "src/daemon/Pam.cpp", "src/daemon/Pam.h", "src/daemon/UserSession.cpp", "src/daemon/UserSession.h", "src/common/LogindDBusTypes.cpp", "src/common/LogindDBusTypes.h", "src/greeter/GreeterApp.cpp"]
precedence = "aggregate"
SPDX-FileCopyrightText = "None"
SPDX-License-Identifier = "GPL-2.0-or-later"
34 changes: 0 additions & 34 deletions data/AuthConfig.cmake.in

This file was deleted.

10 changes: 2 additions & 8 deletions data/DDMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set(DDM_VERSION_PATCH @DDM_VERSION_PATCH@)
set(DDM_VERSION @DDM_VERSION_STRING@)

# 导入 Auth 和 Common 模块的配置文件
include("${CMAKE_CURRENT_LIST_DIR}/AuthConfig.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/CommonConfig.cmake")

# 导出 DDM 相关的信息
Expand All @@ -18,12 +17,7 @@ set(DDM_LIBRARIES Auth Common)
# 如果定义了 COMPONENTS 选项,则导出相应的信息
if(DEFINED COMPONENTS)
foreach(comp ${COMPONENTS})
if(comp STREQUAL "Auth")
set(DDM_FOUND TRUE)
set(DDM_AUTH_FOUND TRUE)
set(DDM_INCLUDE_DIRS ${DDM_INCLUDE_DIRS} ${Auth_INCLUDE_DIRS})
set(DDM_LIBRARIES ${DDM_LIBRARIES} ${Auth_LIBRARIES})
elseif(comp STREQUAL "Common")
if(comp STREQUAL "Common")
set(DDM_FOUND TRUE)
set(DDM_COMMON_FOUND TRUE)
set(DDM_INCLUDE_DIRS ${DDM_INCLUDE_DIRS} ${Common_INCLUDE_DIRS})
Expand All @@ -35,7 +29,7 @@ if(DEFINED COMPONENTS)
endif()

# 如果没有定义 COMPONENTS 选项,则默认导出所有信息
if(NOT DEFINED COMPONENTS OR "${COMPONENTS}" STREQUAL "Auth;Common")
if(NOT DEFINED COMPONENTS OR "${COMPONENTS}" STREQUAL "Common")
set(DDM_FOUND TRUE)
set(DDM_INCLUDE_DIRS ${DDM_INCLUDE_DIRS} PARENT_SCOPE)
set(DDM_LIBRARIES ${DDM_LIBRARIES} PARENT_SCOPE)
Expand Down
114 changes: 52 additions & 62 deletions src/daemon/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,88 +36,78 @@ namespace DDM {
, id(++lastId)
, m_pam(new Pam(this))
, m_session(new UserSession(this)) {
connect(this, &Auth::finished, this, [this] {
active = false;
});
connect(m_session,
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this,
&Auth::userProcessFinished);
}

Auth::~Auth() {
stop();
}

#define LOGIN_FAILED \
const QString displayId = environment.value(QStringLiteral("DISPLAY")); \
const QString vt = environment.value(QStringLiteral("XDG_VTNR")); \
utmpLogin(vt, displayId, user, 0, false); \
Q_EMIT finished(AUTH_ERROR); \
return;

void Auth::start(const QByteArray &secret) {
Q_ASSERT(getuid() == 0);

active = true;
bool Auth::authenticate(const QByteArray &secret) {
m_pam->user = user;
if (!m_pam->start()) {
Q_EMIT authentication(user, false, identifyOnly);
LOGIN_FAILED
utmpLogin(std::to_string(tty).c_str(), display, user, 0, false);
return false;
}

if (!skipAuth && !m_pam->authenticate(secret)) {
Q_EMIT authentication(user, false, identifyOnly);
LOGIN_FAILED
utmpLogin(std::to_string(tty).c_str(), display, user, 0, false);
return false;
}
active = true;
return true;
}

Q_EMIT authentication(user, true, identifyOnly);

if (!sessionPath.isEmpty()) {
auto sessionEnv = m_pam->openSession(environment);
if (!sessionEnv.has_value()) {
Q_EMIT sessionStarted(false, 0);
Q_EMIT finished(SESSION_ERROR);
return;
}

QProcessEnvironment env = *sessionEnv;
xdgSessionId = env.value(QStringLiteral("XDG_SESSION_ID")).toInt();
Q_EMIT sessionStarted(true, xdgSessionId);

struct passwd *pw;
pw = getpwnam(qPrintable(user));
if (pw) {
env.insert(QStringLiteral("HOME"), QString::fromLocal8Bit(pw->pw_dir));
env.insert(QStringLiteral("PWD"), QString::fromLocal8Bit(pw->pw_dir));
env.insert(QStringLiteral("SHELL"), QString::fromLocal8Bit(pw->pw_shell));
env.insert(QStringLiteral("USER"), QString::fromLocal8Bit(pw->pw_name));
env.insert(QStringLiteral("LOGNAME"), QString::fromLocal8Bit(pw->pw_name));
}
m_session->setProcessEnvironment(env);
m_session->start();

// write successful login to utmp/wtmp
const QString displayId = env.value(QStringLiteral("DISPLAY"));
const QString vt = env.value(QStringLiteral("XDG_VTNR"));
// cache pid for session end
utmpLogin(vt, displayId, user, m_session->processId(), true);
int Auth::openSession(const QProcessEnvironment &env) {
Q_ASSERT(active);
auto ret = m_pam->openSession(env);
if (!ret.has_value())
return -1;
m_env = *ret;
xdgSessionId = m_env.value(QStringLiteral("XDG_SESSION_ID")).toInt();
return xdgSessionId;
}

void Auth::startUserProcess(const QString &command, Display::DisplayServerType type, const QByteArray &cookie) {
Q_ASSERT(!m_env.isEmpty());
QProcessEnvironment env = m_env;
struct passwd *pw = getpwnam(qPrintable(user));
if (pw) {
env.insert(QStringLiteral("HOME"), QString::fromLocal8Bit(pw->pw_dir));
env.insert(QStringLiteral("PWD"), QString::fromLocal8Bit(pw->pw_dir));
env.insert(QStringLiteral("SHELL"), QString::fromLocal8Bit(pw->pw_shell));
env.insert(QStringLiteral("USER"), QString::fromLocal8Bit(pw->pw_name));
env.insert(QStringLiteral("LOGNAME"), QString::fromLocal8Bit(pw->pw_name));
}
return;
m_session->setProcessEnvironment(env);
m_session->start(command, type, cookie);

// write successful login to utmp/wtmp
const QString displayId = env.value(QStringLiteral("DISPLAY"));
const QString vt = env.value(QStringLiteral("XDG_VTNR"));
// cache pid for session end
utmpLogin(vt, displayId, user, m_session->processId(), true);
}

void Auth::stop() {
Q_ASSERT(getuid() == 0);

if (!active)
return;
active = false;
qint64 pid = m_session->processId();
m_session->stop();
if (!identifyOnly && m_pam->sessionOpened) {
if (m_session->state() != QProcess::NotRunning)
m_session->stop();
if (m_pam->sessionOpened)
m_pam->closeSession();
}

// write logout to utmp/wtmp
if (pid <= 0)
return;
QProcessEnvironment env = m_session->processEnvironment();
QString vt = env.value(QStringLiteral("XDG_VTNR"));
QString displayId = env.value(QStringLiteral("DISPLAY"));
utmpLogout(vt, displayId, pid);
if (pid > 0) {
QProcessEnvironment env = m_session->processEnvironment();
QString vt = env.value(QStringLiteral("XDG_VTNR"));
QString displayId = env.value(QStringLiteral("DISPLAY"));
utmpLogout(vt, displayId, pid);
}
}

void Auth::utmpLogin(const QString &vt, const QString &displayName, const QString &user, qint64 pid, bool authSuccessful) {
Expand Down
59 changes: 16 additions & 43 deletions src/daemon/Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#ifndef DDM_AUTH_H
#define DDM_AUTH_H

#include "Session.h"
#include "Display.h"

#include <QtCore/QObject>

Check warning on line 26 in src/daemon/Auth.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtCore/QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtCore/QProcessEnvironment>

Check warning on line 27 in src/daemon/Auth.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtCore/QProcessEnvironment> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace DDM {
class Pam;
Expand All @@ -36,39 +36,29 @@
Auth(QObject *parent);
~Auth();

enum ExitStatus {
SUCCESS = 0,
AUTH_ERROR,
SESSION_ERROR,
OTHER_ERROR,
DISPLAYSERVER_ERROR,
TTY_ERROR,
};
Q_ENUM(ExitStatus)

bool active{ false };
QString displayServerCmd{};
QString sessionPath{};
Session::Type sessionType{ Session::UnknownSession };
QString sessionFileName{};
QString user{};
QByteArray cookie{};
bool autologin{ false };
bool greeter{ false };
bool singleMode{ false };
bool identifyOnly{ false };
bool skipAuth{ false };
QProcessEnvironment environment{ };

int id{ 0 };
static int lastId;
QString sessionId{};
QString display{};
int tty{ 0 };
int xdgSessionId{ 0 };
public Q_SLOTS:
/**
* Sets up the environment and starts the authentication
*/
void start(const QByteArray &secret);
bool authenticate(const QByteArray &secret);

int openSession(const QProcessEnvironment &env);

void startUserProcess(const QString &command,
Display::DisplayServerType type,
const QByteArray &cookie = QByteArray());

/**
* Indicates that we do not need the process anymore.
Expand All @@ -77,33 +67,16 @@

Q_SIGNALS:
/**
* Emitted when authentication phase finishes
*
* @note If you want to set some environment variables for the session right before the
* session is started, connect to this signal using a blocking connection and insert anything
* you need in the slot.
* @param user username
* @param success true if succeeded
*/
void authentication(QString user, bool success, bool identifyOnly);

/**
* Emitted when session starting phase finishes
*
* @param success true if succeeded
*/
void sessionStarted(bool success, int xdgSessionId);

/**
* Emitted when the session ends.
*
* @param success true if every underlying task went fine
*/
void finished(Auth::ExitStatus status);
* Emitted when the session ends.
*
* @param success true if every underlying task went fine
*/
void userProcessFinished(int status);

private:
Pam *m_pam { nullptr };
UserSession *m_session{ nullptr };
QProcessEnvironment m_env{};

/**
* Write utmp/wtmp/btmp records when a user logs in
Expand Down
9 changes: 1 addition & 8 deletions src/daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ set(DAEMON_SOURCES
DaemonApp.cpp
Display.cpp
DisplayManager.cpp
DisplayServer.cpp
Greeter.cpp
Pam.cpp
PowerManager.cpp
Seat.cpp
Expand All @@ -39,12 +37,7 @@ set(DAEMON_SOURCES
TreelandConnector.cpp
UserSession.cpp
XorgDisplayServer.cpp
XorgUserDisplayServer.cpp
XorgUserDisplayServer.h
WaylandDisplayServer.cpp
WaylandDisplayServer.h
SingleWaylandDisplayServer.h
SingleWaylandDisplayServer.cpp
TreelandDisplayServer.cpp
${TREELAND_DDM_SOURCE}
)

Expand Down
Loading