Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start the greeter under the user sddm
  • Loading branch information
davidedmundson committed May 29, 2014
1 parent 655228c commit 484395d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/daemon/Authenticator.cpp
Expand Up @@ -316,9 +316,7 @@ namespace SDDM {
}

// create user session process
process = new Session(QString("Session%1").arg(daemonApp->newSessionId()), this);

m_display->addCookie(QString("%1/.Xauthority").arg(pw->pw_dir));
process = new Session(QString("Session%1").arg(daemonApp->newSessionId()), m_display, this);

// set session process params
process->setUser(pw->pw_name);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/Display.cpp
Expand Up @@ -164,7 +164,7 @@ namespace SDDM {
m_socketServer->start(m_display);

// set greeter params
m_greeter->setDisplay(m_display);
m_greeter->setDisplay(this);
m_greeter->setAuthPath(m_authPath);
m_greeter->setSocket(m_socketServer->socketAddress());
m_greeter->setTheme(QString("%1/%2").arg(daemonApp->configuration()->themesDir()).arg(daemonApp->configuration()->currentTheme()));
Expand Down
36 changes: 32 additions & 4 deletions src/daemon/Greeter.cpp
Expand Up @@ -22,10 +22,16 @@
#include "Configuration.h"
#include "Constants.h"
#include "DaemonApp.h"
#include "Session.h"
#include "Display.h"

#include <QDebug>
#include <QProcess>

#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>

namespace SDDM {
Greeter::Greeter(QObject *parent) : QObject(parent) {
}
Expand All @@ -34,7 +40,7 @@ namespace SDDM {
stop();
}

void Greeter::setDisplay(const QString &display) {
void Greeter::setDisplay(Display *display) {
m_display = display;
}

Expand All @@ -55,8 +61,30 @@ namespace SDDM {
if (m_started)
return false;

struct passwd *pw = nullptr;
if (!daemonApp->configuration()->testing)
{
pw = getpwnam(qPrintable("sddm"));
if (!pw) {
qWarning() << "Failed to switch greeter to user sddm. Running greeter as root";
//continue anyway?? Otherwise we'll block out everyone self compiling
//from logging in
}
}

// create process
m_process = new QProcess(this);
m_process = new Session("sddm-greeter", m_display, this);

if (pw) {
m_process->setUser(pw->pw_name);
m_process->setDir(pw->pw_dir);
m_process->setUid(pw->pw_uid);
m_process->setGid(pw->pw_gid);

// take ownership of the socket so we can read/write to it
// -1 = don't change group
chown(qPrintable(m_socket), pw->pw_uid, -1);
}

// delete process on finish
connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished()));
Expand All @@ -69,7 +97,7 @@ namespace SDDM {

// set process environment
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("DISPLAY", m_display);
env.insert("DISPLAY", m_display->name());
env.insert("XAUTHORITY", m_authPath);
env.insert("XCURSOR_THEME", daemonApp->configuration()->cursorTheme());
m_process->setProcessEnvironment(env);
Expand All @@ -84,7 +112,7 @@ namespace SDDM {

//if we fail to start bail immediately, and don't block in waitForStarted
if (m_process->state() == QProcess::NotRunning) {
qCritical() << "DAEMON: Greeter failed to launch.";
qCritical() << "Greeter failed to launch.";
return false;
}
// wait for greeter to start
Expand Down
11 changes: 6 additions & 5 deletions src/daemon/Greeter.h
Expand Up @@ -22,17 +22,18 @@

#include <QObject>

class QProcess;

namespace SDDM {
class Session;
class Display;

class Greeter : public QObject {
Q_OBJECT
Q_DISABLE_COPY(Greeter)
public:
explicit Greeter(QObject *parent = 0);
~Greeter();

void setDisplay(const QString &display);
void setDisplay(Display *display);
void setAuthPath(const QString &authPath);
void setSocket(const QString &socket);
void setTheme(const QString &theme);
Expand All @@ -49,12 +50,12 @@ namespace SDDM {
private:
bool m_started { false };

QString m_display { "" };
Display *m_display { nullptr };
QString m_authPath { "" };
QString m_socket { "" };
QString m_theme { "" };

QProcess *m_process { nullptr };
Session *m_process { nullptr };
};
}

Expand Down
9 changes: 7 additions & 2 deletions src/daemon/Session.cpp
Expand Up @@ -31,9 +31,10 @@
#include <unistd.h>

namespace SDDM {
Session::Session(const QString &name, QObject *parent) :
Session::Session(const QString &name, Display *display, QObject *parent) :
QProcess(parent),
m_name(name)
m_name(name),
m_display(display)
{
}

Expand Down Expand Up @@ -95,7 +96,11 @@ namespace SDDM {
}
}



if (!m_dir.isEmpty()) {
m_display->addCookie(QString("%1/.Xauthority").arg(m_dir));

// change to user home dir
if (chdir(qPrintable(m_dir))) {
qCritical() << "Failed to change dir to user home.";
Expand Down
5 changes: 4 additions & 1 deletion src/daemon/Session.h
Expand Up @@ -23,11 +23,13 @@
#include <QProcess>

namespace SDDM {
class Display;

class Session : public QProcess {
Q_OBJECT
Q_DISABLE_COPY(Session)
public:
explicit Session(const QString &name, QObject *parent);
explicit Session(const QString &name, Display *display, QObject *parent);

const QString &name() const;

Expand All @@ -44,6 +46,7 @@ namespace SDDM {
QString m_user { "" };
QString m_dir { "" };

Display *m_display { nullptr };
int m_uid { 0 };
int m_gid { 0 };
};
Expand Down

0 comments on commit 484395d

Please sign in to comment.