signon  8.40
signondaemon.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  * Copyright (C) 2012 Canonical Ltd.
00006  *
00007  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00008  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public License
00012  * version 2.1 as published by the Free Software Foundation.
00013  *
00014  * This library is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00022  * 02110-1301 USA
00023  */
00024 
00025 #ifndef SIGNONDAEMON_H_
00026 #define SIGNONDAEMON_H_
00027 
00028 extern "C" {
00029     #include <signal.h>
00030     #include <unistd.h>
00031     #include <errno.h>
00032     #include <stdio.h>
00033     #include <sys/types.h>
00034 }
00035 
00036 #include <QtCore>
00037 #include <QtDBus>
00038 
00039 #include "credentialsaccessmanager.h"
00040 
00041 #ifndef SIGNOND_PLUGINS_DIR
00042     #define SIGNOND_PLUGINS_DIR "/usr/lib/signon"
00043 #endif
00044 
00045 #ifndef SIGNOND_PLUGIN_PREFIX
00046     #define SIGNOND_PLUGIN_PREFIX QLatin1String("lib")
00047 #endif
00048 
00049 #ifndef SIGNOND_PLUGIN_SUFFIX
00050     #define SIGNOND_PLUGIN_SUFFIX QLatin1String("plugin.so")
00051 #endif
00052 
00053 class QSocketNotifier;
00054 
00055 namespace SignonDaemonNS {
00056 
00062 class SignonDaemonConfiguration
00063 {
00064 public:
00065     SignonDaemonConfiguration();
00066     ~SignonDaemonConfiguration();
00067 
00068     const CAMConfiguration &camConfiguration() const {
00069         return m_camConfiguration;
00070     }
00071     void setEncryptionPassphrase(const QByteArray &passphrase) {
00072         m_camConfiguration.m_encryptionPassphrase = passphrase;
00073     }
00074 
00075     void load();
00076 
00077     QString pluginsDir() const { return m_pluginsDir; }
00078     QString extensionsDir() const { return m_extensionsDir; }
00079     uint daemonTimeout() const { return m_daemonTimeout; }
00080     uint identityTimeout() const { return m_identityTimeout; }
00081     uint authSessionTimeout() const { return m_authSessionTimeout; }
00082 
00083 private:
00084     QString m_pluginsDir;
00085     QString m_extensionsDir;
00086 
00087     // storage configuration
00088     CAMConfiguration m_camConfiguration;
00089 
00090     //object timeouts
00091     uint m_daemonTimeout;
00092     uint m_identityTimeout;
00093     uint m_authSessionTimeout;
00094 };
00095 
00096 class SignonIdentity;
00097 
00103 class SignonDaemon: public QObject, protected QDBusContext
00104 {
00105     Q_OBJECT
00106 
00107     friend class SignonIdentity;
00108     friend class SignonSessionCore;
00109     friend class SignonDaemonAdaptor;
00110 
00111 public:
00112     static SignonDaemon *instance();
00113     virtual ~SignonDaemon();
00114 
00115     Q_INVOKABLE void init();
00116 
00121     int identityTimeout() const;
00122     int authSessionTimeout() const;
00123 
00124 public Q_SLOTS:
00125     /* Immediate reply calls */
00126 
00127     void registerNewIdentity(QDBusObjectPath &objectPath);
00128     void getIdentity(const quint32 id, QDBusObjectPath &objectPath,
00129                      QVariantMap &identityData);
00130     QString getAuthSessionObjectPath(const quint32 id, const QString type);
00131 
00132     QStringList queryMethods();
00133     QStringList queryMechanisms(const QString &method);
00134     QList<QVariantMap> queryIdentities(const QVariantMap &filter);
00135     bool clear();
00136     void onDisconnected();
00137 
00138 public Q_SLOTS: // backup METHODS
00139     uchar backupStarts();
00140     uchar backupFinished();
00141     uchar restoreStarts();
00142     uchar restoreFinished();
00143 
00144 private:
00145     SignonDaemon(QObject *parent);
00146     void initExtensions();
00147     void initExtension(const QString &filePath);
00148     bool initStorage();
00149 
00150     void identityStored(SignonIdentity *identity);
00151     void setupSignalHandlers();
00152 
00153     void eraseBackupDir() const;
00154     bool copyToBackupDir(const QStringList &fileNames) const;
00155     bool copyFromBackupDir(const QStringList &fileNames) const;
00156     bool createStorageFileTree(const QStringList &fileNames) const;
00157 
00158 private:
00159     /*
00160      * The list of created SignonIdentities
00161      * */
00162     QMap<quint32, SignonIdentity *> m_storedIdentities;
00163     QMap<QString, SignonIdentity *> m_unstoredIdentities;
00164 
00165     SignonDaemonConfiguration *m_configuration;
00166 
00167     /*
00168      * The instance of CAM
00169      * */
00170     CredentialsAccessManager *m_pCAMManager;
00171 
00172     bool m_backup;
00173 
00174     int m_identityTimeout;
00175     int m_authSessionTimeout;
00176 
00177     /*
00178      * UNIX signals handling related
00179      * */
00180 public:
00181     static void signalHandler(int signal);
00182     Q_INVOKABLE void handleUnixSignal();
00183 
00184 private:
00185     QSocketNotifier *m_sigSn;
00186     static SignonDaemon *m_instance;
00187 }; //class SignonDaemon
00188 
00189 } //namespace SignonDaemonNS
00190 
00191 #endif /* SIGNONDAEMON_H_ */