summaryrefslogtreecommitdiff
path: root/libopie2/opiesecurity/multiauthcommon.cpp
Unidiff
Diffstat (limited to 'libopie2/opiesecurity/multiauthcommon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiesecurity/multiauthcommon.cpp179
1 files changed, 179 insertions, 0 deletions
diff --git a/libopie2/opiesecurity/multiauthcommon.cpp b/libopie2/opiesecurity/multiauthcommon.cpp
new file mode 100644
index 0000000..b72b9b1
--- a/dev/null
+++ b/libopie2/opiesecurity/multiauthcommon.cpp
@@ -0,0 +1,179 @@
1#include "multiauthplugininterface.h"
2#include "multiauthcommon.h"
3
4/* Opie */
5#include <opie2/odebug.h>
6#include <opie2/oapplication.h>
7
8/* Qt */
9#include <qpe/qpeapplication.h>
10#include <qpe/qlibrary.h>
11#include <qpe/qcom.h>
12#include <qtextview.h>
13#include <qdir.h>
14
15/* UNIX */
16#include <unistd.h>
17#include <qpe/config.h>
18
19
20SecOwnerDlg::SecOwnerDlg( QWidget *parent, const char * name, Contact c,
21 bool modal, bool fullscreen = FALSE )
22: QDialog( parent, name, modal,
23 fullscreen ?
24 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
25{
26 if ( fullscreen ) {
27 QRect desk = qApp->desktop()->geometry();
28 setGeometry( 0, 0, desk.width(), desk.height() );
29 }
30 // set up contents.
31 QString text("<H3>" + tr("Please contact the owner (directions follow), or try again clicking of this screen (and waiting for the penalty time) if you are the legitimate owner") + "</H3>");
32 text += c.toRichText();
33 tv = new QTextView(this);
34 tv->setText(text);
35
36 tv->viewport()->installEventFilter(this);
37}
38
39void SecOwnerDlg::resizeEvent( QResizeEvent * )
40{
41 tv->resize( size() );
42}
43
44bool SecOwnerDlg::eventFilter(QObject *o, QEvent *e)
45{
46 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
47 accept();
48 return TRUE;
49 }
50 return QWidget::eventFilter(o, e);
51}
52
53void SecOwnerDlg::mousePressEvent( QMouseEvent * ) { accept(); }
54
55
56/// run plugins until we reach nbSuccessMin successes
57int runPlugins() {
58
59 SecOwnerDlg *oi = 0;
60 // see if there is contact information.
61 QString vfilename = Global::applicationFileName("addressbook",
62 "businesscard.vcf");
63 if (QFile::exists(vfilename)) {
64 Contact c;
65 c = Contact::readVCard( vfilename )[0];
66
67 oi = new SecOwnerDlg(0, 0, c, TRUE, TRUE);
68 }
69
70 Config config("Security");
71 config.setGroup("Plugins");
72 QStringList plugins = config.readListEntry("IncludePlugins", ',');
73 config.setGroup("Misc");
74 int nbSuccessMin = config.readNumEntry("nbSuccessMin", 1);
75 int nbSuccess = 0;
76
77 /* tries to launch successively each plugin in $OPIEDIR/plugins/security
78 * directory which file name is in Security.conf / [Misc] / IncludePlugins
79 */
80 QString path = QPEApplication::qpeDir() + "/plugins/security";
81 QStringList::Iterator libIt;
82
83 for ( libIt = plugins.begin(); libIt != plugins.end(); ++libIt ) {
84 QInterfacePtr<MultiauthPluginInterface> iface;
85 QLibrary *lib = new QLibrary( path + "/" + *libIt );
86
87 if ( lib->queryInterface(
88 IID_MultiauthPluginInterface,
89 (QUnknownInterface**)&iface ) == QS_OK )
90 {
91 // the plugin is a true Multiauth plugin
92 odebug << "Accepted plugin: " << QString( path + "/" + *libIt ) << oendl;
93 odebug << "Plugin name: " << iface->plugin()->pluginName() << oendl;
94
95 int resultCode;
96 int tries = 0;
97
98 // perform authentication
99 resultCode = iface->plugin()->authenticate();
100
101 // display the result in command line
102 QString resultMessage;
103 switch (resultCode)
104 {
105 case MultiauthPluginObject::Success:
106 resultMessage = "Success!";
107 nbSuccess++;
108 break;
109 case MultiauthPluginObject::Failure:
110 resultMessage = "Failure...";
111 break;
112 case MultiauthPluginObject::Skip:
113 resultMessage = "Skip";
114 break;
115 }
116 odebug << "Plugin result: " << resultMessage << oendl;
117
118 // if failure, wait, reperform, wait, reperform... until right
119 while (resultCode == MultiauthPluginObject::Failure)
120 {
121 tries++;
122 owarn << "This plugin has failed " << tries << " times already" << oendl;
123
124 // displays owner information, if any
125 if (oi)
126 {
127 oi->exec();
128 odebug << "Contact information displayed" << oendl;
129 }
130
131 /// \todo parametrize the time penalty according to \em mode (exponential,
132 /// linear or fixed) and \em basetime (time penalty for the first failure)
133 sleep(2 * tries);
134
135 if (oi)
136 {
137 oi->hide();
138 /** \todo fix the focus here: should go back to the current plugin widget
139 * but it doesn't, so we have to tap once on the widget before e.g. buttons
140 * are active again
141 */
142 odebug << "Contact information hidden" << oendl;
143 }
144
145 // perform authentication
146 resultCode = iface->plugin()->authenticate();
147
148 // display the result in command line
149 switch (resultCode)
150 {
151 case MultiauthPluginObject::Success:
152 resultMessage = "Success!";
153 nbSuccess++;
154 break;
155 case MultiauthPluginObject::Failure:
156 resultMessage = "Failure...";
157 break;
158 case MultiauthPluginObject::Skip:
159 resultMessage = "Skip";
160 break;
161 }
162 odebug << "Plugin result: " << resultMessage << oendl;
163 }
164 delete lib;
165
166 if (resultCode == MultiauthPluginObject::Success && nbSuccess == nbSuccessMin)
167 {
168 if(oi) delete oi;
169 // we have reached the required number of successes, we can exit the plugin loop
170 return 0;
171 }
172 } else {
173 owarn << "Could not recognize plugin " << QString( path + "/" + *libIt ) << oendl;
174 delete lib;
175 } // end if plugin recognized
176 } //end for
177 if(oi) delete oi;
178 return 1;
179}