9#include "kwalletd_debug.h"
12#include <KConfigGroup>
13#include <KDBusService>
14#include <KLocalizedString>
15#include <QApplication>
16#include <QCommandLineParser>
18#include <QSessionManager>
23#include "backend/kwalletbackend.h"
25#include "kwalletd_version.h"
26#include "kwalletfreedesktopservice.h"
29#include <sys/socket.h>
36static int socketfd = 0;
39static bool isWalletEnabled()
41 KConfig cfg(QStringLiteral(
"kwalletrc"));
43 return walletGroup.readEntry(
"Enabled",
true);
48static char *waitForHash()
50 qCDebug(KWALLETD_LOG) <<
"kwalletd5: Waiting for hash on" << pipefd;
54 char *buf = (
char *)malloc(
sizeof(
char) * PBKDF2_SHA512_KEYSIZE);
55 memset(buf,
'\0', PBKDF2_SHA512_KEYSIZE);
56 while (totalRead != PBKDF2_SHA512_KEYSIZE) {
57 readBytes =
read(pipefd, buf + totalRead, PBKDF2_SHA512_KEYSIZE - totalRead);
58 if (readBytes == -1 || attempts > 5) {
62 totalRead += readBytes;
71static int waitForEnvironment()
73 qCDebug(KWALLETD_LOG) <<
"kwalletd5: waitingForEnvironment on:" << socketfd;
76 struct sockaddr_un remote;
77 socklen_t t =
sizeof(remote);
78 if ((s2 = accept(socketfd, (
struct sockaddr *)&remote, &t)) == -1) {
79 qCWarning(KWALLETD_LOG) <<
"kwalletd5: Couldn't accept incoming connection";
82 qCDebug(KWALLETD_LOG) <<
"kwalletd5: client connected";
84 char str[BSIZE] = {
'\0'};
87 FILE *s3 = fdopen(dup(s2),
"r");
89 if (fgets(str, BSIZE, s3)) {
90 chop = strlen(str) - 1;
91 if (str[chop] ==
'\n') {
99 qCDebug(KWALLETD_LOG) <<
"kwalletd5: client disconnected";
104char *checkPamModule(
int argc,
char **argv)
106 qCDebug(KWALLETD_LOG) <<
"kwalletd5: Checking for pam module";
107 char *hash =
nullptr;
109 for (; x < argc; ++x) {
110 if (strcmp(argv[x],
"--pam-login") != 0) {
113 qCDebug(KWALLETD_LOG) <<
"kwalletd5: Got pam-login param";
118 qCWarning(KWALLETD_LOG) <<
"kwalletd5: Invalid arguments (less than needed)";
123 pipefd = atoi(argv[x]);
127 socketfd = atoi(argv[x]);
132 if (!pipefd || !socketfd) {
133 qCWarning(KWALLETD_LOG) <<
"Lacking a socket, pipe:" << pipefd <<
"env:" << socketfd;
137 hash = waitForHash();
139 if (hash ==
nullptr || waitForEnvironment() == -1) {
140 qCWarning(KWALLETD_LOG) <<
"kwalletd5: Hash or environment not received";
150extern "C" Q_DECL_EXPORT
int kdemain(
int argc,
char **argv)
152int main(
int argc,
char **argv)
155 char *hash =
nullptr;
157 if (getenv(
"PAM_KWALLET5_LOGIN")) {
158 hash = checkPamModule(argc, argv);
169 i18n(
"KDE Wallet Service"),
170 KWALLETD_VERSION_STRING,
171 i18n(
"KDE Wallet Service"),
173 i18n(
"(C) 2002-2013, The KDE Developers"));
174 aboutdata.addAuthor(
i18n(
"Valentin Rusu"),
i18n(
"Former Maintainer, GPG backend support"), QStringLiteral(
"kde@rusu.info"));
175 aboutdata.addAuthor(
i18n(
"Michael Leupold"),
i18n(
"Former Maintainer"), QStringLiteral(
"lemma@confuego.org"));
176 aboutdata.addAuthor(
i18n(
"George Staikos"),
i18n(
"Former maintainer"), QStringLiteral(
"staikos@kde.org"));
177 aboutdata.addAuthor(
i18n(
"Thiago Maceira"),
i18n(
"D-Bus Interface"), QStringLiteral(
"thiago@kde.org"));
185 aboutdata.setupCommandLine(&cmdParser);
188 app.setQuitOnLastWindowClosed(
false);
196 if (!isWalletEnabled()) {
197 qCDebug(KWALLETD_LOG) <<
"kwalletd is disabled!";
200 KWalletFreedesktopService(
nullptr);
206 qCDebug(KWALLETD_LOG) <<
"kwalletd6 started";
210 QByteArray passHash(hash, PBKDF2_SHA512_KEYSIZE);
213 qCWarning(KWALLETD_LOG) <<
"Wallet failed to get opened by PAM, error code is" << wallet;
215 qCDebug(KWALLETD_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...)
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)