Skip to content

Commit

Permalink
[lipstick] enablers for devicelock pass code age
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonni Rainisto committed Nov 14, 2014
1 parent 62286a7 commit f7ae844
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 2 additions & 0 deletions plugin/lipstickplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <notifications/notificationlistmodel.h>
#include <notifications/lipsticknotification.h>
#include <volume/volumecontrol.h>
#include <devicelock/devicelock.h>
#include <usbmodeselector.h>
#include <shutdownscreen.h>
#include <compositor/lipstickcompositor.h>
Expand Down Expand Up @@ -61,6 +62,7 @@ void LipstickPlugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<VolumeControl>("org.nemomobile.lipstick", 0, 1, "VolumeControl", "This type is initialized by HomeApplication");
qmlRegisterUncreatableType<USBModeSelector>("org.nemomobile.lipstick", 0, 1, "USBModeSelector", "This type is initialized by HomeApplication");
qmlRegisterUncreatableType<ShutdownScreen>("org.nemomobile.lipstick", 0, 1, "ShutdownScreen", "This type is initialized by HomeApplication");
qmlRegisterUncreatableType<DeviceLock>("org.nemomobile.lipstick", 0, 1, "DeviceLock", "This type is initialized by HomeApplication");

qmlRegisterType<LipstickCompositor>("org.nemomobile.lipstick", 0, 1, "Compositor");
qmlRegisterUncreatableType<QWaylandSurface>("org.nemomobile.lipstick", 0, 1, "WaylandSurface", "This type is created by the compositor");
Expand Down
14 changes: 8 additions & 6 deletions src/devicelock/devicelock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ void DeviceLock::setState(int state)
}
}

bool DeviceLock::checkCode(const QString &code)
int DeviceLock::checkCode(const QString &code)
{
return runPlugin(QStringList() << "--check-code" << code);
}

bool DeviceLock::setCode(const QString &oldCode, const QString &newCode)
int DeviceLock::setCode(const QString &oldCode, const QString &newCode)
{
return runPlugin(QStringList() << "--set-code" << oldCode << newCode);
}
Expand All @@ -177,29 +177,31 @@ bool DeviceLock::isSet() {
return runPlugin(QStringList() << "--is-set" << "lockcode");
}

bool DeviceLock::runPlugin(const QStringList &args)
int DeviceLock::runPlugin(const QStringList &args)
{
QSettings settings("/usr/share/lipstick/devicelock/devicelock.conf", QSettings::IniFormat);
QString pluginName = settings.value("DeviceLock/pluginName").toString();

if (pluginName.isEmpty()) {
qWarning("No plugin configuration set in /usr/share/lipstick/devicelock/devicelock.conf");
return false;
return Failed;
}

QProcess process;
process.start(pluginName, args);
if (!process.waitForFinished()) {
qWarning("Plugin did not finish in time");
return false;
return Failed;
}

#ifdef DEBUG_DEVICELOCK
qDebug() << process.readAllStandardOutput();
qWarning() << process.readAllStandardError();
#endif

return process.exitCode() == 0;
if (process.exitCode() == 0) return OK;
else if (process.exitCode() == 1) return Failed;
else return process.exitCode(); // special cases like Expired and InHistory
}

void DeviceLock::readSettings()
Expand Down
20 changes: 16 additions & 4 deletions src/devicelock/devicelock.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
#include <sys/time.h>
#include <QFileSystemWatcher>
#include <QDBusContext>
#include "lipstickglobal.h"

class MGConfItem;
class QTimer;

class DeviceLock : public QObject, protected QDBusContext
class LIPSTICK_EXPORT DeviceLock : public QObject, protected QDBusContext
{
Q_OBJECT

Q_ENUMS(LockState)
Q_ENUMS(ReturnValue)
Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)

public:
Expand All @@ -42,11 +45,20 @@ class DeviceLock : public QObject, protected QDBusContext
Undefined /*!< Undefined - The state of the lock is unknown */
};

/*!< note: encryption binary returns 0==OK and 1==Failed, switching is done in runPlugin for the QML */
enum ReturnValue
{
Failed = 0, /*!< Failed - syscall returned with default error */
OK, /*!< OK - syscall returned without errors */
Expired, /*!< Expired - lockcode creation date is over the settings limit */
InHistory /*!< InHistory - lockcode was found in history file. */
};

Q_INVOKABLE int state() const;
Q_INVOKABLE void setState(int state);

Q_INVOKABLE bool checkCode(const QString &code);
Q_INVOKABLE bool setCode(const QString &oldCode, const QString &newCode);
Q_INVOKABLE int checkCode(const QString &code);
Q_INVOKABLE int setCode(const QString &oldCode, const QString &newCode);
Q_INVOKABLE bool isSet();

signals:
Expand All @@ -62,7 +74,7 @@ private slots:
void readSettings();

private:
static bool runPlugin(const QStringList &args);
static int runPlugin(const QStringList &args);
void setupTimer();
bool isPrivileged();

Expand Down

0 comments on commit f7ae844

Please sign in to comment.