9#include "kwalletd_debug.h"
12#include <KConfigGroup>
14#include <KDBusService>
15#include <KLocalizedString>
17#include <QApplication>
18#include <QCommandLineParser>
20#include <QSessionManager>
25#include "backend/kwalletbackend.h"
27#include "kwalletd_version.h"
28#include "kwalletfreedesktopservice.h"
31#include <sys/socket.h>
38static int socketfd = 0;
41static bool isWalletEnabled()
43 KConfig cfg(QStringLiteral(
"kwalletrc"));
45 return walletGroup.readEntry(
"Enabled",
true);
50static char *waitForHash()
52 qCDebug(KWALLETD_LOG) <<
"kwalletd5: Waiting for hash on" << pipefd;
56 char *buf = (
char *)malloc(
sizeof(
char) * PBKDF2_SHA512_KEYSIZE);
57 memset(buf,
'\0', PBKDF2_SHA512_KEYSIZE);
58 while (totalRead != PBKDF2_SHA512_KEYSIZE) {
59 readBytes =
read(pipefd, buf + totalRead, PBKDF2_SHA512_KEYSIZE - totalRead);
60 if (readBytes == -1 || attempts > 5) {
64 totalRead += readBytes;
73static int waitForEnvironment()
75 qCDebug(KWALLETD_LOG) <<
"kwalletd5: waitingForEnvironment on:" << socketfd;
78 struct sockaddr_un remote;
79 socklen_t t =
sizeof(remote);
80 if ((s2 = accept(socketfd, (
struct sockaddr *)&remote, &t)) == -1) {
81 qCWarning(KWALLETD_LOG) <<
"kwalletd5: Couldn't accept incoming connection";
84 qCDebug(KWALLETD_LOG) <<
"kwalletd5: client connected";
86 char str[BSIZE] = {
'\0'};
89 FILE *s3 = fdopen(dup(s2),
"r");
91 if (fgets(str, BSIZE, s3)) {
92 chop = strlen(str) - 1;
93 if (str[chop] ==
'\n') {
101 qCDebug(KWALLETD_LOG) <<
"kwalletd5: client disconnected";
106char *checkPamModule(
int argc,
char **argv)
108 qCDebug(KWALLETD_LOG) <<
"kwalletd5: Checking for pam module";
109 char *hash =
nullptr;
111 for (; x < argc; ++x) {
112 if (strcmp(argv[x],
"--pam-login") != 0) {
115 qCDebug(KWALLETD_LOG) <<
"kwalletd5: Got pam-login param";
120 qCWarning(KWALLETD_LOG) <<
"kwalletd5: Invalid arguments (less than needed)";
125 pipefd = atoi(argv[x]);
129 socketfd = atoi(argv[x]);
134 if (!pipefd || !socketfd) {
135 qCWarning(KWALLETD_LOG) <<
"Lacking a socket, pipe:" << pipefd <<
"env:" << socketfd;
139 hash = waitForHash();
141 if (hash ==
nullptr || waitForEnvironment() == -1) {
142 qCWarning(KWALLETD_LOG) <<
"kwalletd5: Hash or environment not received";
151int main(
int argc,
char **argv)
153 char *hash =
nullptr;
155 if (getenv(
"PAM_KWALLET5_LOGIN")) {
156 hash = checkPamModule(argc, argv);
167 i18n(
"KDE Wallet Service"),
168 KWALLETD_VERSION_STRING,
169 i18n(
"KDE Wallet Service"),
171 i18n(
"(C) 2002-2013, The KDE Developers"));
172 aboutdata.addAuthor(
i18n(
"Valentin Rusu"),
i18n(
"Former Maintainer, GPG backend support"), QStringLiteral(
"kde@rusu.info"));
173 aboutdata.addAuthor(
i18n(
"Michael Leupold"),
i18n(
"Former Maintainer"), QStringLiteral(
"lemma@confuego.org"));
174 aboutdata.addAuthor(
i18n(
"George Staikos"),
i18n(
"Former maintainer"), QStringLiteral(
"staikos@kde.org"));
175 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...)
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)