Repository navigation
feat: delegate Treeland sessions to authentication service #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| #include <QDataStream> | ||
| #include <QDebug> | ||
| #include <QProcess> | ||
| #include <QTimer> | ||
|
|
||
| namespace DDM { | ||
|
|
||
|
|
@@ -76,6 +77,8 @@ namespace DDM { | |
| QProcess *helper { nullptr }; | ||
| // Buffer for streaming replies from the helper. | ||
| QByteArray recvBuffer; | ||
| DASessionClient *da { nullptr }; | ||
| bool busy { false }; | ||
| }; | ||
|
|
||
| Auth::Auth(QObject *parent, QString user) | ||
|
|
@@ -84,6 +87,12 @@ namespace DDM { | |
| , d(new AuthPrivate(this)) {} | ||
|
|
||
| Auth::~Auth() { | ||
| if (type == Display::Treeland) { | ||
| // DASessionClient cancels unfinished attempts and detaches running sessions. | ||
| delete d->da; | ||
| d->da = nullptr; | ||
| return; | ||
| } | ||
| if (sessionOpened) { | ||
| if (sessionPid > 0) | ||
| kill(sessionPid, SIGTERM); | ||
|
|
@@ -220,6 +229,10 @@ namespace DDM { | |
| } | ||
|
|
||
| bool Auth::authenticate(const QByteArray &secret) { | ||
| if (type == Display::Treeland) { | ||
| qWarning() << "[Auth] Treeland requires asynchronous DA authentication"; | ||
| return false; | ||
| } | ||
| Q_ASSERT(!user.isEmpty()); | ||
|
|
||
| qInfo() << "[Auth] Starting..."; | ||
|
|
@@ -260,6 +273,10 @@ namespace DDM { | |
| QString Auth::openSession(const QString &command, | ||
| QProcessEnvironment env, | ||
| const QByteArray &cookie) { | ||
| if (type == Display::Treeland) { | ||
| qWarning() << "[Auth] Treeland requires asynchronous DA session start"; | ||
| return {}; | ||
| } | ||
| Q_ASSERT(authenticated); | ||
|
|
||
| // Everything the helper needs to run the session comes from the | ||
|
|
@@ -269,10 +286,6 @@ namespace DDM { | |
| QString sessionCommand; | ||
| QString sessionLogFile; | ||
| switch (type) { | ||
| case Display::Treeland: | ||
| sessionCommand = mainConfig()->singleSessionCommand(); | ||
| sessionLogFile = mainConfig()->waylandSessionLogFile(); | ||
| break; | ||
| case Display::X11: | ||
| sessionCommand = mainConfig()->x11SessionCommand(); | ||
| sessionLogFile = mainConfig()->x11SessionLogFile(); | ||
|
|
@@ -356,6 +369,8 @@ namespace DDM { | |
| } | ||
|
|
||
| bool Auth::closeSession() { | ||
| if (type == Display::Treeland) | ||
| return d->da && d->da->stop(); | ||
| if (!sessionOpened) { | ||
| qWarning() << "[Auth] closeSession: Session was not opened."; | ||
| return true; | ||
|
|
@@ -376,6 +391,132 @@ namespace DDM { | |
| qInfo() << "[Auth] Session closed."; | ||
| return true; | ||
| } | ||
| DASessionClient *Auth::ensureDAClient() | ||
| { | ||
| if (d->da) | ||
| return d->da; | ||
| d->da = new DASessionClient(this); | ||
| connect(d->da, &DASessionClient::authenticationFinished, this, [this](bool success) { | ||
| sessionId = d->da->sessionId(); | ||
| authenticated = success; | ||
| Q_EMIT authenticationFinished(success); | ||
| }); | ||
| connect(d->da, &DASessionClient::sessionStarted, this, [this] { | ||
| const auto info = d->da->info(); | ||
| xdgSessionId = info.logindSessionId; | ||
| sessionPid = info.pid; | ||
| sessionOpened = true; | ||
| Q_EMIT sessionStarted(); | ||
| }); | ||
| connect(d->da, &DASessionClient::sessionStartFailed, this, [this] { | ||
| authenticated = false; | ||
| Q_EMIT sessionStartFailed(); | ||
| }); | ||
| connect(d->da, &DASessionClient::sessionFinished, this, [this] { | ||
| sessionOpened = false; | ||
| authenticated = false; | ||
| Q_EMIT sessionFinished(); | ||
| }); | ||
| connect(d->da, &DASessionClient::informationMessage, this, &Auth::informationMessage); | ||
| return d->da; | ||
| } | ||
|
|
||
| bool Auth::isBusy() const | ||
| { | ||
| return d->busy || (d->da && d->da->isBusy()); | ||
| } | ||
|
|
||
| void Auth::authenticateAsync(const QByteArray &secret) | ||
| { | ||
| if (isBusy() || authenticated || sessionOpened || d->da) | ||
| return; | ||
| if (type == Display::Treeland) { | ||
| ensureDAClient()->authenticate(user, pamService == QLatin1String("ddm-autologin") | ||
| ? QStringLiteral("autologin") : QStringLiteral("login"), | ||
| seat, tty > 0 ? static_cast<quint32>(tty) : 0, secret); | ||
| return; | ||
|
Comment on lines
+434
to
+437
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Low · Treeland bypasses documented UserSession path When a login uses Treeland, for Treeland, Update kb-965847 to describe DA-managed Treeland authentication and session launch while retaining the Also at Prompt for AI agentsIn `src/daemon/Auth.cpp` at lines 434-437:
**Treeland bypasses documented UserSession path**
When a login uses Treeland, for Treeland, `Auth::authenticateAsync` authenticates through `DASessionClient`, and `openSessionAsync` launches through DA instead of `UserSession`, so the documented login path is false for every Treeland login.
Update kb-965847 to describe DA-managed Treeland authentication and session launch while retaining the `UserSession` path for other display types.
Also at `src/daemon/Auth.cpp:490`.From - When user login, Auth will startup UserSession, which will call PAM to open session, as well as starting up desktop environment. |
||
| } | ||
| d->busy = true; | ||
| QTimer::singleShot(0, this, [this, secret] { | ||
| const bool success = authenticate(secret); | ||
| d->busy = false; | ||
| Q_EMIT authenticationFinished(success); | ||
| }); | ||
| } | ||
|
|
||
| void Auth::openSessionAsync(const QString &command, QProcessEnvironment env, const QByteArray &cookie) | ||
| { | ||
| if (isBusy() || !authenticated || sessionOpened) | ||
| return; | ||
| if (type != Display::Treeland) { | ||
| d->busy = true; | ||
| QTimer::singleShot(0, this, [this, command, env, cookie] { | ||
| const bool success = !openSession(command, env, cookie).isEmpty(); | ||
| d->busy = false; | ||
| if (success) | ||
| Q_EMIT sessionStarted(); | ||
| else | ||
| Q_EMIT sessionStartFailed(); | ||
| }); | ||
| return; | ||
| } | ||
| if (!d->da) | ||
| return; | ||
| if (!daemonApp->seatdControl()->requestSwitchVt(tty)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Failed launch hides greeter When DA rejects the start or the launch fails after the user VT has been selected, Switch back to the greeter VT when a Treeland launch fails and the greeter connection is still active. Prompt for AI agentsIn `src/daemon/Auth.cpp` at line 465:
**Failed launch hides greeter**
When DA rejects the start or the launch fails after the user VT has been selected, `requestSwitchVt(tty)` moves the display to the user VT before DA accepts the session start. If the start then fails, `failLogin` sends `ShowGreeter` without switching back to the greeter VT, so the greeter remains off-screen.
Switch back to the greeter VT when a Treeland launch fails and the greeter connection is still active. |
||
| d->da->cancel(); | ||
| authenticated = false; | ||
| Q_EMIT sessionStartFailed(); | ||
| return; | ||
| } | ||
| QStringList argv; | ||
| const QString wrapper = mainConfig()->singleSessionCommand(); | ||
| if (wrapper.isEmpty()) { | ||
| argv = QProcess::splitCommand(command); | ||
| } else { | ||
| argv = QProcess::splitCommand(wrapper); | ||
| argv.append(command); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Wrapped desktops fail to launch When Append Prompt for AI agentsIn `src/daemon/Auth.cpp` at line 478:
**Wrapped desktops fail to launch**
When `singleSessionCommand` is configured and the desktop command contains arguments, `openSessionAsync` appends the entire desktop command as one argument to the wrapper. When the desktop command contains arguments and the wrapper executes its arguments as an argv vector, it receives a single executable name containing spaces and the DA session fails to start.
Append `QProcess::splitCommand(command)` to the wrapper argv, or explicitly implement and test the wrapper’s intended command-string interface. |
||
| DAEnvironment environment; | ||
| for (const auto &key : env.keys()) { | ||
| if (!DASessionClient::reservedEnvironmentKey(key)) | ||
| environment.insert(key, env.value(key)); | ||
| } | ||
| QStringList namespaces; | ||
| const auto configured = mainConfig()->namespaces(); | ||
| namespaces.reserve(configured.size()); | ||
| for (const QVariant &path : configured) | ||
| namespaces.append(path.toString()); | ||
| d->da->start(argv, environment, namespaces, mainConfig()->waylandSessionLogFile()); | ||
| } | ||
|
|
||
| QList<ManagedSessionInfo> Auth::managedSessions(const QString &seat) | ||
| { | ||
| return DASessionClient::managedSessions(seat); | ||
| } | ||
|
|
||
| bool Auth::adoptManagedSession(const ManagedSessionInfo &info) | ||
| { | ||
| if (isBusy() || authenticated || sessionOpened || d->da) | ||
| return false; | ||
| if (!ensureDAClient()->adopt(info)) | ||
| return false; | ||
| type = Display::Treeland; | ||
| seat = info.seat; | ||
| user = info.user; | ||
| tty = static_cast<int>(info.vt); | ||
| sessionId = d->da->sessionId(); | ||
| xdgSessionId = info.logindSessionId; | ||
| sessionPid = info.pid; | ||
| authenticated = true; | ||
| sessionOpened = true; | ||
| return true; | ||
| } | ||
|
|
||
| QString Auth::managedSessionPath() const | ||
| { | ||
| return d->da ? d->da->objectPath() : QString(); | ||
| } | ||
|
|
||
| } // namespace DDM | ||
|
|
||
| #include "Auth.moc" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Grouped VT loses its session identity
When a Treeland login succeeds through DA,
prepareUserSession()creates the grouped VT with the generatedauth->sessionId, then the authentication callback replaces that ID with the DA object-path ID.registerSessionand cleanup use the replacement, so seatd/VT ownership lookups cannot match the registered session and cleanup can miss the grouped VT.Keep the session ID used to create the grouped VT consistent with the ID used for DA registration and cleanup.
Also at
src/daemon/Display.cpp:346.Prompt for AI agents