signon  8.58
signondaemon.h
Go to the documentation of this file.
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  * Copyright (C) 2012-2013 Canonical Ltd.
6  *
7  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
8  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * version 2.1 as published by the Free Software Foundation.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  */
24 
25 #ifndef SIGNONDAEMON_H_
26 #define SIGNONDAEMON_H_
27 
28 extern "C" {
29  #include <signal.h>
30  #include <unistd.h>
31  #include <errno.h>
32  #include <stdio.h>
33  #include <sys/types.h>
34 }
35 
36 #include <QtCore>
37 #include <QtDBus>
38 
40 
41 #ifndef SIGNOND_PLUGINS_DIR
42  #define SIGNOND_PLUGINS_DIR "/usr/lib/signon"
43 #endif
44 
45 #ifndef SIGNOND_PLUGIN_PREFIX
46  #define SIGNOND_PLUGIN_PREFIX QLatin1String("lib")
47 #endif
48 
49 #ifndef SIGNOND_PLUGIN_SUFFIX
50  #define SIGNOND_PLUGIN_SUFFIX QLatin1String("plugin.so")
51 #endif
52 
53 class QSocketNotifier;
54 
55 namespace SignonDaemonNS {
56 
63 {
64 public:
67 
69  return m_camConfiguration;
70  }
71  void setEncryptionPassphrase(const QByteArray &passphrase) {
72  m_camConfiguration.m_encryptionPassphrase = passphrase;
73  }
74 
75  void load();
76 
77  QString pluginsDir() const { return m_pluginsDir; }
78  QString extensionsDir() const { return m_extensionsDir; }
79  QString busAddress() const { return m_busAddress; }
80  uint daemonTimeout() const { return m_daemonTimeout; }
81  uint identityTimeout() const { return m_identityTimeout; }
82  uint authSessionTimeout() const { return m_authSessionTimeout; }
83 
84 private:
85  QString m_pluginsDir;
86  QString m_extensionsDir;
87  QString m_busAddress;
88 
89  // storage configuration
90  CAMConfiguration m_camConfiguration;
91 
92  //object timeouts
93  uint m_daemonTimeout;
94  uint m_identityTimeout;
95  uint m_authSessionTimeout;
96 };
97 
98 class SignonIdentity;
99 
105 class SignonDaemon: public QObject, protected QDBusContext
106 {
107  Q_OBJECT
108 
109  friend class SignonSessionCore;
110  friend class SignonDaemonAdaptor;
111 
112 public:
113  static SignonDaemon *instance();
114  virtual ~SignonDaemon();
115 
116  Q_INVOKABLE void init();
117 
122  int identityTimeout() const;
123  int authSessionTimeout() const;
124 
125 public:
126  QObject *registerNewIdentity();
127  QObject *getIdentity(const quint32 id, QVariantMap &identityData);
128  QObject *getAuthSession(const quint32 id, const QString type,
129  pid_t ownerPid);
130 
131  QStringList queryMethods();
132  QStringList queryMechanisms(const QString &method);
133  QList<QVariantMap> queryIdentities(const QVariantMap &filter);
134  bool clear();
135 
136  QString lastErrorName() const { return m_lastErrorName; }
137  QString lastErrorMessage() const { return m_lastErrorMessage; }
138  bool lastErrorIsValid() const { return !m_lastErrorName.isEmpty(); }
139 
140 private Q_SLOTS:
141  void onDisconnected();
142  void onNewConnection(const QDBusConnection &connection);
143  void onIdentityStored(SignonIdentity *identity);
144  void onIdentityDestroyed();
145 
146 public Q_SLOTS: // backup METHODS
147  uchar backupStarts();
148  uchar backupFinished();
149  uchar restoreStarts();
150  uchar restoreFinished();
151 
152 private:
153  SignonDaemon(QObject *parent);
154  void initExtensions();
155  void initExtension(const QString &filePath);
156  bool initStorage();
157 
158  void watchIdentity(SignonIdentity *identity);
159  void setupSignalHandlers();
160 
161  void eraseBackupDir() const;
162  bool copyToBackupDir(const QStringList &fileNames) const;
163  bool copyFromBackupDir(const QStringList &fileNames) const;
164  bool createStorageFileTree(const QStringList &fileNames) const;
165 
166  void setLastError(const QString &name, const QString &msg);
167  void clearLastError();
168 
169 private:
170  /*
171  * The list of created SignonIdentities
172  * */
173  QMap<quint32, SignonIdentity *> m_storedIdentities;
174 
175  SignonDaemonConfiguration *m_configuration;
176 
177  /*
178  * The instance of CAM
179  * */
180  CredentialsAccessManager *m_pCAMManager;
181 
182  bool m_backup;
183 
184  int m_identityTimeout;
185  int m_authSessionTimeout;
186 
187  QDBusServer *m_dbusServer;
188 
189  QString m_lastErrorName;
190  QString m_lastErrorMessage;
191 
192  /*
193  * UNIX signals handling related
194  * */
195 public:
196  static void signalHandler(int signal);
197  Q_INVOKABLE void handleUnixSignal();
198 
199 private:
200  QSocketNotifier *m_sigSn;
201  static SignonDaemon *m_instance;
202 }; //class SignonDaemon
203 
204 } //namespace SignonDaemonNS
205 
206 #endif /* SIGNONDAEMON_H_ */
Daemon side representation of authentication session.
const CAMConfiguration & camConfiguration() const
Definition: signondaemon.h:68
void setEncryptionPassphrase(const QByteArray &passphrase)
Definition: signondaemon.h:71
QString lastErrorMessage() const
Definition: signondaemon.h:137
Main singleton and manager object of the credentials database system.
Definition of the CredentialsAccessManager object.
Daemon side representation of identity.
Configuration object for the CredentialsAccessManager - CAM.
QByteArray m_encryptionPassphrase
Passphrase used for opening encrypted FS.
The daemon&#39;s configuration object; loads date from the daemon configuration file. ...
Definition: signondaemon.h:62
QString lastErrorName() const
Definition: signondaemon.h:136