summaryrefslogtreecommitdiff
path: root/libopie2/opiesecurity
Unidiff
Diffstat (limited to 'libopie2/opiesecurity') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiesecurity/multiauthcommon.cpp19
-rw-r--r--libopie2/opiesecurity/multiauthcommon.h3
-rw-r--r--libopie2/opiesecurity/opiesecurity.pro1
3 files changed, 13 insertions, 10 deletions
diff --git a/libopie2/opiesecurity/multiauthcommon.cpp b/libopie2/opiesecurity/multiauthcommon.cpp
index e563193..2760760 100644
--- a/libopie2/opiesecurity/multiauthcommon.cpp
+++ b/libopie2/opiesecurity/multiauthcommon.cpp
@@ -1,195 +1,198 @@
1#include "multiauthplugininterface.h" 1#include "multiauthplugininterface.h"
2#include "multiauthcommon.h" 2#include "multiauthcommon.h"
3 3
4/* Opie */ 4/* Opie */
5#include <opie2/odebug.h> 5#include <opie2/odebug.h>
6#include <opie2/oapplication.h> 6#include <opie2/oapplication.h>
7#include <opie2/ocontactaccessbackend_vcard.h>
8#include <opie2/ocontactaccess.h>
7 9
8/* Qt */ 10/* Qt */
9#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
10#include <qpe/qlibrary.h> 12#include <qpe/qlibrary.h>
11#include <qpe/qcom.h> 13#include <qpe/qcom.h>
12#include <qtextview.h> 14#include <qtextview.h>
13#include <qdir.h> 15#include <qdir.h>
14 16
15/* UNIX */ 17/* UNIX */
16#include <unistd.h> 18#include <unistd.h>
17#include <qpe/config.h> 19#include <qpe/config.h>
18 20
19namespace Opie { 21namespace Opie {
20namespace Security { 22namespace Security {
21 23
22SecOwnerDlg::SecOwnerDlg( QWidget *parent, const char * name, Contact c, 24SecOwnerDlg::SecOwnerDlg( QWidget *parent, const char * name, const QString& c,
23 bool modal, bool fullscreen = FALSE ) 25 bool modal, bool fullscreen = FALSE )
24: QDialog( parent, name, modal, 26: QDialog( parent, name, modal,
25 fullscreen ? 27 fullscreen ?
26 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ) 28 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
27{ 29{
28 if ( fullscreen ) { 30 if ( fullscreen ) {
29 QRect desk = qApp->desktop()->geometry(); 31 QRect desk = qApp->desktop()->geometry();
30 setGeometry( 0, 0, desk.width(), desk.height() ); 32 setGeometry( 0, 0, desk.width(), desk.height() );
31 } 33 }
32 // set up contents. 34 // set up contents.
33 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>"); 35 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>");
34 text += c.toRichText(); 36 text += c;
35 tv = new QTextView(this); 37 tv = new QTextView(this);
36 tv->setText(text); 38 tv->setText(text);
37 39
38 tv->viewport()->installEventFilter(this); 40 tv->viewport()->installEventFilter(this);
39} 41}
40 42
41void SecOwnerDlg::resizeEvent( QResizeEvent * ) 43void SecOwnerDlg::resizeEvent( QResizeEvent * )
42{ 44{
43 tv->resize( size() ); 45 tv->resize( size() );
44} 46}
45 47
46bool SecOwnerDlg::eventFilter(QObject *o, QEvent *e) 48bool SecOwnerDlg::eventFilter(QObject *o, QEvent *e)
47{ 49{
48 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) { 50 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
49 accept(); 51 accept();
50 return TRUE; 52 return TRUE;
51 } 53 }
52 return QWidget::eventFilter(o, e); 54 return QWidget::eventFilter(o, e);
53} 55}
54 56
55void SecOwnerDlg::mousePressEvent( QMouseEvent * ) { accept(); } 57void SecOwnerDlg::mousePressEvent( QMouseEvent * ) { accept(); }
56 58
57 59
58namespace Internal { 60namespace Internal {
59/// run plugins until we reach nbSuccessMin successes 61/// run plugins until we reach nbSuccessMin successes
60int runPlugins() { 62int runPlugins() {
61 63
62 SecOwnerDlg *oi = 0; 64 SecOwnerDlg *oi = 0;
63 // see if there is contact information. 65 // see if there is contact information.
64 QString vfilename = Global::applicationFileName("addressbook", 66 QString vfilename = Global::applicationFileName("addressbook",
65 "businesscard.vcf"); 67 "businesscard.vcf");
66 if (QFile::exists(vfilename)) { 68 Opie::OPimContactAccess acc( "multiauth", vfilename,
67 Contact c; 69 new Opie::OPimContactAccessBackend_VCard( "multiauth", vfilename ) );
68 c = Contact::readVCard( vfilename )[0]; 70 if ( acc.load() ) {
69 71 Opie::OPimContact contact = acc.allRecords()[0];
70 oi = new SecOwnerDlg(0, 0, c, TRUE, TRUE); 72 if ( !contact.isEmpty() )
73 oi = new SecOwnerDlg(0, 0, contact.toRichText(), TRUE, TRUE);
71 } 74 }
72 75
73 Config config("Security"); 76 Config config("Security");
74 config.setGroup("Plugins"); 77 config.setGroup("Plugins");
75 QStringList plugins = config.readListEntry("IncludePlugins", ','); 78 QStringList plugins = config.readListEntry("IncludePlugins", ',');
76 /* if there are no configured plugins, we simply return 0 to 79 /* if there are no configured plugins, we simply return 0 to
77 * let the user in: 80 * let the user in:
78 */ 81 */
79 if (plugins.isEmpty() == true) { 82 if (plugins.isEmpty() == true) {
80 owarn << "No authentication plugin has been configured yet!" << oendl; 83 owarn << "No authentication plugin has been configured yet!" << oendl;
81 odebug << "Letting the user in..." << oendl; 84 odebug << "Letting the user in..." << oendl;
82 if(oi) delete oi; 85 if(oi) delete oi;
83 return 0; 86 return 0;
84 } 87 }
85 config.setGroup("Misc"); 88 config.setGroup("Misc");
86 int nbSuccessMin = config.readNumEntry("nbSuccessMin", 1); 89 int nbSuccessMin = config.readNumEntry("nbSuccessMin", 1);
87 int nbSuccess = 0; 90 int nbSuccess = 0;
88 91
89 /* tries to launch successively each plugin in $OPIEDIR/plugins/security 92 /* tries to launch successively each plugin in $OPIEDIR/plugins/security
90 * directory which file name is in Security.conf / [Misc] / IncludePlugins 93 * directory which file name is in Security.conf / [Misc] / IncludePlugins
91 */ 94 */
92 QString path = QPEApplication::qpeDir() + "plugins/security"; 95 QString path = QPEApplication::qpeDir() + "plugins/security";
93 QStringList::Iterator libIt; 96 QStringList::Iterator libIt;
94 97
95 for ( libIt = plugins.begin(); libIt != plugins.end(); ++libIt ) { 98 for ( libIt = plugins.begin(); libIt != plugins.end(); ++libIt ) {
96 QInterfacePtr<MultiauthPluginInterface> iface; 99 QInterfacePtr<MultiauthPluginInterface> iface;
97 QLibrary *lib = new QLibrary( path + "/" + *libIt ); 100 QLibrary *lib = new QLibrary( path + "/" + *libIt );
98 101
99 if ( lib->queryInterface( 102 if ( lib->queryInterface(
100 IID_MultiauthPluginInterface, 103 IID_MultiauthPluginInterface,
101 (QUnknownInterface**)&iface ) == QS_OK ) 104 (QUnknownInterface**)&iface ) == QS_OK )
102 { 105 {
103 // the plugin is a true Multiauth plugin 106 // the plugin is a true Multiauth plugin
104 odebug << "Accepted plugin: " << QString( path + "/" + *libIt ) << oendl; 107 odebug << "Accepted plugin: " << QString( path + "/" + *libIt ) << oendl;
105 odebug << "Plugin name: " << iface->plugin()->pluginName() << oendl; 108 odebug << "Plugin name: " << iface->plugin()->pluginName() << oendl;
106 109
107 int resultCode; 110 int resultCode;
108 int tries = 0; 111 int tries = 0;
109 112
110 // perform authentication 113 // perform authentication
111 resultCode = iface->plugin()->authenticate(); 114 resultCode = iface->plugin()->authenticate();
112 115
113 // display the result in command line 116 // display the result in command line
114 QString resultMessage; 117 QString resultMessage;
115 switch (resultCode) 118 switch (resultCode)
116 { 119 {
117 case MultiauthPluginObject::Success: 120 case MultiauthPluginObject::Success:
118 resultMessage = "Success!"; 121 resultMessage = "Success!";
119 nbSuccess++; 122 nbSuccess++;
120 break; 123 break;
121 case MultiauthPluginObject::Failure: 124 case MultiauthPluginObject::Failure:
122 resultMessage = "Failure..."; 125 resultMessage = "Failure...";
123 break; 126 break;
124 case MultiauthPluginObject::Skip: 127 case MultiauthPluginObject::Skip:
125 resultMessage = "Skip"; 128 resultMessage = "Skip";
126 break; 129 break;
127 } 130 }
128 odebug << "Plugin result: " << resultMessage << oendl; 131 odebug << "Plugin result: " << resultMessage << oendl;
129 132
130 // if failure, wait, reperform, wait, reperform... until right 133 // if failure, wait, reperform, wait, reperform... until right
131 while (resultCode == MultiauthPluginObject::Failure) 134 while (resultCode == MultiauthPluginObject::Failure)
132 { 135 {
133 tries++; 136 tries++;
134 owarn << "This plugin has failed " << tries << " times already" << oendl; 137 owarn << "This plugin has failed " << tries << " times already" << oendl;
135 138
136 // displays owner information, if any 139 // displays owner information, if any
137 if (oi) 140 if (oi)
138 { 141 {
139 oi->exec(); 142 oi->exec();
140 odebug << "Contact information displayed" << oendl; 143 odebug << "Contact information displayed" << oendl;
141 } 144 }
142 145
143 /// \todo parametrize the time penalty according to \em mode (exponential, 146 /// \todo parametrize the time penalty according to \em mode (exponential,
144 /// linear or fixed) and \em basetime (time penalty for the first failure) 147 /// linear or fixed) and \em basetime (time penalty for the first failure)
145 sleep(2 * tries); 148 sleep(2 * tries);
146 149
147 if (oi) 150 if (oi)
148 { 151 {
149 oi->hide(); 152 oi->hide();
150 /** \todo fix the focus here: should go back to the current plugin widget 153 /** \todo fix the focus here: should go back to the current plugin widget
151 * but it doesn't, so we have to tap once on the widget before e.g. buttons 154 * but it doesn't, so we have to tap once on the widget before e.g. buttons
152 * are active again 155 * are active again
153 */ 156 */
154 odebug << "Contact information hidden" << oendl; 157 odebug << "Contact information hidden" << oendl;
155 } 158 }
156 159
157 // perform authentication 160 // perform authentication
158 resultCode = iface->plugin()->authenticate(); 161 resultCode = iface->plugin()->authenticate();
159 162
160 // display the result in command line 163 // display the result in command line
161 switch (resultCode) 164 switch (resultCode)
162 { 165 {
163 case MultiauthPluginObject::Success: 166 case MultiauthPluginObject::Success:
164 resultMessage = "Success!"; 167 resultMessage = "Success!";
165 nbSuccess++; 168 nbSuccess++;
166 break; 169 break;
167 case MultiauthPluginObject::Failure: 170 case MultiauthPluginObject::Failure:
168 resultMessage = "Failure..."; 171 resultMessage = "Failure...";
169 break; 172 break;
170 case MultiauthPluginObject::Skip: 173 case MultiauthPluginObject::Skip:
171 resultMessage = "Skip"; 174 resultMessage = "Skip";
172 break; 175 break;
173 } 176 }
174 odebug << "Plugin result: " << resultMessage << oendl; 177 odebug << "Plugin result: " << resultMessage << oendl;
175 } 178 }
176 delete lib; 179 delete lib;
177 180
178 if (resultCode == MultiauthPluginObject::Success && nbSuccess == nbSuccessMin) 181 if (resultCode == MultiauthPluginObject::Success && nbSuccess == nbSuccessMin)
179 { 182 {
180 if(oi) delete oi; 183 if(oi) delete oi;
181 // we have reached the required number of successes, we can exit the plugin loop 184 // we have reached the required number of successes, we can exit the plugin loop
182 return 0; 185 return 0;
183 } 186 }
184 } else { 187 } else {
185 owarn << "Could not recognize plugin " << QString( path + "/" + *libIt ) << oendl; 188 owarn << "Could not recognize plugin " << QString( path + "/" + *libIt ) << oendl;
186 delete lib; 189 delete lib;
187 } // end if plugin recognized 190 } // end if plugin recognized
188 } //end for 191 } //end for
189 if(oi) delete oi; 192 delete oi;
190 return 1; 193 return 1;
191} 194}
192 195
193} 196}
194} 197}
195} 198}
diff --git a/libopie2/opiesecurity/multiauthcommon.h b/libopie2/opiesecurity/multiauthcommon.h
index b728dae..42dff17 100644
--- a/libopie2/opiesecurity/multiauthcommon.h
+++ b/libopie2/opiesecurity/multiauthcommon.h
@@ -1,76 +1,75 @@
1/** 1/**
2 * \file multiauthcommon.h 2 * \file multiauthcommon.h
3 * \brief Objects and functions for Opie multiauth framework 3 * \brief Objects and functions for Opie multiauth framework
4 * \author Clément Séveillac (clement . seveillac (at) via . ecp . fr) 4 * \author Clément Séveillac (clement . seveillac (at) via . ecp . fr)
5 */ 5 */
6/* 6/*
7 =. This file is part of the Opie Project 7 =. This file is part of the Opie Project
8 .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> 8 .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
9 .>+-= 9 .>+-=
10 _;:, .> :=|. This library is free software; you can 10 _;:, .> :=|. This library is free software; you can
11.> <`_, > . <= redistribute it and/or modify it under 11.> <`_, > . <= redistribute it and/or modify it under
12:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 12:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
13.="- .-=="i, .._ License as published by the Free Software 13.="- .-=="i, .._ License as published by the Free Software
14 - . .-<_> .<> Foundation; either version 2 of the License, 14 - . .-<_> .<> Foundation; either version 2 of the License,
15 ._= =} : or (at your option) any later version. 15 ._= =} : or (at your option) any later version.
16 .%`+i> _;_. 16 .%`+i> _;_.
17 .i_,=:_. -<s. This library is distributed in the hope that 17 .i_,=:_. -<s. This library is distributed in the hope that
18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
19 : .. .:, . . . without even the implied warranty of 19 : .. .:, . . . without even the implied warranty of
20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.= = ; Library General Public License for more 22..}^=.= = ; Library General Public License for more
23++= -. .` .: details. 23++= -. .` .: details.
24 : = ...= . :.=- 24 : = ...= . :.=-
25 -. .:....=;==+<; You should have received a copy of the GNU 25 -. .:....=;==+<; You should have received a copy of the GNU
26 -_. . . )=. = Library General Public License along with 26 -_. . . )=. = Library General Public License along with
27 -- :-=` this library; see the file COPYING.LIB. 27 -- :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef MULTIAUTHCOMMON_H 34#ifndef MULTIAUTHCOMMON_H
35#define MULTIAUTHCOMMON_H 35#define MULTIAUTHCOMMON_H
36 36
37 37
38/* OwnerDialog stuff */ 38/* OwnerDialog stuff */
39#include <qpe/global.h> 39#include <qpe/global.h>
40#include <qpe/contact.h> 40#include <qpe/contact.h>
41#include <qtextview.h> 41#include <qtextview.h>
42#include <qdialog.h> 42#include <qdialog.h>
43 43
44
45namespace Opie { 44namespace Opie {
46namespace Security { 45namespace Security {
47 46
48/// QDialog simply showing the owner information 47/// QDialog simply showing the owner information
49class SecOwnerDlg : public QDialog 48class SecOwnerDlg : public QDialog
50{ 49{
51 Q_OBJECT 50 Q_OBJECT
52 public: 51 public:
53 52
54 SecOwnerDlg( QWidget *parent, const char * name, Contact c, 53 SecOwnerDlg( QWidget *parent, const char * name, const QString& owner,
55 bool modal, bool fullscreen); 54 bool modal, bool fullscreen);
56 55
57 void resizeEvent( QResizeEvent * ); 56 void resizeEvent( QResizeEvent * );
58 bool eventFilter(QObject *o, QEvent *e); 57 bool eventFilter(QObject *o, QEvent *e);
59 void mousePressEvent( QMouseEvent * ); 58 void mousePressEvent( QMouseEvent * );
60 59
61 private: 60 private:
62 QTextView *tv; 61 QTextView *tv;
63 62
64 private: 63 private:
65 struct Private; 64 struct Private;
66 Private *d; 65 Private *d;
67}; 66};
68 67
69namespace Internal { 68namespace Internal {
70int runPlugins(); 69int runPlugins();
71} 70}
72 71
73} 72}
74} 73}
75 74
76#endif // MULTIAUTHCOMMON_H 75#endif // MULTIAUTHCOMMON_H
diff --git a/libopie2/opiesecurity/opiesecurity.pro b/libopie2/opiesecurity/opiesecurity.pro
index 7171e67..d4d7925 100644
--- a/libopie2/opiesecurity/opiesecurity.pro
+++ b/libopie2/opiesecurity/opiesecurity.pro
@@ -1,17 +1,18 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = multiauthcommon.h \ 4HEADERS = multiauthcommon.h \
5 multiauthmainwindow.h \ 5 multiauthmainwindow.h \
6 multiauthconfigwidget.h \ 6 multiauthconfigwidget.h \
7 multiauthplugininterface.h \ 7 multiauthplugininterface.h \
8 multiauthpassword.h 8 multiauthpassword.h
9SOURCES = multiauthcommon.cpp \ 9SOURCES = multiauthcommon.cpp \
10 multiauthmainwindow.cpp \ 10 multiauthmainwindow.cpp \
11 multiauthpassword.cpp 11 multiauthpassword.cpp
12TARGET = opiesecurity2 12TARGET = opiesecurity2
13VERSION = 0.0.2 13VERSION = 0.0.2
14INCLUDEPATH += $(OPIEDIR)/include 14INCLUDEPATH += $(OPIEDIR)/include
15DEPENDPATH += $(OPIEDIR)/include 15DEPENDPATH += $(OPIEDIR)/include
16LIBS += -lopiepim2
16 17
17include( $(OPIEDIR)/include.pro ) 18include( $(OPIEDIR)/include.pro )