2014-11-13 01:04:59 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
|
|
|
|
* Copyright (C) 2009 Dario Freddi <drf@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kauthhelpersupport.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include "BackendsManager.h"
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QTimer*)
|
|
|
|
|
|
|
|
namespace KAuth
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace HelperSupport
|
|
|
|
{
|
|
|
|
void helperDebugHandler(QtMsgType type, const char *msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool remote_dbg = false;
|
|
|
|
|
2016-04-11 08:06:16 +00:00
|
|
|
int HelperSupport::helperMain(int argc, char **argv, const char *id, QObject *responder)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2016-04-11 08:06:16 +00:00
|
|
|
#ifdef Q_OS_UNIX
|
2014-11-13 01:04:59 +02:00
|
|
|
//try correct HOME
|
|
|
|
const char *home = "HOME";
|
2016-04-11 08:06:16 +00:00
|
|
|
if(getenv(home)==NULL) {
|
2014-11-13 01:04:59 +02:00
|
|
|
struct passwd *pw = getpwuid(getuid());
|
2016-04-11 08:06:16 +00:00
|
|
|
if (pw!=NULL) {
|
|
|
|
setenv(home, pw->pw_dir, 0 /* overwrite */);
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
openlog(id, 0, LOG_USER);
|
|
|
|
qInstallMsgHandler(&HelperSupport::helperDebugHandler);
|
|
|
|
|
2021-07-21 12:47:43 +03:00
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
2014-11-13 01:04:59 +02:00
|
|
|
if (!BackendsManager::helperProxy()->initHelper(QString::fromLatin1(id))) {
|
|
|
|
syslog(LOG_DEBUG, "Helper initialization failed");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//closelog();
|
|
|
|
remote_dbg = true;
|
|
|
|
|
|
|
|
BackendsManager::helperProxy()->setHelperResponder(responder);
|
|
|
|
|
|
|
|
// Attach the timer
|
|
|
|
QTimer *timer = new QTimer(0);
|
|
|
|
responder->setProperty("__KAuth_Helper_Shutdown_Timer", QVariant::fromValue(timer));
|
|
|
|
timer->setInterval(10000);
|
|
|
|
timer->start();
|
|
|
|
QObject::connect(timer, SIGNAL(timeout()), &app, SLOT(quit()));
|
|
|
|
app.exec(); //krazy:exclude=crashy
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HelperSupport::helperDebugHandler(QtMsgType type, const char *msg)
|
|
|
|
{
|
|
|
|
if (!remote_dbg) {
|
|
|
|
int level = LOG_DEBUG;
|
|
|
|
switch (type) {
|
|
|
|
case QtDebugMsg:
|
|
|
|
level = LOG_DEBUG;
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
level = LOG_WARNING;
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
2021-07-21 13:12:34 +03:00
|
|
|
level = LOG_CRIT;
|
|
|
|
break;
|
2014-11-13 01:04:59 +02:00
|
|
|
case QtFatalMsg:
|
|
|
|
level = LOG_ERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
syslog(level, "%s", msg);
|
|
|
|
} else {
|
|
|
|
BackendsManager::helperProxy()->sendDebugMessage(type, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Anyway I should follow the rule:
|
|
|
|
if (type == QtFatalMsg) {
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HelperSupport::progressStep(int step)
|
|
|
|
{
|
|
|
|
BackendsManager::helperProxy()->sendProgressStep(step);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HelperSupport::progressStep(const QVariantMap &data)
|
|
|
|
{
|
|
|
|
BackendsManager::helperProxy()->sendProgressStep(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HelperSupport::isStopped()
|
|
|
|
{
|
|
|
|
return BackendsManager::helperProxy()->hasToStopAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Auth
|