summaryrefslogtreecommitdiff
path: root/core/settings/security/security.cpp
Unidiff
Diffstat (limited to 'core/settings/security/security.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/security/security.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/core/settings/security/security.cpp b/core/settings/security/security.cpp
index 4eddb55..b917aea 100644
--- a/core/settings/security/security.cpp
+++ b/core/settings/security/security.cpp
@@ -1,58 +1,64 @@
1/********************************************************************** 1/**********************************************************************
2 ** Copyright (C) 2000 Trolltech AS. All rights reserved. 2 ** Copyright (C) 2000 Trolltech AS. All rights reserved.
3 ** 3 **
4 ** This file is part of Qtopia Environment. 4 ** This file is part of Qtopia Environment.
5 ** 5 **
6 ** This file may be distributed and/or modified under the terms of the 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 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 8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file. 9 ** packaging of this file.
10 ** 10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ** 13 **
14 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 14 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
15 ** 15 **
16 ** Contact info@trolltech.com if any conditions of this licensing are 16 ** Contact info@trolltech.com if any conditions of this licensing are
17 ** not clear to you. 17 ** not clear to you.
18 ** 18 **
19 **********************************************************************/ 19 **********************************************************************/
20#include "security.h" 20#include "security.h"
21 21
22/* OPIE */
22#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
23#include <qpe/config.h> 24#include <qpe/config.h>
24#include <qpe/password.h> 25#include <qpe/password.h>
25#include <qpe/qpedialog.h> 26#include <qpe/qpedialog.h>
26#include <qpe/qcopenvelope_qws.h> 27#include <qpe/qcopenvelope_qws.h>
28#include <opie2/odebug.h>
27 29
30/* QT */
28#include <qcheckbox.h> 31#include <qcheckbox.h>
29#include <qpushbutton.h> 32#include <qpushbutton.h>
30#include <qcombobox.h> 33#include <qcombobox.h>
31#include <qmessagebox.h> 34#include <qmessagebox.h>
32#include <qfile.h> 35#include <qfile.h>
33#include <qtextstream.h> 36#include <qtextstream.h>
34 37
38
39using namespace Opie::Core;
40
35 Security::Security( QWidget* parent, const char* name, WFlags fl ) 41 Security::Security( QWidget* parent, const char* name, WFlags fl )
36: SecurityBase( parent, name, TRUE, WStyle_ContextHelp ) 42: SecurityBase( parent, name, TRUE, WStyle_ContextHelp )
37{ 43{
38 valid=FALSE; 44 valid=FALSE;
39 Config cfg("Security"); 45 Config cfg("Security");
40 cfg.setGroup("Passcode"); 46 cfg.setGroup("Passcode");
41 passcode = cfg.readEntry("passcode"); 47 passcode = cfg.readEntry("passcode");
42 passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE)); 48 passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE));
43 cfg.setGroup("Sync"); 49 cfg.setGroup("Sync");
44 int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 50 int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24
45 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 51 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
46 selectNet(auth_peer,auth_peer_bits,TRUE); 52 selectNet(auth_peer,auth_peer_bits,TRUE);
47 53
48 connect(syncnet, SIGNAL(textChanged(const QString&)), 54 connect(syncnet, SIGNAL(textChanged(const QString&)),
49 this, SLOT(setSyncNet(const QString&))); 55 this, SLOT(setSyncNet(const QString&)));
50 56
51 57
52 58
53 /* 59 /*
54 cfg.setGroup("Remote"); 60 cfg.setGroup("Remote");
55 if ( telnetAvailable() ) 61 if ( telnetAvailable() )
56 telnet->setChecked(cfg.readEntry("allow_telnet")); 62 telnet->setChecked(cfg.readEntry("allow_telnet"));
57 else 63 else
58 telnet->hide(); 64 telnet->hide();
@@ -97,49 +103,49 @@
97 connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode())); 103 connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode()));
98 connect(restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults())); 104 connect(restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults()));
99 connect(deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry())); 105 connect(deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry()));
100 106
101 loadUsers(); 107 loadUsers();
102 updateGUI(); 108 updateGUI();
103 109
104 dl = new QPEDialogListener(this); 110 dl = new QPEDialogListener(this);
105 QPEApplication::showDialog( this ); 111 QPEApplication::showDialog( this );
106} 112}
107 113
108Security::~Security() 114Security::~Security()
109{ 115{
110} 116}
111 117
112void Security::deleteListEntry() 118void Security::deleteListEntry()
113{ 119{
114 syncnet->removeItem(syncnet->currentItem()); 120 syncnet->removeItem(syncnet->currentItem());
115} 121}
116 122
117void Security::restoreDefaults() 123void Security::restoreDefaults()
118{ 124{
119 QMessageBox unrecbox( 125 QMessageBox unrecbox(
120 tr("Attention"), 126 tr("Attention"),
121 tr("<p>All user-defined net ranges will be lost."), 127 tr( "<p>All user-defined net ranges will be lost."),
122 QMessageBox::Warning, 128 QMessageBox::Warning,
123 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 129 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
124 0, QString::null, TRUE, WStyle_StaysOnTop); 130 0, QString::null, TRUE, WStyle_StaysOnTop);
125 unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel")); 131 unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
126 unrecbox.setButtonText(QMessageBox::Yes, tr("Ok")); 132 unrecbox.setButtonText(QMessageBox::Yes, tr("Ok"));
127 133
128 if ( unrecbox.exec() == QMessageBox::Yes) 134 if ( unrecbox.exec() == QMessageBox::Yes)
129 { 135 {
130 syncnet->clear(); 136 syncnet->clear();
131 insertDefaultRanges(); 137 insertDefaultRanges();
132 } 138 }
133 syncModeCombo->setCurrentItem( 2 ); 139 syncModeCombo->setCurrentItem( 2 );
134} 140}
135 141
136void Security::insertDefaultRanges() 142void Security::insertDefaultRanges()
137{ 143{
138 syncnet->insertItem( tr( "192.168.129.0/24" ) ); 144 syncnet->insertItem( tr( "192.168.129.0/24" ) );
139 syncnet->insertItem( tr( "192.168.1.0/24" ) ); 145 syncnet->insertItem( tr( "192.168.1.0/24" ) );
140 syncnet->insertItem( tr( "192.168.0.0/16" ) ); 146 syncnet->insertItem( tr( "192.168.0.0/16" ) );
141 syncnet->insertItem( tr( "172.16.0.0/12" ) ); 147 syncnet->insertItem( tr( "172.16.0.0/12" ) );
142 syncnet->insertItem( tr( "10.0.0.0/8" ) ); 148 syncnet->insertItem( tr( "10.0.0.0/8" ) );
143 syncnet->insertItem( tr( "1.0.0.0/8" ) ); 149 syncnet->insertItem( tr( "1.0.0.0/8" ) );
144 syncnet->insertItem( tr( "Any" ) ); 150 syncnet->insertItem( tr( "Any" ) );
145 syncnet->insertItem( tr( "None" ) ); 151 syncnet->insertItem( tr( "None" ) );
@@ -149,136 +155,136 @@ void Security::updateGUI()
149{ 155{
150 bool empty = passcode.isEmpty(); 156 bool empty = passcode.isEmpty();
151 157
152 changepasscode->setText( empty ? tr("Set passcode" ) 158 changepasscode->setText( empty ? tr("Set passcode" )
153 : tr("Change passcode" ) ); 159 : tr("Change passcode" ) );
154 passcode_poweron->setEnabled( !empty ); 160 passcode_poweron->setEnabled( !empty );
155 clearpasscode->setEnabled( !empty ); 161 clearpasscode->setEnabled( !empty );
156 162
157 autologinToggle->setChecked(autoLogin); 163 autologinToggle->setChecked(autoLogin);
158 userlist->setEnabled(autoLogin); 164 userlist->setEnabled(autoLogin);
159} 165}
160 166
161 167
162void Security::show() 168void Security::show()
163{ 169{
164 //valid=FALSE; 170 //valid=FALSE;
165 setEnabled(FALSE); 171 setEnabled(FALSE);
166 SecurityBase::show(); 172 SecurityBase::show();
167 if ( passcode.isEmpty() ) { 173 if ( passcode.isEmpty() ) {
168 // could insist... 174 // could insist...
169 //changePassCode(); 175 //changePassCode();
170 //if ( passcode.isEmpty() ) 176 //if ( passcode.isEmpty() )
171 //reject(); 177 //reject();
172 } else { 178 } else {
173 if (!valid) // security passcode was not asked yet, so ask now 179 if (!valid) // security passcode was not asked yet, so ask now
174 { 180 {
175 QString pc = enterPassCode(tr("Enter passcode")); 181 QString pc = enterPassCode(tr("Enter passcode"));
176 if ( pc != passcode ) { 182 if ( pc != passcode ) {
177 QMessageBox::critical(this, tr("Passcode incorrect"), 183 QMessageBox::critical(this, tr("Passcode incorrect"),
178 tr("The passcode entered is incorrect.\nAccess denied")); 184 tr("The passcode entered is incorrect.\nAccess denied"));
179 reject(); 185 reject();
180 return; 186 return;
181 } 187 }
182 } 188 }
183 } 189 }
184 setEnabled(TRUE); 190 setEnabled(TRUE);
185 valid=TRUE; 191 valid=TRUE;
186} 192}
187 193
188void Security::accept() 194void Security::accept()
189{ 195{
190 applySecurity(); 196 applySecurity();
191 QDialog::accept(); 197 QDialog::accept();
192 QCopEnvelope env("QPE/System", "securityChanged()" ); 198 QCopEnvelope env("QPE/System", "securityChanged()" );
193} 199}
194 200
195void Security::done(int r) 201void Security::done(int r)
196{ 202{
197 QDialog::done(r); 203 QDialog::done(r);
198 close(); 204 close();
199} 205}
200 206
201void Security::selectNet(int auth_peer,int auth_peer_bits, bool update) 207void Security::selectNet(int auth_peer,int auth_peer_bits, bool update)
202{ 208{
203 QString sn; 209 QString sn;
204 if ( auth_peer_bits == 0 && auth_peer == 0 ) { 210 if ( auth_peer_bits == 0 && auth_peer == 0 ) {
205 sn = tr("Any"); 211 sn = tr("Any");
206 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { 212 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) {
207 sn = tr("None"); 213 sn = tr("None");
208 } else { 214 } else {
209 sn = 215 sn =
210 QString::number((auth_peer>>24)&0xff) + "." 216 QString::number((auth_peer>>24)&0xff) + "."
211 + QString::number((auth_peer>>16)&0xff) + "." 217 + QString::number((auth_peer>>16)&0xff) + "."
212 + QString::number((auth_peer>>8)&0xff) + "." 218 + QString::number((auth_peer>>8)&0xff) + "."
213 + QString::number((auth_peer>>0)&0xff) + "/" 219 + QString::number((auth_peer>>0)&0xff) + "/"
214 + QString::number(auth_peer_bits); 220 + QString::number(auth_peer_bits);
215 } 221 }
216 222
217 //insert user-defined list of netranges upon start 223 //insert user-defined list of netranges upon start
218 if (update) { 224 if (update) {
219 //User selected/active netrange first 225 //User selected/active netrange first
220 syncnet->insertItem( tr( sn ) ); 226 syncnet->insertItem( tr( sn ) );
221 227
222 Config cfg("Security"); 228 Config cfg("Security");
223 cfg.setGroup("Sync"); 229 cfg.setGroup("Sync");
224 230
225 //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe 231 //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe
226 QString test = cfg.readEntry("net0",""); 232 QString test = cfg.readEntry("net0","");
227 if (test.isEmpty()) { 233 if (test.isEmpty()) {
228 insertDefaultRanges(); 234 insertDefaultRanges();
229 } else { 235 } else {
230 // 10 ought to be enough for everybody... :) 236 // 10 ought to be enough for everybody... :)
231 // If you need more, don't forget to edit applySecurity() as well 237 // If you need more, don't forget to edit applySecurity() as well
232 bool already_there=FALSE; 238 bool already_there=FALSE;
233 for (int i=0; i<10; i++) { 239 for (int i=0; i<10; i++) {
234 QString target, netrange; 240 QString target, netrange;
235 target.sprintf("net%d", i); 241 target.sprintf("net%d", i);
236 netrange = cfg.readEntry(target,""); 242 netrange = cfg.readEntry(target,"");
237 if (! netrange.isEmpty()){ 243 if (! netrange.isEmpty()){
238 //make sure we have no "twin" entries 244 //make sure we have no "twin" entries
239 for (int i=0; i<syncnet->count(); i++) { 245 for (int i=0; i<syncnet->count(); i++) {
240 if ( syncnet->text(i) == netrange ) { 246 if ( syncnet->text(i) == netrange ) {
241 already_there=TRUE; 247 already_there=TRUE;
242 } 248 }
243 } 249 }
244 if (! already_there) { 250 if (! already_there) {
245 syncnet->insertItem( tr( netrange ) ); 251 syncnet->insertItem( tr( netrange ) );
246 } else { 252 } else {
247 already_there=FALSE; 253 already_there=FALSE;
248 } 254 }
249 } 255 }
250 } 256 }
251 } 257 }
252 } 258 }
253 259
254 for (int i=0; i<syncnet->count(); i++) { 260 for (int i=0; i<syncnet->count(); i++) {
255 if ( syncnet->text(i).left(sn.length()) == sn ) { 261 if ( syncnet->text(i).left(sn.length()) == sn ) {
256 syncnet->setCurrentItem(i); 262 syncnet->setCurrentItem(i);
257 return; 263 return;
258 } 264 }
259 } 265 }
260 qDebug("No match for \"%s\"",sn.latin1()); 266 odebug << "No match for \"" << sn << "\"" << oendl;
261} 267}
262 268
263void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits) 269void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits)
264{ 270{
265 auth_peer=0; 271 auth_peer=0;
266 if ( sn == tr("Any") ) { 272 if ( sn == tr("Any") ) {
267 auth_peer = 0; 273 auth_peer = 0;
268 auth_peer_bits = 0; 274 auth_peer_bits = 0;
269 } else if ( sn == tr("None") ) { 275 } else if ( sn == tr("None") ) {
270 auth_peer = 0; 276 auth_peer = 0;
271 auth_peer_bits = 32; 277 auth_peer_bits = 32;
272 } else { 278 } else {
273 int x=0; 279 int x=0;
274 for (int i=0; i<4; i++) { 280 for (int i=0; i<4; i++) {
275 int nx = sn.find(QChar(i==3 ? '/' : '.'),x); 281 int nx = sn.find(QChar(i==3 ? '/' : '.'),x);
276 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt(); 282 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt();
277 x = nx+1; 283 x = nx+1;
278 } 284 }
279 uint n = (uint)sn.find(' ',x)-x; 285 uint n = (uint)sn.find(' ',x)-x;
280 auth_peer_bits = sn.mid(x,n).toInt(); 286 auth_peer_bits = sn.mid(x,n).toInt();
281 } 287 }
282} 288}
283 289
284void Security::loadUsers ( void ) 290void Security::loadUsers ( void )
@@ -319,54 +325,54 @@ void Security::toggleAutoLogin(bool val)
319void Security::setSyncNet(const QString& sn) 325void Security::setSyncNet(const QString& sn)
320{ 326{
321 int auth_peer,auth_peer_bits; 327 int auth_peer,auth_peer_bits;
322 parseNet(sn,auth_peer,auth_peer_bits); 328 parseNet(sn,auth_peer,auth_peer_bits);
323 selectNet(auth_peer,auth_peer_bits,FALSE); 329 selectNet(auth_peer,auth_peer_bits,FALSE);
324} 330}
325 331
326void Security::applySecurity() 332void Security::applySecurity()
327{ 333{
328 if ( valid ) { 334 if ( valid ) {
329 Config cfg("Security"); 335 Config cfg("Security");
330 cfg.setGroup("Passcode"); 336 cfg.setGroup("Passcode");
331 cfg.writeEntry("passcode",passcode); 337 cfg.writeEntry("passcode",passcode);
332 cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked()); 338 cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked());
333 cfg.setGroup("Sync"); 339 cfg.setGroup("Sync");
334 int auth_peer=0; 340 int auth_peer=0;
335 int auth_peer_bits; 341 int auth_peer_bits;
336 QString sn = syncnet->currentText(); 342 QString sn = syncnet->currentText();
337 parseNet(sn,auth_peer,auth_peer_bits); 343 parseNet(sn,auth_peer,auth_peer_bits);
338 344
339 //this is the *selected* (active) net range 345 //this is the *selected* (active) net range
340 cfg.writeEntry("auth_peer",auth_peer); 346 cfg.writeEntry("auth_peer",auth_peer);
341 cfg.writeEntry("auth_peer_bits",auth_peer_bits); 347 cfg.writeEntry("auth_peer_bits",auth_peer_bits);
342 348
343 //write back all other net ranges in *cleartext* 349 //write back all other net ranges in *cleartext*
344 for (int i=0; i<10; i++) { 350 for (int i=0; i<10; i++) {
345 QString target; 351 QString target;
346 target.sprintf("net%d", i); 352 target.sprintf("net%d", i);
347 cfg.writeEntry(target,syncnet->text(i)); 353 cfg.writeEntry(target,syncnet->text(i));
348 } 354 }
349 355
350#ifdef ODP 356#ifdef ODP
351 #error "Use 0,1,2 and use Launcher" 357 #error "Use 0,1,2 and use Launcher"
352#endif 358#endif
353 /* keep the old code so we don't use currentItem directly */ 359 /* keep the old code so we don't use currentItem directly */
354 int value = 0x02; 360 int value = 0x02;
355 switch( syncModeCombo->currentItem() ) { 361 switch( syncModeCombo->currentItem() ) {
356 case 0: 362 case 0:
357 value = 0x01; 363 value = 0x01;
358 break; 364 break;
359 case 1: 365 case 1:
360 value = 0x02; 366 value = 0x02;
361 break; 367 break;
362 case 2: 368 case 2:
363 value = 0x04; 369 value = 0x04;
364 break; 370 break;
365 } 371 }
366 cfg.setGroup("SyncMode"); 372 cfg.setGroup("SyncMode");
367 cfg.writeEntry( "Mode", value ); 373 cfg.writeEntry( "Mode", value );
368 374
369 /* 375 /*
370 cfg.setGroup("Remote"); 376 cfg.setGroup("Remote");
371 if ( telnetAvailable() ) 377 if ( telnetAvailable() )
372 cfg.writeEntry("allow_telnet",telnet->isChecked()); 378 cfg.writeEntry("allow_telnet",telnet->isChecked());