-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathAuth.h
More file actions
118 lines (93 loc) · 3.56 KB
/
Auth.h
File metadata and controls
118 lines (93 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (C) 2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef DDM_AUTH_H
#define DDM_AUTH_H
#include "Display.h"
#include <QObject>
#include <QProcessEnvironment>
#include <QSocketNotifier>
namespace DDM {
class AuthPrivate;
class UserSession;
/** Authentication handler, manage login and session */
class Auth : public QObject {
Q_OBJECT
public:
Auth(QObject *parent, QString user);
~Auth();
/** Indicates whether authenticated (authenticate() is called and succeed) */
bool authenticated{ false };
/** Indicates whether a session is opened with this handle */
bool sessionOpened{ false };
/** Username. Must be set before authenticate() */
QString user{};
/** Display sever type of the session. Must be set before startUserProcess() */
Display::DisplayServerType type{};
/** The "Session ID" (defined and used by DisplayManager) */
QString sessionId{};
/** X Display identifier (e.g. :0), if presents */
QString display{};
/** Virtual terminal number (e.g. 7 for tty7) */
int tty{ 0 };
/** Logind session ID (the XDG_SESSION_ID env var) */
QString session{};
/** PID of the session leader. Positive values are valid */
pid_t sessionLeaderPid{ 0 };
/** PID of the session process started by session leader. Positive values are valid */
qint64 sessionPid{ 0 };
public Q_SLOTS:
/**
* Sets up the environment and starts the authentication.
*
* @param secret Password or other secret data acceptable by PAM
* @return true on success, false on failure
*/
bool authenticate(const QByteArray &secret);
/**
* Starts user process, opens Logind session and returns the
* XDG_SESSION_ID. Must be called after authenticate().
*
* @param command Command to execute as user process
* @param env Environment variables to set for the session
* @param cookie XAuth cookie, must be provided if type=X11
* @return A valid XDG_SESSION_ID on success, empty string on failure
*/
QString openSession(const QString &command,
QProcessEnvironment env,
const QByteArray &cookie = QByteArray());
/**
* Close PAM session
* @return true on success, false on failure
*/
bool closeSession();
/**
* Opens PAM session and returns the environment variables set
* by PAM modules. Must be called in the child process after
* fork()
*
* @param sessionEnv Environment variables to set for the session
* @return Environs retrieved from pam_getenvlist on success, std::nullopt on failure
*/
std::optional<QProcessEnvironment> openSessionInternal(const QProcessEnvironment &sessionEnv);
Q_SIGNALS:
/**
* Emitted when the session process ends.
*/
void sessionFinished();
private:
/**
* Write utmp/wtmp/btmp records when a user logs in
*
* @param success Was authentication successful
*/
void utmpLogin(bool success);
/**
* Write utmp/wtmp records when a user logs out
*/
void utmpLogout();
/** Child process listener */
QSocketNotifier *m_notifier{ nullptr };
AuthPrivate *d{ nullptr };
};
}
#endif // DDM_AUTH_H