9#include "ksecretd_debug.h"
12#include <KConfigGroup>
14#include <KDBusService>
15#include <KLocalizedString>
17#include <QApplication>
18#include <QCommandLineParser>
20#include <QSessionManager>
25#include "../kwalletbackend/kwalletbackend.h"
27#include "ksecretd_version.h"
28#include "kwalletfreedesktopservice.h"
31#include <sys/socket.h>
38static int socketfd = 0;
43static char *waitForHash()
45 qCDebug(KSECRETD_LOG) <<
"ksecretd5: Waiting for hash on" << pipefd;
49 char *buf = (
char *)malloc(
sizeof(
char) * PBKDF2_SHA512_KEYSIZE);
50 memset(buf,
'\0', PBKDF2_SHA512_KEYSIZE);
51 while (totalRead != PBKDF2_SHA512_KEYSIZE) {
52 readBytes =
read(pipefd, buf + totalRead, PBKDF2_SHA512_KEYSIZE - totalRead);
53 if (readBytes == -1 || attempts > 5) {
57 totalRead += readBytes;
66static int waitForEnvironment()
68 qCDebug(KSECRETD_LOG) <<
"ksecretd5: waitingForEnvironment on:" << socketfd;
71 struct sockaddr_un remote;
72 socklen_t t =
sizeof(remote);
73 if ((s2 = accept(socketfd, (
struct sockaddr *)&remote, &t)) == -1) {
74 qCWarning(KSECRETD_LOG) <<
"ksecretd5: Couldn't accept incoming connection";
77 qCDebug(KSECRETD_LOG) <<
"ksecretd5: client connected";
79 char str[BSIZE] = {
'\0'};
82 FILE *s3 = fdopen(dup(s2),
"r");
84 if (fgets(str, BSIZE, s3)) {
85 chop = strlen(str) - 1;
86 if (str[chop] ==
'\n') {
94 qCDebug(KSECRETD_LOG) <<
"ksecretd5: client disconnected";
99char *checkPamModule(
int argc,
char **argv)
101 qCDebug(KSECRETD_LOG) <<
"ksecretd5: Checking for pam module";
102 char *hash =
nullptr;
104 for (; x < argc; ++x) {
105 if (strcmp(argv[x],
"--pam-login") != 0) {
108 qCDebug(KSECRETD_LOG) <<
"ksecretd5: Got pam-login param";
113 qCWarning(KSECRETD_LOG) <<
"ksecretd5: Invalid arguments (less than needed)";
118 pipefd = atoi(argv[x]);
122 socketfd = atoi(argv[x]);
127 if (!pipefd || !socketfd) {
128 qCWarning(KSECRETD_LOG) <<
"Lacking a socket, pipe:" << pipefd <<
"env:" << socketfd;
132 hash = waitForHash();
134 if (hash ==
nullptr || waitForEnvironment() == -1) {
135 qCWarning(KSECRETD_LOG) <<
"ksecretd5: Hash or environment not received";
144int main(
int argc,
char **argv)
146 char *hash =
nullptr;
148 if (getenv(
"PAM_KWALLET5_LOGIN")) {
149 hash = checkPamModule(argc, argv);
160 i18n(
"KDE Wallet Service"),
161 KSECRETD_VERSION_STRING,
162 i18n(
"KDE Wallet Service"),
164 i18n(
"(C) 2002-2025, The KDE Developers"));
165 aboutdata.addAuthor(
i18n(
"Valentin Rusu"),
i18n(
"Former Maintainer, GPG backend support"), QStringLiteral(
"kde@rusu.info"));
166 aboutdata.addAuthor(
i18n(
"Michael Leupold"),
i18n(
"Former Maintainer"), QStringLiteral(
"lemma@confuego.org"));
167 aboutdata.addAuthor(
i18n(
"George Staikos"),
i18n(
"Former maintainer"), QStringLiteral(
"staikos@kde.org"));
168 aboutdata.addAuthor(
i18n(
"Thiago Maceira"),
i18n(
"D-Bus Interface"), QStringLiteral(
"thiago@kde.org"));
178 aboutdata.setupCommandLine(&cmdParser);
181 app.setQuitOnLastWindowClosed(
false);
189 if (!KSecretD::isEnabled()) {
190 qCDebug(KSECRETD_LOG) <<
"ksecretd is disabled!";
193 KWalletFreedesktopService(
nullptr);
199 qCDebug(KSECRETD_LOG) <<
"ksecretd6 started";
202 QByteArray passHash(hash, PBKDF2_SHA512_KEYSIZE);
205 qCWarning(KSECRETD_LOG) <<
"Wallet failed to get opened by PAM, error code is" << wallet;
207 qCDebug(KSECRETD_LOG) <<
"Wallet opened by PAM";
static void setApplicationData(const KAboutData &aboutData)
static const QString LocalWallet()
The name of the wallet used to store local passwords.
QString i18n(const char *text, const TYPE &arg...)
KCRASH_EXPORT void initialize()
QVariant read(const QByteArray &data, int versionOverride=0)
const QList< QKeySequence > & close()
void process(const QCoreApplication &app)
void commitDataRequest(QSessionManager &manager)
void saveStateRequest(QSessionManager &manager)
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)