Diffstat (limited to 'core/settings/security/multiauthconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/security/multiauthconfig.cpp | 665 |
1 files changed, 665 insertions, 0 deletions
diff --git a/core/settings/security/multiauthconfig.cpp b/core/settings/security/multiauthconfig.cpp new file mode 100644 index 0000000..0ce4542 --- a/dev/null +++ b/core/settings/security/multiauthconfig.cpp | |||
@@ -0,0 +1,665 @@ | |||
1 | #include "multiauthconfig.h" | ||
2 | |||
3 | #include <opie2/odebug.h> | ||
4 | |||
5 | #include <qgroupbox.h> | ||
6 | #include <qpe/resource.h> | ||
7 | #include <qlayout.h> | ||
8 | #include <qlabel.h> | ||
9 | #include <qhbox.h> | ||
10 | #include <qheader.h> | ||
11 | #include <qvbox.h> | ||
12 | #include <qwhatsthis.h> | ||
13 | #include <qtoolbutton.h> | ||
14 | #include <qstringlist.h> | ||
15 | #include <qdir.h> | ||
16 | #include <qpe/qlibrary.h> | ||
17 | #include <qpe/qpeapplication.h> | ||
18 | |||
19 | |||
20 | using Opie::Security::MultiauthPluginInterface; | ||
21 | using Opie::Security::MultiauthPluginObject; | ||
22 | using Opie::Security::MultiauthConfigWidget; | ||
23 | /// keeps information about MultiauthPluginObject plugins | ||
24 | struct MultiauthPlugin { | ||
25 | MultiauthPlugin() : library( 0 ), iface( 0 ), pluginObject( 0 ) {} | ||
26 | /// plugin file | ||
27 | QLibrary *library; | ||
28 | /// the plugin object interface | ||
29 | QInterfacePtr<MultiauthPluginInterface> iface; | ||
30 | /// the plugin object itself | ||
31 | MultiauthPluginObject *pluginObject; | ||
32 | /// name of the plugin file | ||
33 | QString name; | ||
34 | /// should the plugin be launched during authentication or not | ||
35 | bool active; | ||
36 | /// order of the plugin, in the pluginListWidget and during authentication | ||
37 | int pos; | ||
38 | }; | ||
39 | |||
40 | /// list of available MultiauthPlugin objects | ||
41 | static QValueList<MultiauthPlugin> pluginList; | ||
42 | |||
43 | |||
44 | /// extension of QToolButton that adds signals, icons and stuff (taken from todayconfig.cpp) | ||
45 | class ToolButton : public QToolButton { | ||
46 | |||
47 | public: | ||
48 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) | ||
49 | : QToolButton( parent, name ) { | ||
50 | setPixmap( Resource::loadPixmap( icon ) ); | ||
51 | setAutoRaise( TRUE ); | ||
52 | setFocusPolicy( QWidget::NoFocus ); | ||
53 | setToggleButton( t ); | ||
54 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); | ||
55 | } | ||
56 | }; | ||
57 | |||
58 | MultiauthGeneralConfig::MultiauthGeneralConfig(QWidget * parent, const char * name = "general Opie-multiauthentication config widget") | ||
59 | : QWidget(parent, name), onStart(0), onResume(0), nbSuccessMin(0) | ||
60 | { | ||
61 | QVBoxLayout *vb = new QVBoxLayout(this); | ||
62 | vb->setSpacing(11); | ||
63 | vb->setMargin(11); | ||
64 | vb->setAlignment( Qt::AlignTop ); | ||
65 | |||
66 | QGroupBox *lockBox = new QGroupBox(0, Qt::Vertical, tr("When to lock Opie"), this, "lock box"); | ||
67 | vb->addWidget(lockBox); | ||
68 | QGridLayout *boxLayout = new QGridLayout( lockBox->layout() ); | ||
69 | onStart = new QCheckBox( tr( "on Opie start" ), lockBox, "lock on opie start"); | ||
70 | onResume = new QCheckBox( tr( "on Opie resume" ), lockBox, "lock on opie resume"); | ||
71 | boxLayout->addWidget(onStart, 0, 0); | ||
72 | boxLayout->addWidget(onResume, 0, 1); | ||
73 | |||
74 | QGroupBox *nbBox = new QGroupBox(0, Qt::Vertical, tr("Multiple plugins authentication"), this, "nb box"); | ||
75 | vb->addWidget(nbBox); | ||
76 | QGridLayout *nbBoxLayout = new QGridLayout( nbBox->layout() ); | ||
77 | nbSuccessMin = new QSpinBox(nbBox); | ||
78 | QLabel *lNbSuccessMin = new QLabel( tr( "Required successes" ), nbBox); | ||
79 | nbBoxLayout->addWidget(nbSuccessMin, 0, 0); | ||
80 | nbBoxLayout->addWidget(lNbSuccessMin, 0, 1); | ||
81 | nbSuccessMin->setMinValue(1); // the max value is defined in MultiauthConfig constructor | ||
82 | |||
83 | QGroupBox *devBox = new QGroupBox(0, Qt::Vertical, tr("Debug options"), this, "dev box"); | ||
84 | vb->addWidget(devBox); | ||
85 | QGridLayout *devBoxLayout = new QGridLayout( devBox->layout() ); | ||
86 | noProtectConfig = new QCheckBox( tr("Don't protect this config screen"), devBox, "don't protect config"); | ||
87 | explanScreens = new QCheckBox( tr("Show explanatory screens"), devBox, "Show explan. screens"); | ||
88 | allowBypass = new QCheckBox( tr("Allow to bypass authentication"), devBox, "AllowBypass"); | ||
89 | QLabel *logicNote = new QLabel( "<p>" + tr("Note: the third option implies the second one") + "</p>", devBox ); | ||
90 | devBoxLayout->addWidget(noProtectConfig, 0, 0); | ||
91 | devBoxLayout->addWidget(explanScreens, 1, 0); | ||
92 | devBoxLayout->addWidget(allowBypass, 2, 0); | ||
93 | devBoxLayout->addMultiCellWidget(logicNote, 3, 3, 0, 1); | ||
94 | |||
95 | connect( explanScreens, SIGNAL(toggled(bool)), this, SLOT(checkBypass()) ); | ||
96 | connect( allowBypass, SIGNAL(toggled(bool)), this, SLOT(checkScreens()) ); | ||
97 | } | ||
98 | |||
99 | /// nothing to do | ||
100 | MultiauthGeneralConfig::~MultiauthGeneralConfig() | ||
101 | {} | ||
102 | |||
103 | /// Be sure that explanScreens is checked if allowBypass is | ||
104 | void MultiauthGeneralConfig::checkScreens() | ||
105 | { | ||
106 | if ( (allowBypass->isChecked() == true) && (explanScreens->isChecked() == false) ) | ||
107 | explanScreens->setChecked(true); | ||
108 | } | ||
109 | |||
110 | /// Be sure that allowBypass is not checked if explanScreens is not | ||
111 | void MultiauthGeneralConfig::checkBypass() | ||
112 | { | ||
113 | if ( (allowBypass->isChecked() == true) && (explanScreens->isChecked() == false) ) | ||
114 | allowBypass->setChecked(false); | ||
115 | } | ||
116 | |||
117 | /// Builds and displays the Opie multi-authentication configuration dialog | ||
118 | MultiauthConfig::MultiauthConfig() : QDialog(0, 0, TRUE), | ||
119 | m_mainTW(0), m_pluginListView(0), m_pluginListWidget(0), | ||
120 | m_generalConfig(0), m_loginWidget(0), m_syncWidget(0), | ||
121 | m_nbSuccessReq(0), m_plugins_changed(false) | ||
122 | { | ||
123 | /* Initializes the global configuration window | ||
124 | */ | ||
125 | setCaption( tr( "Security configuration" ) ); | ||
126 | QVBoxLayout *layout = new QVBoxLayout( this ); | ||
127 | m_mainTW = new Opie::Ui::OTabWidget( this ); | ||
128 | layout->addWidget(m_mainTW); | ||
129 | m_pluginListWidget = new QWidget(m_mainTW, "plugin list widget"); | ||
130 | QVBoxLayout * pluginListLayout = new QVBoxLayout(m_pluginListWidget); | ||
131 | pluginListLayout->setSpacing(6); | ||
132 | pluginListLayout->setMargin(11); | ||
133 | QLabel * pluginListTitle = new QLabel( tr( "Load which plugins in what order:" ), m_pluginListWidget ); | ||
134 | pluginListLayout->addWidget(pluginListTitle); | ||
135 | QHBox * pluginListHB = new QHBox(m_pluginListWidget); | ||
136 | pluginListLayout->addWidget(pluginListHB); | ||
137 | |||
138 | m_pluginListView = new QListView(pluginListHB); | ||
139 | m_pluginListView->addColumn("PluginList"); | ||
140 | m_pluginListView->header()->hide(); | ||
141 | m_pluginListView->setSorting(-1); | ||
142 | QWhatsThis::add(m_pluginListView, tr( "Check a checkbox to activate/deactivate a plugin or use the arrow buttons on the right to change the order they will appear in" )); | ||
143 | |||
144 | QVBox * pluginListVB = new QVBox(pluginListHB); | ||
145 | new ToolButton( pluginListVB, tr( "Move Up" ), "up", this , SLOT( moveSelectedUp() ) ); | ||
146 | new ToolButton( pluginListVB, tr( "Move Down" ), "down", this , SLOT( moveSelectedDown() ) ); | ||
147 | m_mainTW->addTab( m_pluginListWidget, "pass", tr( "plugins" ) ); | ||
148 | |||
149 | connect ( m_pluginListView , SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( pluginsChanged ( ) ) ); | ||
150 | |||
151 | // general Opie multi-authentication configuration tab | ||
152 | m_generalConfig = new MultiauthGeneralConfig(m_mainTW); | ||
153 | m_mainTW->addTab(m_generalConfig, "SettingsIcon", tr( "Authentication") ); | ||
154 | |||
155 | // login settings page | ||
156 | m_loginWidget = new LoginBase(m_mainTW, "login config widget"); | ||
157 | m_mainTW->addTab(m_loginWidget, "security/users", tr( "Login") ); | ||
158 | |||
159 | // sync settings page | ||
160 | m_syncWidget = new SyncBase( m_mainTW, "sync config widget" ); | ||
161 | m_mainTW->addTab(m_syncWidget, "security/sync", tr( "Sync") ); | ||
162 | |||
163 | // read the "Security" Config file and update our UI | ||
164 | readConfig(); | ||
165 | |||
166 | /* loads plugins configuration widgets in mainTW tabs and in pluginListView | ||
167 | */ | ||
168 | |||
169 | loadPlugins(); | ||
170 | |||
171 | for ( int i = pluginList.count() - 1; i >= 0; i-- ) { | ||
172 | MultiauthPlugin plugin = pluginList[i]; | ||
173 | |||
174 | // load the config widgets in the tabs | ||
175 | // (configWidget will return 0l if there is no configuration GUI) | ||
176 | MultiauthConfigWidget* widget = plugin.pluginObject->configWidget(m_mainTW); | ||
177 | if ( widget != 0l ) { | ||
178 | odebug << "plugin " << plugin.name << " has a configuration widget" << oendl; | ||
179 | configWidgetList.append(widget); | ||
180 | m_mainTW->addTab( widget, plugin.pluginObject->pixmapNameConfig(), | ||
181 | plugin.pluginObject->pluginName() ); | ||
182 | } | ||
183 | // set the order/activate tab | ||
184 | QPixmap icon = Resource::loadPixmap( plugin.pluginObject->pixmapNameWidget() ); | ||
185 | QCheckListItem * item = new QCheckListItem(m_pluginListView, plugin.pluginObject->pluginName(), QCheckListItem::CheckBox ); | ||
186 | if ( !icon.isNull() ) { | ||
187 | item->setPixmap( 0, icon ); | ||
188 | } | ||
189 | if ( m_excludePlugins.find( plugin.name ) == m_excludePlugins.end() ) { | ||
190 | item->setOn( TRUE ); | ||
191 | } | ||
192 | m_plugins[plugin.name] = item; | ||
193 | } | ||
194 | |||
195 | // set the first tab as default. | ||
196 | m_mainTW->setCurrentTab(m_pluginListWidget); | ||
197 | |||
198 | // put the number of plugins as the max number of req. auth. | ||
199 | m_generalConfig->nbSuccessMin->setMaxValue( pluginList.count() ); | ||
200 | |||
201 | showMaximized(); | ||
202 | } | ||
203 | |||
204 | /// nothing to do | ||
205 | MultiauthConfig::~MultiauthConfig() | ||
206 | { | ||
207 | } | ||
208 | |||
209 | /// moves up the selected plugin | ||
210 | void MultiauthConfig::moveSelectedUp() | ||
211 | { | ||
212 | QListViewItem *item = m_pluginListView->selectedItem(); | ||
213 | if ( item && item->itemAbove() ) { | ||
214 | item->itemAbove()->moveItem( item ); | ||
215 | } | ||
216 | } | ||
217 | |||
218 | /// moves down the selected plugin | ||
219 | void MultiauthConfig::moveSelectedDown() | ||
220 | { | ||
221 | QListViewItem *item = m_pluginListView->selectedItem(); | ||
222 | if ( item && item->itemBelow() ) { | ||
223 | item->moveItem( item->itemBelow() ); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | /// reads the <code>Security.conf</code> Config file, and updates parts of the user interface | ||
228 | void MultiauthConfig::readConfig() | ||
229 | { | ||
230 | // pointer, so we release this Config when we want | ||
231 | Config* pcfg = new Config("Security"); | ||
232 | pcfg->setGroup( "Misc" ); | ||
233 | m_generalConfig->onStart->setChecked( pcfg->readBoolEntry( "onStart", false ) ); | ||
234 | m_generalConfig->onResume->setChecked( pcfg->readBoolEntry( "onResume", false ) ); | ||
235 | m_generalConfig->nbSuccessMin->setValue( pcfg->readNumEntry( "nbSuccessMin", 1 ) ); | ||
236 | m_generalConfig->noProtectConfig->setChecked( pcfg->readBoolEntry( "noProtectConfig", true) ); | ||
237 | m_generalConfig->explanScreens->setChecked( pcfg->readBoolEntry( "explanScreens", true ) ); | ||
238 | m_generalConfig->allowBypass->setChecked( pcfg->readBoolEntry( "allowBypass", false ) ); | ||
239 | |||
240 | pcfg->setGroup( "Plugins" ); | ||
241 | m_excludePlugins = pcfg->readListEntry( "ExcludePlugins", ',' ); | ||
242 | m_allPlugins = pcfg->readListEntry( "AllPlugins", ',' ); | ||
243 | |||
244 | /* Login and Sync stuff */ | ||
245 | pcfg->setGroup("Sync"); | ||
246 | int auth_peer = pcfg->readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 | ||
247 | int auth_peer_bits = pcfg->readNumEntry("auth_peer_bits",24); | ||
248 | |||
249 | pcfg->setGroup("SyncMode"); | ||
250 | int mode = pcfg->readNumEntry("Mode",2); // Default to Sharp | ||
251 | switch( mode ) { | ||
252 | case 0x01: | ||
253 | m_syncWidget->syncModeCombo->setCurrentItem( 0 ); | ||
254 | break; | ||
255 | case 0x02: | ||
256 | default: | ||
257 | m_syncWidget->syncModeCombo->setCurrentItem( 1 ); | ||
258 | break; | ||
259 | case 0x04: | ||
260 | m_syncWidget->syncModeCombo->setCurrentItem( 2 ); | ||
261 | break; | ||
262 | } | ||
263 | /* | ||
264 | cfg.setGroup("Remote"); | ||
265 | if ( telnetAvailable() ) | ||
266 | telnet->setChecked(cfg.readEntry("allow_telnet")); | ||
267 | else | ||
268 | telnet->hide(); | ||
269 | |||
270 | if ( sshAvailable() ) | ||
271 | ssh->setChecked(cfg.readEntry("allow_ssh")); | ||
272 | else | ||
273 | ssh->hide(); | ||
274 | */ | ||
275 | |||
276 | // release the Config handler | ||
277 | delete pcfg; | ||
278 | // indeed, selectNet will open the config file... | ||
279 | selectNet(auth_peer,auth_peer_bits,TRUE); | ||
280 | |||
281 | connect( m_syncWidget->syncnet, SIGNAL(textChanged(const QString&)), | ||
282 | this, SLOT(setSyncNet(const QString&))); | ||
283 | |||
284 | |||
285 | |||
286 | QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; | ||
287 | Config loginCfg(configFile,Config::File); | ||
288 | |||
289 | loginCfg.setGroup("General"); | ||
290 | autoLoginName=loginCfg.readEntry("AutoLogin",""); | ||
291 | |||
292 | if (autoLoginName.stripWhiteSpace().isEmpty()) { | ||
293 | autoLogin=false; | ||
294 | } else { | ||
295 | autoLogin=true; | ||
296 | } | ||
297 | |||
298 | |||
299 | connect(m_loginWidget->autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool))); | ||
300 | connect(m_loginWidget->userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int))); | ||
301 | connect(m_syncWidget->restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults())); | ||
302 | connect(m_syncWidget->deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry())); | ||
303 | |||
304 | loadUsers(); | ||
305 | updateGUI(); | ||
306 | |||
307 | } | ||
308 | |||
309 | void MultiauthConfig::writeConfig() | ||
310 | { | ||
311 | Config* pcfg = new Config("Security"); | ||
312 | pcfg->setGroup( "Plugins" ); | ||
313 | QStringList exclude; | ||
314 | QStringList include; | ||
315 | QStringList allPlugins; | ||
316 | |||
317 | QListViewItemIterator list_it( m_pluginListView ); | ||
318 | |||
319 | // this makes sure the names get saved in the order selected | ||
320 | for ( ; list_it.current(); ++list_it ) { | ||
321 | QMap <QString, QCheckListItem *>::Iterator it; | ||
322 | for ( it = m_plugins.begin(); it != m_plugins. end (); ++it ) { | ||
323 | if ( list_it.current() == (*it) && !(*it)-> isOn () ) { | ||
324 | exclude << it.key(); | ||
325 | } else if ( list_it.current() == (*it) && (*it)-> isOn () ){ | ||
326 | include << it.key(); | ||
327 | } | ||
328 | if ( list_it.current() == (*it) ) { | ||
329 | allPlugins << it.key(); | ||
330 | } | ||
331 | } | ||
332 | } | ||
333 | pcfg->writeEntry( "ExcludePlugins", exclude, ',' ); | ||
334 | pcfg->writeEntry( "IncludePlugins", include, ',' ); | ||
335 | pcfg->writeEntry( "AllPlugins", allPlugins, ',' ); | ||
336 | |||
337 | pcfg->setGroup( "Misc" ); | ||
338 | pcfg->writeEntry( "onStart", m_generalConfig->onStart->isChecked() ); | ||
339 | pcfg->writeEntry( "onResume", m_generalConfig->onResume->isChecked() ); | ||
340 | pcfg->writeEntry( "nbSuccessMin", m_generalConfig->nbSuccessMin->text() ); | ||
341 | pcfg->writeEntry( "noProtectConfig", m_generalConfig->noProtectConfig->isChecked() ); | ||
342 | pcfg->writeEntry( "explanScreens", m_generalConfig->explanScreens->isChecked() ); | ||
343 | pcfg->writeEntry( "allowBypass", m_generalConfig->allowBypass->isChecked() ); | ||
344 | |||
345 | /* Login and Sync stuff */ | ||
346 | |||
347 | pcfg->setGroup("Sync"); | ||
348 | int auth_peer=0; | ||
349 | int auth_peer_bits; | ||
350 | QString sn = m_syncWidget->syncnet->currentText(); | ||
351 | parseNet(sn,auth_peer,auth_peer_bits); | ||
352 | |||
353 | //this is the *selected* (active) net range | ||
354 | pcfg->writeEntry("auth_peer",auth_peer); | ||
355 | pcfg->writeEntry("auth_peer_bits",auth_peer_bits); | ||
356 | |||
357 | //write back all other net ranges in *cleartext* | ||
358 | for (int i=0; i<10; i++) { | ||
359 | QString target; | ||
360 | target.sprintf("net%d", i); | ||
361 | pcfg->writeEntry(target,m_syncWidget->syncnet->text(i)); | ||
362 | } | ||
363 | |||
364 | #ifdef ODP | ||
365 | #error "Use 0,1,2 and use Launcher" | ||
366 | #endif | ||
367 | /* keep the old code so we don't use currentItem directly */ | ||
368 | int value = 0x02; | ||
369 | switch( m_syncWidget->syncModeCombo->currentItem() ) { | ||
370 | case 0: | ||
371 | value = 0x01; | ||
372 | break; | ||
373 | case 1: | ||
374 | value = 0x02; | ||
375 | break; | ||
376 | case 2: | ||
377 | value = 0x04; | ||
378 | break; | ||
379 | } | ||
380 | pcfg->setGroup("SyncMode"); | ||
381 | pcfg->writeEntry( "Mode", value ); | ||
382 | |||
383 | /* | ||
384 | pcfg->setGroup("Remote"); | ||
385 | if ( telnetAvailable() ) | ||
386 | pcfg->writeEntry("allow_telnet",telnet->isChecked()); | ||
387 | if ( sshAvailable() ) | ||
388 | pcfg->writeEntry("allow_ssh",ssh->isChecked()); | ||
389 | // ### write ssh/telnet sys config files | ||
390 | */ | ||
391 | |||
392 | //release the Config handler | ||
393 | delete pcfg; | ||
394 | |||
395 | QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; | ||
396 | Config loginCfg(configFile,Config::File); | ||
397 | loginCfg.setGroup("General"); | ||
398 | |||
399 | if (autoLogin) { | ||
400 | loginCfg.writeEntry("AutoLogin",autoLoginName); | ||
401 | } else { | ||
402 | loginCfg.removeEntry("AutoLogin"); | ||
403 | } | ||
404 | |||
405 | } | ||
406 | |||
407 | /// slot used to record the fact plugins order has been modified | ||
408 | void MultiauthConfig::pluginsChanged() { | ||
409 | m_plugins_changed = true; | ||
410 | } | ||
411 | |||
412 | /// loads each multiauth plugin | ||
413 | void MultiauthConfig::loadPlugins() { | ||
414 | |||
415 | odebug << "loading plugins..." << oendl; | ||
416 | QString path = QPEApplication::qpeDir() + "/plugins/security"; | ||
417 | QDir dir( path, "lib*.so" ); | ||
418 | |||
419 | QStringList list = dir.entryList(); | ||
420 | QStringList::Iterator it; | ||
421 | |||
422 | // temporary list used to sort plugins | ||
423 | QMap<QString, MultiauthPlugin> sortList; | ||
424 | |||
425 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
426 | QInterfacePtr<MultiauthPluginInterface> iface; | ||
427 | QLibrary *lib = new QLibrary( path + "/" + *it ); | ||
428 | QString libPath(path + "/" + *it); | ||
429 | odebug << "library path: " << libPath << oendl; | ||
430 | |||
431 | odebug << "querying: " << QString( path + "/" + *it ) << oendl; | ||
432 | if ( lib->queryInterface( IID_MultiauthPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { | ||
433 | odebug << "accepted: " << QString( path + "/" + *it ) << oendl; | ||
434 | |||
435 | MultiauthPlugin plugin; | ||
436 | plugin.library = lib; | ||
437 | plugin.iface = iface; | ||
438 | plugin.name = QString(*it); | ||
439 | |||
440 | // find out if plugins should be launched | ||
441 | if ( m_excludePlugins.grep( *it ).isEmpty() ) { | ||
442 | plugin.active = true; | ||
443 | } else { | ||
444 | plugin.active = false; | ||
445 | } | ||
446 | |||
447 | plugin.pluginObject = plugin.iface->plugin(); | ||
448 | |||
449 | // "prebuffer" it in one more list, to get the sorting done | ||
450 | sortList.insert( plugin.name, plugin ); | ||
451 | |||
452 | // on first start the list is off course empty | ||
453 | if ( m_allPlugins.isEmpty() ) { | ||
454 | pluginList.append( plugin ); | ||
455 | } | ||
456 | // if plugin is not yet in the list, add it to the layout too | ||
457 | else if ( !m_allPlugins.contains( plugin.name ) ) { | ||
458 | pluginList.append( plugin ); | ||
459 | } | ||
460 | |||
461 | } else { | ||
462 | odebug << "could not recognize " << QString( path + "/" + *it ) << oendl; | ||
463 | delete lib; | ||
464 | } | ||
465 | |||
466 | } // end for | ||
467 | |||
468 | // put m_allPlugins tempPlugin objects into pluginList | ||
469 | if ( !m_allPlugins.isEmpty() ) { | ||
470 | MultiauthPlugin tempPlugin; | ||
471 | QStringList::Iterator stringit; | ||
472 | for( stringit = m_allPlugins.begin(); stringit != m_allPlugins.end(); ++stringit ) { | ||
473 | tempPlugin = ( sortList.find( *stringit ) ).data(); | ||
474 | if ( !( (tempPlugin.name).isEmpty() ) ) { | ||
475 | pluginList.append( tempPlugin ); | ||
476 | } | ||
477 | } | ||
478 | } | ||
479 | |||
480 | } | ||
481 | |||
482 | void MultiauthConfig::deleteListEntry() | ||
483 | { | ||
484 | m_syncWidget->syncnet->removeItem(m_syncWidget->syncnet->currentItem()); | ||
485 | } | ||
486 | |||
487 | void MultiauthConfig::restoreDefaults() | ||
488 | { | ||
489 | QMessageBox unrecbox( | ||
490 | tr("Attention"), | ||
491 | tr( "<p>All user-defined net ranges will be lost."), | ||
492 | QMessageBox::Warning, | ||
493 | QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, | ||
494 | 0, QString::null, TRUE, WStyle_StaysOnTop); | ||
495 | unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel")); | ||
496 | unrecbox.setButtonText(QMessageBox::Yes, tr("Ok")); | ||
497 | |||
498 | if ( unrecbox.exec() == QMessageBox::Yes) | ||
499 | { | ||
500 | m_syncWidget->syncnet->clear(); | ||
501 | insertDefaultRanges(); | ||
502 | } | ||
503 | m_syncWidget->syncModeCombo->setCurrentItem( 2 ); | ||
504 | } | ||
505 | |||
506 | void MultiauthConfig::insertDefaultRanges() | ||
507 | { | ||
508 | m_syncWidget->syncnet->insertItem( tr( "192.168.129.0/24" ) ); | ||
509 | m_syncWidget->syncnet->insertItem( tr( "192.168.1.0/24" ) ); | ||
510 | m_syncWidget->syncnet->insertItem( tr( "192.168.0.0/16" ) ); | ||
511 | m_syncWidget->syncnet->insertItem( tr( "172.16.0.0/12" ) ); | ||
512 | m_syncWidget->syncnet->insertItem( tr( "10.0.0.0/8" ) ); | ||
513 | m_syncWidget->syncnet->insertItem( tr( "1.0.0.0/8" ) ); | ||
514 | m_syncWidget->syncnet->insertItem( tr( "Any" ) ); | ||
515 | m_syncWidget->syncnet->insertItem( tr( "None" ) ); | ||
516 | } | ||
517 | |||
518 | void MultiauthConfig::updateGUI() | ||
519 | { | ||
520 | m_loginWidget->autologinToggle->setChecked(autoLogin); | ||
521 | m_loginWidget->userlist->setEnabled(autoLogin); | ||
522 | } | ||
523 | |||
524 | void MultiauthConfig::selectNet(int auth_peer,int auth_peer_bits, bool update) | ||
525 | { | ||
526 | QString sn; | ||
527 | if ( auth_peer_bits == 0 && auth_peer == 0 ) { | ||
528 | sn = tr("Any"); | ||
529 | } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { | ||
530 | sn = tr("None"); | ||
531 | } else { | ||
532 | sn = | ||
533 | QString::number((auth_peer>>24)&0xff) + "." | ||
534 | + QString::number((auth_peer>>16)&0xff) + "." | ||
535 | + QString::number((auth_peer>>8)&0xff) + "." | ||
536 | + QString::number((auth_peer>>0)&0xff) + "/" | ||
537 | + QString::number(auth_peer_bits); | ||
538 | } | ||
539 | |||
540 | //insert user-defined list of netranges upon start | ||
541 | if (update) { | ||
542 | //User selected/active netrange first | ||
543 | m_syncWidget->syncnet->insertItem( tr(sn) ); | ||
544 | Config cfg("Security"); | ||
545 | cfg.setGroup("Sync"); | ||
546 | |||
547 | //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe | ||
548 | QString test = cfg.readEntry("net0",""); | ||
549 | if (test.isEmpty()) { | ||
550 | insertDefaultRanges(); | ||
551 | } else { | ||
552 | // 10 ought to be enough for everybody... :) | ||
553 | // If you need more, don't forget to edit applySecurity() as well | ||
554 | bool already_there=FALSE; | ||
555 | for (int i=0; i<10; i++) { | ||
556 | QString target, netrange; | ||
557 | target.sprintf("net%d", i); | ||
558 | netrange = cfg.readEntry(target,""); | ||
559 | if (! netrange.isEmpty()){ | ||
560 | //make sure we have no "twin" entries | ||
561 | for (int i=0; i<m_syncWidget->syncnet->count(); i++) { | ||
562 | if ( m_syncWidget->syncnet->text(i) == netrange ) { | ||
563 | already_there=TRUE; | ||
564 | } | ||
565 | } | ||
566 | if (! already_there) { | ||
567 | m_syncWidget->syncnet->insertItem( tr( netrange ) ); | ||
568 | } else { | ||
569 | already_there=FALSE; | ||
570 | } | ||
571 | } | ||
572 | } | ||
573 | } | ||
574 | } | ||
575 | |||
576 | for (int i=0; i<m_syncWidget->syncnet->count(); i++) { | ||
577 | if ( m_syncWidget->syncnet->text(i).left(sn.length()) == sn ) { | ||
578 | m_syncWidget->syncnet->setCurrentItem(i); | ||
579 | return; | ||
580 | } | ||
581 | } | ||
582 | odebug << "No match for \"" << sn << "\"" << oendl; | ||
583 | } | ||
584 | |||
585 | void MultiauthConfig::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits) | ||
586 | { | ||
587 | auth_peer=0; | ||
588 | if ( sn == tr("Any") ) { | ||
589 | auth_peer = 0; | ||
590 | auth_peer_bits = 0; | ||
591 | } else if ( sn == tr("None") ) { | ||
592 | auth_peer = 0; | ||
593 | auth_peer_bits = 32; | ||
594 | } else { | ||
595 | int x=0; | ||
596 | for (int i=0; i<4; i++) { | ||
597 | int nx = sn.find(QChar(i==3 ? '/' : '.'),x); | ||
598 | auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt(); | ||
599 | x = nx+1; | ||
600 | } | ||
601 | uint n = (uint)sn.find(' ',x)-x; | ||
602 | auth_peer_bits = sn.mid(x,n).toInt(); | ||
603 | } | ||
604 | } | ||
605 | |||
606 | void MultiauthConfig::loadUsers() | ||
607 | { | ||
608 | QFile passwd("/etc/passwd"); | ||
609 | if ( passwd.open(IO_ReadOnly) ) { | ||
610 | QTextStream t( &passwd ); | ||
611 | QString s; | ||
612 | QStringList account; | ||
613 | while ( !t.eof() ) { | ||
614 | account = QStringList::split(':',t.readLine()); | ||
615 | // Hide disabled accounts and some special accounts | ||
616 | if (*account.at(1)!="*" && *account.at(0)!="ppp" && *account.at(0)!="messagebus") { | ||
617 | |||
618 | m_loginWidget->userlist->insertItem(*account.at(0)); | ||
619 | // Highlight this item if it is set to m_loginWidget->autologinToggle | ||
620 | if ( *account.at(0) == autoLoginName) | ||
621 | m_loginWidget->userlist->setCurrentItem(m_loginWidget->userlist->count()-1); | ||
622 | } | ||
623 | } | ||
624 | passwd.close(); | ||
625 | } | ||
626 | |||
627 | } | ||
628 | |||
629 | void MultiauthConfig::toggleAutoLogin(bool val) | ||
630 | { | ||
631 | autoLogin=val; | ||
632 | m_loginWidget->userlist->setEnabled(val); | ||
633 | // if autoLogin is true, we will set by default the login currently visible in the userlist | ||
634 | if (autoLogin) | ||
635 | autoLoginName=m_loginWidget->userlist->currentText(); | ||
636 | } | ||
637 | |||
638 | |||
639 | |||
640 | |||
641 | void MultiauthConfig::setSyncNet(const QString& sn) | ||
642 | { | ||
643 | int auth_peer,auth_peer_bits; | ||
644 | parseNet(sn,auth_peer,auth_peer_bits); | ||
645 | selectNet(auth_peer,auth_peer_bits,FALSE); | ||
646 | } | ||
647 | |||
648 | void MultiauthConfig::changeLoginName( int idx ) | ||
649 | { | ||
650 | autoLoginName = m_loginWidget->userlist->text(idx);; | ||
651 | updateGUI(); | ||
652 | } | ||
653 | |||
654 | /// \todo do implement that? who? how? | ||
655 | bool MultiauthConfig::telnetAvailable() const | ||
656 | { | ||
657 | return FALSE; | ||
658 | } | ||
659 | |||
660 | /// \todo do implement that? who? how? | ||
661 | bool MultiauthConfig::sshAvailable() const | ||
662 | { | ||
663 | return FALSE; | ||
664 | } | ||
665 | |||