signon
8.58
|
00001 /* 00002 * This file is part of signon 00003 * 00004 * Copyright (C) 2009-2010 Nokia Corporation. 00005 * Copyright (C) 2012-2013 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 QString busAddress() const { return m_busAddress; } 00080 uint daemonTimeout() const { return m_daemonTimeout; } 00081 uint identityTimeout() const { return m_identityTimeout; } 00082 uint authSessionTimeout() const { return m_authSessionTimeout; } 00083 00084 private: 00085 QString m_pluginsDir; 00086 QString m_extensionsDir; 00087 QString m_busAddress; 00088 00089 // storage configuration 00090 CAMConfiguration m_camConfiguration; 00091 00092 //object timeouts 00093 uint m_daemonTimeout; 00094 uint m_identityTimeout; 00095 uint m_authSessionTimeout; 00096 }; 00097 00098 class SignonIdentity; 00099 00105 class SignonDaemon: public QObject, protected QDBusContext 00106 { 00107 Q_OBJECT 00108 00109 friend class SignonSessionCore; 00110 friend class SignonDaemonAdaptor; 00111 00112 public: 00113 static SignonDaemon *instance(); 00114 virtual ~SignonDaemon(); 00115 00116 Q_INVOKABLE void init(); 00117 00122 int identityTimeout() const; 00123 int authSessionTimeout() const; 00124 00125 public: 00126 QObject *registerNewIdentity(); 00127 QObject *getIdentity(const quint32 id, QVariantMap &identityData); 00128 QObject *getAuthSession(const quint32 id, const QString type, 00129 pid_t ownerPid); 00130 00131 QStringList queryMethods(); 00132 QStringList queryMechanisms(const QString &method); 00133 QList<QVariantMap> queryIdentities(const QVariantMap &filter); 00134 bool clear(); 00135 00136 QString lastErrorName() const { return m_lastErrorName; } 00137 QString lastErrorMessage() const { return m_lastErrorMessage; } 00138 bool lastErrorIsValid() const { return !m_lastErrorName.isEmpty(); } 00139 00140 private Q_SLOTS: 00141 void onDisconnected(); 00142 void onNewConnection(const QDBusConnection &connection); 00143 void onIdentityStored(SignonIdentity *identity); 00144 void onIdentityDestroyed(); 00145 00146 public Q_SLOTS: // backup METHODS 00147 uchar backupStarts(); 00148 uchar backupFinished(); 00149 uchar restoreStarts(); 00150 uchar restoreFinished(); 00151 00152 private: 00153 SignonDaemon(QObject *parent); 00154 void initExtensions(); 00155 void initExtension(const QString &filePath); 00156 bool initStorage(); 00157 00158 void watchIdentity(SignonIdentity *identity); 00159 void setupSignalHandlers(); 00160 00161 void eraseBackupDir() const; 00162 bool copyToBackupDir(const QStringList &fileNames) const; 00163 bool copyFromBackupDir(const QStringList &fileNames) const; 00164 bool createStorageFileTree(const QStringList &fileNames) const; 00165 00166 void setLastError(const QString &name, const QString &msg); 00167 void clearLastError(); 00168 00169 private: 00170 /* 00171 * The list of created SignonIdentities 00172 * */ 00173 QMap<quint32, SignonIdentity *> m_storedIdentities; 00174 00175 SignonDaemonConfiguration *m_configuration; 00176 00177 /* 00178 * The instance of CAM 00179 * */ 00180 CredentialsAccessManager *m_pCAMManager; 00181 00182 bool m_backup; 00183 00184 int m_identityTimeout; 00185 int m_authSessionTimeout; 00186 00187 QDBusServer *m_dbusServer; 00188 00189 QString m_lastErrorName; 00190 QString m_lastErrorMessage; 00191 00192 /* 00193 * UNIX signals handling related 00194 * */ 00195 public: 00196 static void signalHandler(int signal); 00197 Q_INVOKABLE void handleUnixSignal(); 00198 00199 private: 00200 QSocketNotifier *m_sigSn; 00201 static SignonDaemon *m_instance; 00202 }; //class SignonDaemon 00203 00204 } //namespace SignonDaemonNS 00205 00206 #endif /* SIGNONDAEMON_H_ */