signon  8.42
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 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  uint daemonTimeout() const { return m_daemonTimeout; }
80  uint identityTimeout() const { return m_identityTimeout; }
81  uint authSessionTimeout() const { return m_authSessionTimeout; }
82 
83 private:
84  QString m_pluginsDir;
85  QString m_extensionsDir;
86 
87  // storage configuration
88  CAMConfiguration m_camConfiguration;
89 
90  //object timeouts
91  uint m_daemonTimeout;
92  uint m_identityTimeout;
93  uint m_authSessionTimeout;
94 };
95 
96 class SignonIdentity;
97 
103 class SignonDaemon: public QObject, protected QDBusContext
104 {
105  Q_OBJECT
106 
107  friend class SignonIdentity;
108  friend class SignonSessionCore;
109  friend class SignonDaemonAdaptor;
110 
111 public:
112  static SignonDaemon *instance();
113  virtual ~SignonDaemon();
114 
115  Q_INVOKABLE void init();
116 
121  int identityTimeout() const;
122  int authSessionTimeout() const;
123 
124 public Q_SLOTS:
125  /* Immediate reply calls */
126 
127  void registerNewIdentity(QDBusObjectPath &objectPath);
128  void getIdentity(const quint32 id, QDBusObjectPath &objectPath,
129  QVariantMap &identityData);
130  QString getAuthSessionObjectPath(const quint32 id, const QString type);
131 
132  QStringList queryMethods();
133  QStringList queryMechanisms(const QString &method);
134  QList<QVariantMap> queryIdentities(const QVariantMap &filter);
135  bool clear();
136  void onDisconnected();
137 
138 public Q_SLOTS: // backup METHODS
139  uchar backupStarts();
140  uchar backupFinished();
141  uchar restoreStarts();
142  uchar restoreFinished();
143 
144 private:
145  SignonDaemon(QObject *parent);
146  void initExtensions();
147  void initExtension(const QString &filePath);
148  bool initStorage();
149 
150  void identityStored(SignonIdentity *identity);
151  void setupSignalHandlers();
152 
153  void eraseBackupDir() const;
154  bool copyToBackupDir(const QStringList &fileNames) const;
155  bool copyFromBackupDir(const QStringList &fileNames) const;
156  bool createStorageFileTree(const QStringList &fileNames) const;
157 
158 private:
159  /*
160  * The list of created SignonIdentities
161  * */
162  QMap<quint32, SignonIdentity *> m_storedIdentities;
163  QMap<QString, SignonIdentity *> m_unstoredIdentities;
164 
165  SignonDaemonConfiguration *m_configuration;
166 
167  /*
168  * The instance of CAM
169  * */
170  CredentialsAccessManager *m_pCAMManager;
171 
172  bool m_backup;
173 
174  int m_identityTimeout;
175  int m_authSessionTimeout;
176 
177  /*
178  * UNIX signals handling related
179  * */
180 public:
181  static void signalHandler(int signal);
182  Q_INVOKABLE void handleUnixSignal();
183 
184 private:
185  QSocketNotifier *m_sigSn;
186  static SignonDaemon *m_instance;
187 }; //class SignonDaemon
188 
189 } //namespace SignonDaemonNS
190 
191 #endif /* SIGNONDAEMON_H_ */