summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/security/security.cpp446
-rw-r--r--core/settings/security/security.h74
2 files changed, 0 insertions, 520 deletions
diff --git a/core/settings/security/security.cpp b/core/settings/security/security.cpp
deleted file mode 100644
index 122dfae..0000000
--- a/core/settings/security/security.cpp
+++ b/dev/null
@@ -1,446 +0,0 @@
1/**********************************************************************
2 ** Copyright (C) 2000 Trolltech AS. All rights reserved.
3 **
4 ** This file is part of Qtopia Environment.
5 **
6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
15 **
16 ** Contact info@trolltech.com if any conditions of this licensing are
17 ** not clear to you.
18 **
19 **********************************************************************/
20#include "security.h"
21
22/* OPIE */
23#include <qpe/qpeapplication.h>
24#include <qpe/config.h>
25#include <qpe/password.h>
26#include <qpe/qpedialog.h>
27#include <qpe/qcopenvelope_qws.h>
28#include <opie2/odebug.h>
29
30/* QT */
31#include <qcheckbox.h>
32#include <qpushbutton.h>
33#include <qcombobox.h>
34#include <qmessagebox.h>
35#include <qfile.h>
36#include <qtextstream.h>
37
38
39using namespace Opie::Core;
40
41 Security::Security( QWidget* parent, const char* name, WFlags fl )
42: SecurityBase( parent, name, TRUE, WStyle_ContextHelp )
43{
44 valid=FALSE;
45 Config cfg("Security");
46 cfg.setGroup("Passcode");
47 passcode = cfg.readEntry("passcode");
48 passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE));
49 cfg.setGroup("Sync");
50 int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24
51 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
52 selectNet(auth_peer,auth_peer_bits,TRUE);
53
54 connect(syncnet, SIGNAL(textChanged(const QString&)),
55 this, SLOT(setSyncNet(const QString&)));
56
57
58
59 /*
60 cfg.setGroup("Remote");
61 if ( telnetAvailable() )
62 telnet->setChecked(cfg.readEntry("allow_telnet"));
63 else
64 telnet->hide();
65
66 if ( sshAvailable() )
67 ssh->setChecked(cfg.readEntry("allow_ssh"));
68 else
69 ssh->hide();
70 */
71
72 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf";
73 Config loginCfg(configFile,Config::File);
74
75 loginCfg.setGroup("General");
76 autoLoginName=loginCfg.readEntry("AutoLogin","");
77
78 if (autoLoginName.stripWhiteSpace().isEmpty()) {
79 autoLogin=false;
80 } else {
81 autoLogin=true;
82 }
83
84 cfg.setGroup("SyncMode");
85 int mode = cfg.readNumEntry("Mode",2); // Default to Sharp
86 switch( mode ) {
87 case 0x01:
88 syncModeCombo->setCurrentItem( 0 );
89 break;
90 case 0x02:
91 default:
92 syncModeCombo->setCurrentItem( 1 );
93 break;
94 case 0x04:
95 syncModeCombo->setCurrentItem( 2 );
96 break;
97 }
98
99
100 connect(autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool)));
101 connect(userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int)));
102 connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode()));
103 connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode()));
104 connect(restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults()));
105 connect(deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry()));
106
107 loadUsers();
108 updateGUI();
109
110 dl = new QPEDialogListener(this);
111 QPEApplication::showDialog( this );
112}
113
114Security::~Security()
115{
116}
117
118void Security::deleteListEntry()
119{
120 syncnet->removeItem(syncnet->currentItem());
121}
122
123void Security::restoreDefaults()
124{
125 QMessageBox unrecbox(
126 tr("Attention"),
127 "<p>" + tr("All user-defined net ranges will be lost.") + "</p>",
128 QMessageBox::Warning,
129 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
130 0, QString::null, TRUE, WStyle_StaysOnTop);
131 unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
132 unrecbox.setButtonText(QMessageBox::Yes, tr("Ok"));
133
134 if ( unrecbox.exec() == QMessageBox::Yes)
135 {
136 syncnet->clear();
137 insertDefaultRanges();
138 }
139 syncModeCombo->setCurrentItem( 2 );
140}
141
142void Security::insertDefaultRanges()
143{
144 syncnet->insertItem( "192.168.129.0/24" );
145 syncnet->insertItem( "192.168.1.0/24" );
146 syncnet->insertItem( "192.168.0.0/16" );
147 syncnet->insertItem( "172.16.0.0/12" );
148 syncnet->insertItem( "10.0.0.0/8" );
149 syncnet->insertItem( "1.0.0.0/8" );
150 syncnet->insertItem( tr( "Any" ) );
151 syncnet->insertItem( tr( "None" ) );
152}
153
154void Security::updateGUI()
155{
156 bool empty = passcode.isEmpty();
157
158 changepasscode->setText( empty ? tr("Set passcode" )
159 : tr("Change passcode" ) );
160 passcode_poweron->setEnabled( !empty );
161 clearpasscode->setEnabled( !empty );
162
163 autologinToggle->setChecked(autoLogin);
164 userlist->setEnabled(autoLogin);
165}
166
167
168void Security::show()
169{
170 //valid=FALSE;
171 setEnabled(FALSE);
172 SecurityBase::show();
173 if ( passcode.isEmpty() ) {
174 // could insist...
175 //changePassCode();
176 //if ( passcode.isEmpty() )
177 //reject();
178 } else {
179 if (!valid) // security passcode was not asked yet, so ask now
180 {
181 QString pc = enterPassCode(tr("Enter passcode"));
182 if ( pc != passcode ) {
183 QMessageBox::critical(this, tr("Passcode incorrect"),
184 tr("The passcode entered is incorrect.\nAccess denied"));
185 reject();
186 return;
187 }
188 }
189 }
190 setEnabled(TRUE);
191 valid=TRUE;
192}
193
194void Security::accept()
195{
196 applySecurity();
197 QDialog::accept();
198 QCopEnvelope env("QPE/System", "securityChanged()" );
199}
200
201void Security::done(int r)
202{
203 QDialog::done(r);
204 close();
205}
206
207void Security::selectNet(int auth_peer,int auth_peer_bits, bool update)
208{
209 QString sn;
210 if ( auth_peer_bits == 0 && auth_peer == 0 ) {
211 sn = tr("Any");
212 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) {
213 sn = tr("None");
214 } else {
215 sn =
216 QString::number((auth_peer>>24)&0xff) + "."
217 + QString::number((auth_peer>>16)&0xff) + "."
218 + QString::number((auth_peer>>8)&0xff) + "."
219 + QString::number((auth_peer>>0)&0xff) + "/"
220 + QString::number(auth_peer_bits);
221 }
222
223 //insert user-defined list of netranges upon start
224 if (update) {
225 //User selected/active netrange first
226 syncnet->insertItem( sn );
227
228 Config cfg("Security");
229 cfg.setGroup("Sync");
230
231 //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe
232 QString test = cfg.readEntry("net0","");
233 if (test.isEmpty()) {
234 insertDefaultRanges();
235 } else {
236 // 10 ought to be enough for everybody... :)
237 // If you need more, don't forget to edit applySecurity() as well
238 bool already_there=FALSE;
239 for (int i=0; i<10; i++) {
240 QString target, netrange;
241 target.sprintf("net%d", i);
242 netrange = cfg.readEntry(target,"");
243 if (! netrange.isEmpty()){
244 //make sure we have no "twin" entries
245 for (int i=0; i<syncnet->count(); i++) {
246 if ( syncnet->text(i) == netrange ) {
247 already_there=TRUE;
248 }
249 }
250 if (! already_there) {
251 syncnet->insertItem( netrange );
252 } else {
253 already_there=FALSE;
254 }
255 }
256 }
257 }
258 }
259
260 for (int i=0; i<syncnet->count(); i++) {
261 if ( syncnet->text(i).left(sn.length()) == sn ) {
262 syncnet->setCurrentItem(i);
263 return;
264 }
265 }
266 odebug << "No match for \"" << sn << "\"" << oendl;
267}
268
269void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits)
270{
271 auth_peer=0;
272 if ( sn == tr("Any") ) {
273 auth_peer = 0;
274 auth_peer_bits = 0;
275 } else if ( sn == tr("None") ) {
276 auth_peer = 0;
277 auth_peer_bits = 32;
278 } else {
279 int x=0;
280 for (int i=0; i<4; i++) {
281 int nx = sn.find(QChar(i==3 ? '/' : '.'),x);
282 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt();
283 x = nx+1;
284 }
285 uint n = (uint)sn.find(' ',x)-x;
286 auth_peer_bits = sn.mid(x,n).toInt();
287 }
288}
289
290void Security::loadUsers ( void )
291{
292 QFile passwd("/etc/passwd");
293 if ( passwd.open(IO_ReadOnly) ) {
294 QTextStream t( &passwd );
295 QString s;
296 QStringList account;
297 while ( !t.eof() ) {
298 account = QStringList::split(':',t.readLine());
299
300 // Hide disabled accounts
301 if (*account.at(1)!="*") {
302
303 userlist->insertItem(*account.at(0));
304 // Highlight this item if it is set to autologinToggle
305 if ( *account.at(0) == autoLoginName)
306 userlist->setCurrentItem(userlist->count()-1);
307 }
308 }
309 passwd.close();
310 }
311
312}
313
314void Security::toggleAutoLogin(bool val)
315{
316 autoLogin=val;
317 userlist->setEnabled(val);
318 if (!autoLogin)
319 autoLoginName=userlist->currentText();
320}
321
322
323
324
325void Security::setSyncNet(const QString& sn)
326{
327 int auth_peer,auth_peer_bits;
328 parseNet(sn,auth_peer,auth_peer_bits);
329 selectNet(auth_peer,auth_peer_bits,FALSE);
330}
331
332void Security::applySecurity()
333{
334 if ( valid ) {
335 Config cfg("Security");
336 cfg.setGroup("Passcode");
337 cfg.writeEntry("passcode",passcode);
338 cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked());
339 cfg.setGroup("Sync");
340 int auth_peer=0;
341 int auth_peer_bits;
342 QString sn = syncnet->currentText();
343 parseNet(sn,auth_peer,auth_peer_bits);
344
345 //this is the *selected* (active) net range
346 cfg.writeEntry("auth_peer",auth_peer);
347 cfg.writeEntry("auth_peer_bits",auth_peer_bits);
348
349 //write back all other net ranges in *cleartext*
350 for (int i=0; i<10; i++) {
351 QString target;
352 target.sprintf("net%d", i);
353 cfg.writeEntry(target,syncnet->text(i));
354 }
355
356#ifdef ODP
357 #error "Use 0,1,2 and use Launcher"
358#endif
359 /* keep the old code so we don't use currentItem directly */
360 int value = 0x02;
361 switch( syncModeCombo->currentItem() ) {
362 case 0:
363 value = 0x01;
364 break;
365 case 1:
366 value = 0x02;
367 break;
368 case 2:
369 value = 0x04;
370 break;
371 }
372 cfg.setGroup("SyncMode");
373 cfg.writeEntry( "Mode", value );
374
375 /*
376 cfg.setGroup("Remote");
377 if ( telnetAvailable() )
378 cfg.writeEntry("allow_telnet",telnet->isChecked());
379 if ( sshAvailable() )
380 cfg.writeEntry("allow_ssh",ssh->isChecked());
381 // ### write ssh/telnet sys config files
382 */
383
384 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf";
385 Config loginCfg(configFile,Config::File);
386 loginCfg.setGroup("General");
387
388 if (autoLogin) {
389 loginCfg.writeEntry("AutoLogin",autoLoginName);
390 } else {
391 loginCfg.removeEntry("AutoLogin");
392 }
393
394 }
395}
396
397
398
399
400void Security::changeLoginName( int idx )
401{
402 autoLoginName = userlist->text(idx);;
403 updateGUI();
404}
405
406void Security::changePassCode()
407{
408 QString new1;
409 QString new2;
410
411 do {
412 new1 = enterPassCode(tr("Enter new passcode"));
413 if ( new1.isNull() )
414 return;
415 new2 = enterPassCode(tr("Re-enter new passcode"));
416 if ( new2.isNull() )
417 return;
418 } while (new1 != new2);
419
420 passcode = new1;
421 updateGUI();
422}
423
424void Security::clearPassCode()
425{
426 passcode = QString::null;
427 updateGUI();
428}
429
430
431QString Security::enterPassCode(const QString& prompt)
432{
433 return Password::getPassword(prompt);
434}
435
436bool Security::telnetAvailable() const
437{
438 // ### not implemented
439 return FALSE;
440}
441
442bool Security::sshAvailable() const
443{
444 // ### not implemented
445 return FALSE;
446}
diff --git a/core/settings/security/security.h b/core/settings/security/security.h
deleted file mode 100644
index ed25ce1..0000000
--- a/core/settings/security/security.h
+++ b/dev/null
@@ -1,74 +0,0 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SECURITY_H
21#define SECURITY_H
22
23#include "securitybase.h"
24
25class QPEDialogListener;
26
27class Security : public SecurityBase
28{
29 Q_OBJECT
30
31public:
32 static QString appName() { return QString::fromLatin1("security"); }
33 Security( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
34 ~Security();
35
36 void show();
37
38protected:
39 void accept();
40 void applySecurity();
41 void done(int);
42
43private slots:
44 void changePassCode();
45 void clearPassCode();
46 void setSyncNet(const QString&);
47 void changeLoginName(int);
48 void toggleAutoLogin(bool);
49 void restoreDefaults();
50 void insertDefaultRanges();
51 void deleteListEntry();
52
53private:
54 void loadUsers(void);
55 bool telnetAvailable() const;
56 bool sshAvailable() const;
57 void updateGUI();
58
59 static void parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits);
60 void selectNet(int auth_peer,int auth_peer_bits,bool update);
61
62
63 QString enterPassCode(const QString&);
64 QString passcode;
65 bool valid;
66 bool autoLogin;
67 QString autoLoginName;
68
69 QPEDialogListener *dl;
70};
71
72
73#endif // SECURITY_H
74