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
14 changes: 12 additions & 2 deletions src/auth/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace DDM {
static qint64 lastId;
QString sessionId;
int tty { 0 };
int xdgSessionId { 0 };
};

qint64 Auth::Private::lastId = 1;
Expand Down Expand Up @@ -203,9 +204,10 @@ namespace DDM {
}
case SESSION_STATUS: {
bool status;
str >> status;
int sessionId;
str >> status >> sessionId;
if(!auth->identifyOnly()) {
Q_EMIT auth->sessionStarted(status);
Q_EMIT auth->sessionStarted(status, sessionId);
}
str.reset();
str << SESSION_STATUS;
Expand Down Expand Up @@ -427,6 +429,14 @@ namespace DDM {
}
}

int Auth::xdgSessionId() const {
return d->xdgSessionId;
}

void Auth::setXdgSessionId(int xdgSessionId) {
d->xdgSessionId = xdgSessionId;
}

void Auth::setVerbose(bool on) {
if (on != verbose()) {
if (on)
Expand Down
5 changes: 4 additions & 1 deletion src/auth/Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace DDM {
Session::Type sessionType() const;
QString sessionFileName() const;
int tty() const;
int xdgSessionId() const;

void setTTY(int tty);
/**
Expand Down Expand Up @@ -191,6 +192,8 @@ namespace DDM {

void setSessionFileName(const QString &fileName);

void setXdgSessionId(int xdgSessionId);

public Q_SLOTS:
/**
* Sets up the environment and starts the authentication
Expand Down Expand Up @@ -229,7 +232,7 @@ namespace DDM {
*
* @param success true if succeeded
*/
void sessionStarted(bool success);
void sessionStarted(bool success, int xdgSessionId);

/**
* Emitted when the display server is ready.
Expand Down
2 changes: 1 addition & 1 deletion src/common/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ namespace DDM {
Suspend,
Hibernate,
HybridSleep,
ActivateUser,
BackToNormal,
Unlock,
Logout,
};

enum class TreelandMessages {
Expand Down
36 changes: 16 additions & 20 deletions src/daemon/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ namespace DDM {
// connect login signal
connect(m_socketServer, &SocketServer::login, this, &Display::login);

// connect logout signal
connect(m_socketServer, &SocketServer::logout, this, &Display::logout);

// connect unlock signal
connect(m_socketServer, &SocketServer::unlock,this, &Display::unlock);

Expand All @@ -178,7 +181,7 @@ namespace DDM {
connect(m_greeter, &Greeter::displayServerFailed, this, &Display::displayServerFailed);
connect(m_greeter, &Greeter::greeterStarted, this, [this] {
if (m_currentAuth) {
switchToUser(m_currentAuth->user());
switchToUser(m_currentAuth->user(), m_currentAuth->xdgSessionId());
}
});
}
Expand Down Expand Up @@ -217,7 +220,7 @@ namespace DDM {
return m_seat;
}

void Display::switchToUser(const QString &user) {
void Display::switchToUser(const QString &user, int xdgSessionId) {
if (user == "dde") {
m_greeter->setUserActivated(false);
}
Expand All @@ -236,23 +239,11 @@ namespace DDM {
}

auto* server = reinterpret_cast<SingleWaylandDisplayServer*>(m_displayServer);
server->activateUser(user);
server->activateUser(user, xdgSessionId);

if (Logind::isAvailable()) {
OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
auto reply = manager.ListSessions();
reply.waitForFinished();

const auto info = reply.value();
for(const SessionInfo &s : reply.value()) {
if (s.userName == user) {
OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(), s.sessionPath.path(), QDBusConnection::systemBus());
if (session.state() == "online" && session.vTNr() == static_cast<uint>(auth->tty())) {
session.Activate();
break;
}
}
}
manager.ActivateSession(QString::number(auth->xdgSessionId()));
}
}

Expand Down Expand Up @@ -396,6 +387,11 @@ namespace DDM {
startAuth(user, password, session);
}

void Display::logout([[maybe_unused]] QLocalSocket *socket, int id) {
OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
manager.TerminateSession(QString::number(id));
}

void Display::unlock(QLocalSocket *socket,
const QString &user, const QString &password) {
m_socket = socket;
Expand Down Expand Up @@ -644,7 +640,6 @@ namespace DDM {
if (auth->isSingleMode()) {
auto* server = reinterpret_cast<SingleWaylandDisplayServer*>(m_displayServer);
server->onLoginSucceeded(user);
switchToUser(auth->user());
} else {
if (m_socket) {
emit loginSucceeded(m_socket, user);
Expand Down Expand Up @@ -744,7 +739,7 @@ namespace DDM {
if (m_displayServerType == DisplayServerType::SingleCompositerServerType) {
auto* server = reinterpret_cast<SingleWaylandDisplayServer*>(m_displayServer);
// TODO: switch to greeter
server->activateUser("dde");
server->activateUser("dde", 0);

// TODO: only current user logout will reset greeter state
m_greeter->setUserActivated(false);
Expand All @@ -769,11 +764,12 @@ namespace DDM {
}
}

void Display::slotSessionStarted(bool success) {
void Display::slotSessionStarted(bool success, int xdgSessionId) {
qDebug() << "Session started" << success;
Auth* auth = qobject_cast<Auth*>(sender());
auth->setXdgSessionId(xdgSessionId);
if (auth->isSingleMode()) {
switchToUser(auth->user());
switchToUser(auth->user(), xdgSessionId);
}

if (success && m_displayServerType != SingleCompositerServerType) {
Expand Down
6 changes: 4 additions & 2 deletions src/daemon/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace DDM {
QString reuseSessionId() const { return m_reuseSessionId; }

Seat *seat() const;
void switchToUser(const QString &user);
void switchToUser(const QString &user, int xdgSessionId);

QVector<Auth*> loginedSession() const {
return m_auths;
Expand All @@ -79,6 +79,8 @@ namespace DDM {
void login(QLocalSocket *socket,
const QString &user, const QString &password,
const Session &session);
void logout(QLocalSocket *socket,
int id);
void unlock(QLocalSocket *socket,
const QString &user, const QString &password);
bool attemptAutologin();
Expand Down Expand Up @@ -120,7 +122,7 @@ namespace DDM {
private slots:
void slotRequestChanged();
void slotAuthenticationFinished(const QString &user, bool success, bool identifyOnly);
void slotSessionStarted(bool success);
void slotSessionStarted(bool success, int xdgSessionId);
void slotHelperFinished(Auth::HelperExitStatus status);
void slotAuthInfo(const QString &message, Auth::Info info);
void slotAuthError(const QString &message, Auth::Error error);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/Greeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ namespace DDM {
m_auth->request()->setFinishAutomatically(true);
}

void Greeter::onSessionStarted(bool success) {
void Greeter::onSessionStarted(bool success,[[maybe_unused]] int xdgSessionId) {
// set flag
m_started = success;

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/Greeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace DDM {

private slots:
void onRequestChanged();
void onSessionStarted(bool success);
void onSessionStarted(bool success, int xdgSessionId);
void onDisplayServerReady(const QString &displayName);
void onHelperFinished(Auth::HelperExitStatus status);
void onReadyReadStandardOutput();
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/Seat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace DDM {

if (Display::defaultDisplayServerType() == Display::SingleCompositerServerType && !m_displays.isEmpty()) {
auto display = m_displays.first();
display->switchToUser("dde");
display->switchToUser("dde", 0);
return;
}

Expand Down
9 changes: 2 additions & 7 deletions src/daemon/SingleWaylandDisplayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ SingleWaylandDisplayServer::SingleWaylandDisplayServer(SocketServer *socketServe
connect(m_socketServer, &SocketServer::disconnected, this, [this](QLocalSocket *socket) {
m_greeterSockets.removeOne(socket);
});

// TODO: use PAM auth again
connect(m_socketServer, &SocketServer::requestActivateUser, this, [this]([[maybe_unused]] QLocalSocket *socket, const QString &user){
activateUser(user);
});
}

SingleWaylandDisplayServer::~SingleWaylandDisplayServer() {
Expand Down Expand Up @@ -99,13 +94,13 @@ void SingleWaylandDisplayServer::setupDisplay()
{
}

void SingleWaylandDisplayServer::activateUser(const QString &user) {
void SingleWaylandDisplayServer::activateUser(const QString &user, int xdgSessionId) {
for (auto greeter : m_greeterSockets) {
if (user == "dde") {
SocketWriter(greeter) << quint32(DaemonMessages::SwitchToGreeter);
}

SocketWriter(greeter) << quint32(DaemonMessages::UserActivateMessage) << user;
SocketWriter(greeter) << quint32(DaemonMessages::UserActivateMessage) << user << xdgSessionId;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/SingleWaylandDisplayServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Q_SLOTS:
void stop();
void finished();
void setupDisplay();
void activateUser(const QString &user);
void activateUser(const QString &user, int xdgSessionId);
QString getUserWaylandSocket(const QString &user) const;
void onLoginFailed(const QString &user);
void onLoginSucceeded(const QString &user);
Expand Down
22 changes: 10 additions & 12 deletions src/daemon/SocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ namespace DDM {
emit login(socket, user, password, session);
}
break;
case GreeterMessages::Logout: {
// log message
qDebug() << "Message received from greeter: Logout";
// read username
int id;
input >> id;
// emit signal
emit logout(socket, id);
}
break;
case GreeterMessages::Unlock : {
// log message
qDebug() << "Message received from greeter: Unlock";
Expand All @@ -163,18 +173,6 @@ namespace DDM {
emit unlock(socket, user, password);
}
break;
case GreeterMessages::ActivateUser: {
// log message
qDebug() << "Message received from greeter: ActivateUser";

// read username, pasword etc.
QString user;
input >> user;

// emit signal
emit requestActivateUser(socket, user);
}
break;
case GreeterMessages::PowerOff: {
// log message
qDebug() << "Message received from greeter: PowerOff";
Expand Down
3 changes: 2 additions & 1 deletion src/daemon/SocketServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ namespace DDM {
void login(QLocalSocket *socket,
const QString &user, const QString &password,
const Session &session);
void logout(QLocalSocket *socket,
int id);
void unlock(QLocalSocket *socket,
const QString &user, const QString &password);
void connected(QLocalSocket *socket);
void disconnected(QLocalSocket *socket);
void requestActivateUser(QLocalSocket *socket, const QString &user);

private:
QLocalServer *m_server { nullptr };
Expand Down
2 changes: 2 additions & 0 deletions src/helper/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
void setIdentifyOnly(bool on);

inline bool isGreeter() const { return m_greeter; }
inline int sessionId() const { return m_sessionId; }

public slots:

Check warning on line 47 in src/helper/Backend.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
virtual bool start(const QString &user = QString()) = 0;
virtual bool authenticate() = 0;
virtual bool openSession();
Expand All @@ -58,6 +59,7 @@
bool m_displayServer = false;
bool m_greeter { false };
bool m_identifyOnly { false };
int m_sessionId;
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/helper/HelperApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ namespace DDM {
m_session->setProcessEnvironment(env);

if (!m_backend->openSession()) {
sessionOpened(false);
sessionOpened(false, 0);
exit(Auth::HELPER_SESSION_ERROR);
return;
}

sessionOpened(true);
sessionOpened(true, m_backend->sessionId());

// write successful login to utmp/wtmp
const QProcessEnvironment env = m_session->processEnvironment();
Expand Down Expand Up @@ -282,10 +282,10 @@ namespace DDM {
return env;
}

void HelperApp::sessionOpened(bool success) {
void HelperApp::sessionOpened(bool success, int sessionId) {
Msg m = Msg::MSG_UNKNOWN;
SafeDataStream str(m_socket);
str << Msg::SESSION_STATUS << success;
str << Msg::SESSION_STATUS << success << sessionId;
str.send();
str.receive();
str >> m;
Expand Down
2 changes: 1 addition & 1 deletion src/helper/HelperApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace DDM {
void error(const QString &message, Auth::Error type);
QProcessEnvironment authenticated(const QString &user);
void displayServerStarted(const QString &displayName);
void sessionOpened(bool success);
void sessionOpened(bool success, int sessionId);

private slots:
void setUp();
Expand Down
1 change: 1 addition & 0 deletions src/helper/backend/PamBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ namespace DDM {
}
sessionEnv.insert(m_pam->getEnv());
m_app->session()->setProcessEnvironment(sessionEnv);
m_sessionId = sessionEnv.value(QStringLiteral("XDG_SESSION_ID")).toInt();
return Backend::openSession();
}

Expand Down