summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/security/security.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/core/settings/security/security.cpp b/core/settings/security/security.cpp
index 2821f4b..4701506 100644
--- a/core/settings/security/security.cpp
+++ b/core/settings/security/security.cpp
@@ -1,223 +1,224 @@
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#include <qpe/config.h> 22#include <qpe/config.h>
23#include <qpe/password.h> 23#include <qpe/password.h>
24#include <qpe/qpedialog.h> 24#include <qpe/qpedialog.h>
25 25
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qmessagebox.h> 29#include <qmessagebox.h>
30 30
31Security::Security( QWidget* parent, const char* name, WFlags fl ) 31Security::Security( QWidget* parent, const char* name, WFlags fl )
32 : SecurityBase( parent, name, TRUE, fl ) 32 : SecurityBase( parent, name, TRUE, fl )
33{ 33{
34 valid=FALSE; 34 valid=FALSE;
35 Config cfg("Security"); 35 Config cfg("Security");
36 cfg.setGroup("Passcode"); 36 cfg.setGroup("Passcode");
37 passcode = cfg.readEntry("passcode"); 37 passcode = cfg.readEntry("passcode");
38 passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE)); 38 passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE));
39 cfg.setGroup("Sync"); 39 cfg.setGroup("Sync");
40 int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 40 int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24
41 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 41 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
42 selectNet(auth_peer,auth_peer_bits); 42 selectNet(auth_peer,auth_peer_bits);
43 connect(syncnet, SIGNAL(textChanged(const QString&)), 43 connect(syncnet, SIGNAL(textChanged(const QString&)),
44 this, SLOT(setSyncNet(const QString&))); 44 this, SLOT(setSyncNet(const QString&)));
45 45
46 /* 46 /*
47 cfg.setGroup("Remote"); 47 cfg.setGroup("Remote");
48 if ( telnetAvailable() ) 48 if ( telnetAvailable() )
49 telnet->setChecked(cfg.readEntry("allow_telnet")); 49 telnet->setChecked(cfg.readEntry("allow_telnet"));
50 else 50 else
51 telnet->hide(); 51 telnet->hide();
52 52
53 if ( sshAvailable() ) 53 if ( sshAvailable() )
54 ssh->setChecked(cfg.readEntry("allow_ssh")); 54 ssh->setChecked(cfg.readEntry("allow_ssh"));
55 else 55 else
56 ssh->hide(); 56 ssh->hide();
57 */ 57 */
58 58
59 connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode())); 59 connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode()));
60 connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode())); 60 connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode()));
61 updateGUI(); 61 updateGUI();
62 62
63 dl = new QPEDialogListener(this); 63 dl = new QPEDialogListener(this);
64 showMaximized();
64} 65}
65 66
66Security::~Security() 67Security::~Security()
67{ 68{
68} 69}
69 70
70 71
71void Security::updateGUI() 72void Security::updateGUI()
72{ 73{
73 bool empty = passcode.isEmpty(); 74 bool empty = passcode.isEmpty();
74 75
75 changepasscode->setText( empty ? tr("Set passcode" ) 76 changepasscode->setText( empty ? tr("Set passcode" )
76 : tr("Change passcode" ) ); 77 : tr("Change passcode" ) );
77 passcode_poweron->setEnabled( !empty ); 78 passcode_poweron->setEnabled( !empty );
78 clearpasscode->setEnabled( !empty ); 79 clearpasscode->setEnabled( !empty );
79} 80}
80 81
81 82
82void Security::show() 83void Security::show()
83{ 84{
84 valid=FALSE; 85 valid=FALSE;
85 setEnabled(FALSE); 86 setEnabled(FALSE);
86 SecurityBase::show(); 87 SecurityBase::show();
87 if ( passcode.isEmpty() ) { 88 if ( passcode.isEmpty() ) {
88 // could insist... 89 // could insist...
89 //changePassCode(); 90 //changePassCode();
90 //if ( passcode.isEmpty() ) 91 //if ( passcode.isEmpty() )
91 //reject(); 92 //reject();
92 } else { 93 } else {
93 QString pc = enterPassCode(tr("Enter passcode")); 94 QString pc = enterPassCode(tr("Enter passcode"));
94 if ( pc != passcode ) { 95 if ( pc != passcode ) {
95 QMessageBox::critical(this, tr("Passcode incorrect"), 96 QMessageBox::critical(this, tr("Passcode incorrect"),
96 tr("The passcode entered is incorrect.\nAccess denied")); 97 tr("The passcode entered is incorrect.\nAccess denied"));
97 reject(); 98 reject();
98 return; 99 return;
99 } 100 }
100 } 101 }
101 setEnabled(TRUE); 102 setEnabled(TRUE);
102 valid=TRUE; 103 valid=TRUE;
103} 104}
104 105
105void Security::accept() 106void Security::accept()
106{ 107{
107 applySecurity(); 108 applySecurity();
108 QDialog::accept(); 109 QDialog::accept();
109} 110}
110 111
111void Security::done(int r) 112void Security::done(int r)
112{ 113{
113 QDialog::done(r); 114 QDialog::done(r);
114 close(); 115 close();
115} 116}
116 117
117void Security::selectNet(int auth_peer,int auth_peer_bits) 118void Security::selectNet(int auth_peer,int auth_peer_bits)
118{ 119{
119 QString sn; 120 QString sn;
120 if ( auth_peer_bits == 0 && auth_peer == 0 ) { 121 if ( auth_peer_bits == 0 && auth_peer == 0 ) {
121 sn = tr("Any"); 122 sn = tr("Any");
122 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { 123 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) {
123 sn = tr("None"); 124 sn = tr("None");
124 } else { 125 } else {
125 sn = 126 sn =
126 QString::number((auth_peer>>24)&0xff) + "." 127 QString::number((auth_peer>>24)&0xff) + "."
127 + QString::number((auth_peer>>16)&0xff) + "." 128 + QString::number((auth_peer>>16)&0xff) + "."
128 + QString::number((auth_peer>>8)&0xff) + "." 129 + QString::number((auth_peer>>8)&0xff) + "."
129 + QString::number((auth_peer>>0)&0xff) + "/" 130 + QString::number((auth_peer>>0)&0xff) + "/"
130 + QString::number(auth_peer_bits); 131 + QString::number(auth_peer_bits);
131 } 132 }
132 for (int i=0; i<syncnet->count(); i++) { 133 for (int i=0; i<syncnet->count(); i++) {
133 if ( syncnet->text(i).left(sn.length()) == sn ) { 134 if ( syncnet->text(i).left(sn.length()) == sn ) {
134 syncnet->setCurrentItem(i); 135 syncnet->setCurrentItem(i);
135 return; 136 return;
136 } 137 }
137 } 138 }
138 qDebug("No match for \"%s\"",sn.latin1()); 139 qDebug("No match for \"%s\"",sn.latin1());
139} 140}
140 141
141void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits) 142void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits)
142{ 143{
143 auth_peer=0; 144 auth_peer=0;
144 if ( sn == tr("Any") ) { 145 if ( sn == tr("Any") ) {
145 auth_peer = 0; 146 auth_peer = 0;
146 auth_peer_bits = 0; 147 auth_peer_bits = 0;
147 } else if ( sn == tr("None") ) { 148 } else if ( sn == tr("None") ) {
148 auth_peer = 0; 149 auth_peer = 0;
149 auth_peer_bits = 32; 150 auth_peer_bits = 32;
150 } else { 151 } else {
151 int x=0; 152 int x=0;
152 for (int i=0; i<4; i++) { 153 for (int i=0; i<4; i++) {
153 int nx = sn.find(QChar(i==3 ? '/' : '.'),x); 154 int nx = sn.find(QChar(i==3 ? '/' : '.'),x);
154 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt(); 155 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt();
155 x = nx+1; 156 x = nx+1;
156 } 157 }
157 uint n = (uint)sn.find(' ',x)-x; 158 uint n = (uint)sn.find(' ',x)-x;
158 auth_peer_bits = sn.mid(x,n).toInt(); 159 auth_peer_bits = sn.mid(x,n).toInt();
159 } 160 }
160} 161}
161 162
162void Security::setSyncNet(const QString& sn) 163void Security::setSyncNet(const QString& sn)
163{ 164{
164 int auth_peer,auth_peer_bits; 165 int auth_peer,auth_peer_bits;
165 parseNet(sn,auth_peer,auth_peer_bits); 166 parseNet(sn,auth_peer,auth_peer_bits);
166 selectNet(auth_peer,auth_peer_bits); 167 selectNet(auth_peer,auth_peer_bits);
167} 168}
168 169
169void Security::applySecurity() 170void Security::applySecurity()
170{ 171{
171 if ( valid ) { 172 if ( valid ) {
172 Config cfg("Security"); 173 Config cfg("Security");
173 cfg.setGroup("Passcode"); 174 cfg.setGroup("Passcode");
174 cfg.writeEntry("passcode",passcode); 175 cfg.writeEntry("passcode",passcode);
175 cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked()); 176 cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked());
176 cfg.setGroup("Sync"); 177 cfg.setGroup("Sync");
177 int auth_peer=0; 178 int auth_peer=0;
178 int auth_peer_bits; 179 int auth_peer_bits;
179 QString sn = syncnet->currentText(); 180 QString sn = syncnet->currentText();
180 parseNet(sn,auth_peer,auth_peer_bits); 181 parseNet(sn,auth_peer,auth_peer_bits);
181 cfg.writeEntry("auth_peer",auth_peer); 182 cfg.writeEntry("auth_peer",auth_peer);
182 cfg.writeEntry("auth_peer_bits",auth_peer_bits); 183 cfg.writeEntry("auth_peer_bits",auth_peer_bits);
183 /* 184 /*
184 cfg.setGroup("Remote"); 185 cfg.setGroup("Remote");
185 if ( telnetAvailable() ) 186 if ( telnetAvailable() )
186 cfg.writeEntry("allow_telnet",telnet->isChecked()); 187 cfg.writeEntry("allow_telnet",telnet->isChecked());
187 if ( sshAvailable() ) 188 if ( sshAvailable() )
188 cfg.writeEntry("allow_ssh",ssh->isChecked()); 189 cfg.writeEntry("allow_ssh",ssh->isChecked());
189 // ### write ssh/telnet sys config files 190 // ### write ssh/telnet sys config files
190 */ 191 */
191 } 192 }
192} 193}
193 194
194void Security::changePassCode() 195void Security::changePassCode()
195{ 196{
196 QString new1; 197 QString new1;
197 QString new2; 198 QString new2;
198 199
199 do { 200 do {
200 new1 = enterPassCode(tr("Enter new passcode")); 201 new1 = enterPassCode(tr("Enter new passcode"));
201 if ( new1.isNull() ) 202 if ( new1.isNull() )
202 return; 203 return;
203 new2 = enterPassCode(tr("Re-enter new passcode")); 204 new2 = enterPassCode(tr("Re-enter new passcode"));
204 if ( new2.isNull() ) 205 if ( new2.isNull() )
205 return; 206 return;
206 } while (new1 != new2); 207 } while (new1 != new2);
207 208
208 passcode = new1; 209 passcode = new1;
209 updateGUI(); 210 updateGUI();
210} 211}
211 212
212void Security::clearPassCode() 213void Security::clearPassCode()
213{ 214{
214 passcode = QString::null; 215 passcode = QString::null;
215 updateGUI(); 216 updateGUI();
216} 217}
217 218
218 219
219QString Security::enterPassCode(const QString& prompt) 220QString Security::enterPassCode(const QString& prompt)
220{ 221{
221 return Password::getPassword(prompt); 222 return Password::getPassword(prompt);
222} 223}
223 224