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