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.cpp5
1 files changed, 0 insertions, 5 deletions
diff --git a/core/settings/security/security.cpp b/core/settings/security/security.cpp
index 42a39c2..81363d2 100644
--- a/core/settings/security/security.cpp
+++ b/core/settings/security/security.cpp
@@ -27,299 +27,294 @@
27 27
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qcombobox.h> 30#include <qcombobox.h>
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qlistview.h> 33#include <qlistview.h>
34#include <qtextstream.h> 34#include <qtextstream.h>
35 35
36 Security::Security( QWidget* parent, const char* name, WFlags fl ) 36 Security::Security( QWidget* parent, const char* name, WFlags fl )
37: SecurityBase( parent, name, TRUE, fl ) 37: SecurityBase( parent, name, TRUE, fl )
38{ 38{
39 valid=FALSE; 39 valid=FALSE;
40 Config cfg("Security"); 40 Config cfg("Security");
41 cfg.setGroup("Passcode"); 41 cfg.setGroup("Passcode");
42 passcode = cfg.readEntry("passcode"); 42 passcode = cfg.readEntry("passcode");
43 passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE)); 43 passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE));
44 cfg.setGroup("Sync"); 44 cfg.setGroup("Sync");
45 int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 45 int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24
46 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); 46 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24);
47 selectNet(auth_peer,auth_peer_bits); 47 selectNet(auth_peer,auth_peer_bits);
48 connect(syncnet, SIGNAL(textChanged(const QString&)), 48 connect(syncnet, SIGNAL(textChanged(const QString&)),
49 this, SLOT(setSyncNet(const QString&))); 49 this, SLOT(setSyncNet(const QString&)));
50 50
51 /* 51 /*
52 cfg.setGroup("Remote"); 52 cfg.setGroup("Remote");
53 if ( telnetAvailable() ) 53 if ( telnetAvailable() )
54 telnet->setChecked(cfg.readEntry("allow_telnet")); 54 telnet->setChecked(cfg.readEntry("allow_telnet"));
55 else 55 else
56 telnet->hide(); 56 telnet->hide();
57 57
58 if ( sshAvailable() ) 58 if ( sshAvailable() )
59 ssh->setChecked(cfg.readEntry("allow_ssh")); 59 ssh->setChecked(cfg.readEntry("allow_ssh"));
60 else 60 else
61 ssh->hide(); 61 ssh->hide();
62 */ 62 */
63 63
64 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; 64 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf";
65 Config loginCfg(configFile,Config::File); 65 Config loginCfg(configFile,Config::File);
66 66
67 loginCfg.setGroup("General"); 67 loginCfg.setGroup("General");
68 autoLoginName=loginCfg.readEntry("AutoLogin",""); 68 autoLoginName=loginCfg.readEntry("AutoLogin","");
69 69
70 if (autoLoginName.stripWhiteSpace().isEmpty()) { 70 if (autoLoginName.stripWhiteSpace().isEmpty()) {
71 autoLogin=false; 71 autoLogin=false;
72 } else { 72 } else {
73 autoLogin=true; 73 autoLogin=true;
74 } 74 }
75 75
76 cfg.setGroup("SyncMode"); 76 cfg.setGroup("SyncMode");
77 int mode = cfg.readNumEntry("Mode",2); // Default to Sharp 77 int mode = cfg.readNumEntry("Mode",2); // Default to Sharp
78 syncModeCombo->setCurrentItem( mode - 1 ); 78 syncModeCombo->setCurrentItem( mode - 1 );
79 79
80 connect(autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool))); 80 connect(autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool)));
81 connect(userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int))); 81 connect(userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int)));
82 connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode())); 82 connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode()));
83 connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode())); 83 connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode()));
84 84
85 loadUsers(); 85 loadUsers();
86 updateGUI(); 86 updateGUI();
87 87
88 dl = new QPEDialogListener(this); 88 dl = new QPEDialogListener(this);
89 showMaximized(); 89 showMaximized();
90} 90}
91 91
92Security::~Security() 92Security::~Security()
93{ 93{
94} 94}
95 95
96 96
97void Security::updateGUI() 97void Security::updateGUI()
98{ 98{
99 bool empty = passcode.isEmpty(); 99 bool empty = passcode.isEmpty();
100 100
101 changepasscode->setText( empty ? tr("Set passcode" ) 101 changepasscode->setText( empty ? tr("Set passcode" )
102 : tr("Change passcode" ) ); 102 : tr("Change passcode" ) );
103 passcode_poweron->setEnabled( !empty ); 103 passcode_poweron->setEnabled( !empty );
104 clearpasscode->setEnabled( !empty ); 104 clearpasscode->setEnabled( !empty );
105 105
106 autologinToggle->setChecked(autoLogin); 106 autologinToggle->setChecked(autoLogin);
107 userlist->setEnabled(autoLogin); 107 userlist->setEnabled(autoLogin);
108 108
109} 109}
110 110
111 111
112void Security::show() 112void Security::show()
113{ 113{
114 //valid=FALSE; 114 //valid=FALSE;
115 setEnabled(FALSE); 115 setEnabled(FALSE);
116 SecurityBase::show(); 116 SecurityBase::show();
117 if ( passcode.isEmpty() ) { 117 if ( passcode.isEmpty() ) {
118 // could insist... 118 // could insist...
119 //changePassCode(); 119 //changePassCode();
120 //if ( passcode.isEmpty() ) 120 //if ( passcode.isEmpty() )
121 //reject(); 121 //reject();
122 } else { 122 } else {
123
124 if (!valid) // security passcode was not asked yet, so ask now 123 if (!valid) // security passcode was not asked yet, so ask now
125 { 124 {
126 QString pc = enterPassCode(tr("Enter passcode")); 125 QString pc = enterPassCode(tr("Enter passcode"));
127 if ( pc != passcode ) { 126 if ( pc != passcode ) {
128 QMessageBox::critical(this, tr("Passcode incorrect"), 127 QMessageBox::critical(this, tr("Passcode incorrect"),
129 tr("The passcode entered is incorrect.\nAccess denied")); 128 tr("The passcode entered is incorrect.\nAccess denied"));
130 reject(); 129 reject();
131 return; 130 return;
132 } 131 }
133 } 132 }
134 } 133 }
135 setEnabled(TRUE); 134 setEnabled(TRUE);
136 valid=TRUE; 135 valid=TRUE;
137} 136}
138 137
139void Security::accept() 138void Security::accept()
140{ 139{
141 applySecurity(); 140 applySecurity();
142 QDialog::accept(); 141 QDialog::accept();
143 QCopEnvelope env("QPE/System", "securityChanged()" ); 142 QCopEnvelope env("QPE/System", "securityChanged()" );
144} 143}
145 144
146void Security::done(int r) 145void Security::done(int r)
147{ 146{
148 QDialog::done(r); 147 QDialog::done(r);
149 close(); 148 close();
150} 149}
151 150
152void Security::selectNet(int auth_peer,int auth_peer_bits) 151void Security::selectNet(int auth_peer,int auth_peer_bits)
153{ 152{
154 QString sn; 153 QString sn;
155 if ( auth_peer_bits == 0 && auth_peer == 0 ) { 154 if ( auth_peer_bits == 0 && auth_peer == 0 ) {
156 sn = tr("Any"); 155 sn = tr("Any");
157 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { 156 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) {
158 sn = tr("None"); 157 sn = tr("None");
159 } else { 158 } else {
160 sn = 159 sn =
161 QString::number((auth_peer>>24)&0xff) + "." 160 QString::number((auth_peer>>24)&0xff) + "."
162 + QString::number((auth_peer>>16)&0xff) + "." 161 + QString::number((auth_peer>>16)&0xff) + "."
163 + QString::number((auth_peer>>8)&0xff) + "." 162 + QString::number((auth_peer>>8)&0xff) + "."
164 + QString::number((auth_peer>>0)&0xff) + "/" 163 + QString::number((auth_peer>>0)&0xff) + "/"
165 + QString::number(auth_peer_bits); 164 + QString::number(auth_peer_bits);
166 } 165 }
167 for (int i=0; i<syncnet->count(); i++) { 166 for (int i=0; i<syncnet->count(); i++) {
168 if ( syncnet->text(i).left(sn.length()) == sn ) { 167 if ( syncnet->text(i).left(sn.length()) == sn ) {
169 syncnet->setCurrentItem(i); 168 syncnet->setCurrentItem(i);
170 return; 169 return;
171 } 170 }
172 } 171 }
173 qDebug("No match for \"%s\"",sn.latin1()); 172 qDebug("No match for \"%s\"",sn.latin1());
174} 173}
175 174
176void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits) 175void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits)
177{ 176{
178 auth_peer=0; 177 auth_peer=0;
179 if ( sn == tr("Any") ) { 178 if ( sn == tr("Any") ) {
180 auth_peer = 0; 179 auth_peer = 0;
181 auth_peer_bits = 0; 180 auth_peer_bits = 0;
182 } else if ( sn == tr("None") ) { 181 } else if ( sn == tr("None") ) {
183 auth_peer = 0; 182 auth_peer = 0;
184 auth_peer_bits = 32; 183 auth_peer_bits = 32;
185 } else { 184 } else {
186 int x=0; 185 int x=0;
187 for (int i=0; i<4; i++) { 186 for (int i=0; i<4; i++) {
188 int nx = sn.find(QChar(i==3 ? '/' : '.'),x); 187 int nx = sn.find(QChar(i==3 ? '/' : '.'),x);
189 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt(); 188 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt();
190 x = nx+1; 189 x = nx+1;
191 } 190 }
192 uint n = (uint)sn.find(' ',x)-x; 191 uint n = (uint)sn.find(' ',x)-x;
193 auth_peer_bits = sn.mid(x,n).toInt(); 192 auth_peer_bits = sn.mid(x,n).toInt();
194 } 193 }
195} 194}
196 195
197void Security::loadUsers ( void ) 196void Security::loadUsers ( void )
198{ 197{
199 QFile passwd("/etc/passwd"); 198 QFile passwd("/etc/passwd");
200 if ( passwd.open(IO_ReadOnly) ) { 199 if ( passwd.open(IO_ReadOnly) ) {
201 QTextStream t( &passwd ); 200 QTextStream t( &passwd );
202 QString s; 201 QString s;
203 QStringList account; 202 QStringList account;
204 while ( !t.eof() ) { 203 while ( !t.eof() ) {
205 account = QStringList::split(':',t.readLine()); 204 account = QStringList::split(':',t.readLine());
206 205
207 // Hide disabled accounts 206 // Hide disabled accounts
208 if (*account.at(1)!="*") { 207 if (*account.at(1)!="*") {
209 208
210 userlist->insertItem(*account.at(0)); 209 userlist->insertItem(*account.at(0));
211 // Highlight this item if it is set to autologinToggle 210 // Highlight this item if it is set to autologinToggle
212 if ( *account.at(0) == autoLoginName) 211 if ( *account.at(0) == autoLoginName)
213 userlist->setCurrentItem(userlist->count()-1); 212 userlist->setCurrentItem(userlist->count()-1);
214 } 213 }
215 } 214 }
216 passwd.close(); 215 passwd.close();
217 } 216 }
218 217
219} 218}
220 219
221void Security::toggleAutoLogin(bool val) 220void Security::toggleAutoLogin(bool val)
222{ 221{
223 autoLogin=val; 222 autoLogin=val;
224 userlist->setEnabled(val); 223 userlist->setEnabled(val);
225 if (!autoLogin) 224 if (!autoLogin)
226 autoLoginName=userlist->currentText(); 225 autoLoginName=userlist->currentText();
227} 226}
228 227
229 228
230 229
231 230
232void Security::setSyncNet(const QString& sn) 231void Security::setSyncNet(const QString& sn)
233{ 232{
234 int auth_peer,auth_peer_bits; 233 int auth_peer,auth_peer_bits;
235 parseNet(sn,auth_peer,auth_peer_bits); 234 parseNet(sn,auth_peer,auth_peer_bits);
236 selectNet(auth_peer,auth_peer_bits); 235 selectNet(auth_peer,auth_peer_bits);
237} 236}
238 237
239void Security::applySecurity() 238void Security::applySecurity()
240{ 239{
241 if ( valid ) { 240 if ( valid ) {
242
243 Config cfg("Security"); 241 Config cfg("Security");
244 cfg.setGroup("Passcode"); 242 cfg.setGroup("Passcode");
245 cfg.writeEntry("passcode",passcode); 243 cfg.writeEntry("passcode",passcode);
246 cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked()); 244 cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked());
247 cfg.setGroup("Sync"); 245 cfg.setGroup("Sync");
248 int auth_peer=0; 246 int auth_peer=0;
249 int auth_peer_bits; 247 int auth_peer_bits;
250 QString sn = syncnet->currentText(); 248 QString sn = syncnet->currentText();
251 parseNet(sn,auth_peer,auth_peer_bits); 249 parseNet(sn,auth_peer,auth_peer_bits);
252 cfg.writeEntry("auth_peer",auth_peer); 250 cfg.writeEntry("auth_peer",auth_peer);
253 cfg.writeEntry("auth_peer_bits",auth_peer_bits); 251 cfg.writeEntry("auth_peer_bits",auth_peer_bits);
254 /* 252 /*
255 cfg.setGroup("Remote"); 253 cfg.setGroup("Remote");
256 if ( telnetAvailable() ) 254 if ( telnetAvailable() )
257 cfg.writeEntry("allow_telnet",telnet->isChecked()); 255 cfg.writeEntry("allow_telnet",telnet->isChecked());
258 if ( sshAvailable() ) 256 if ( sshAvailable() )
259 cfg.writeEntry("allow_ssh",ssh->isChecked()); 257 cfg.writeEntry("allow_ssh",ssh->isChecked());
260 // ### write ssh/telnet sys config files 258 // ### write ssh/telnet sys config files
261 */ 259 */
262 260
263 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; 261 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf";
264 Config loginCfg(configFile,Config::File); 262 Config loginCfg(configFile,Config::File);
265 loginCfg.setGroup("General"); 263 loginCfg.setGroup("General");
266 264
267 if (autoLogin) { 265 if (autoLogin) {
268 loginCfg.writeEntry("AutoLogin",autoLoginName); 266 loginCfg.writeEntry("AutoLogin",autoLoginName);
269 } else { 267 } else {
270 loginCfg.removeEntry("AutoLogin"); 268 loginCfg.removeEntry("AutoLogin");
271 } 269 }
272 270
273 cfg.setGroup("SyncMode");
274 cfg.writeEntry("Mode", syncModeCombo->currentItem()+1 );
275
276 } 271 }
277} 272}
278 273
279void Security::changeLoginName( int idx ) 274void Security::changeLoginName( int idx )
280{ 275{
281 autoLoginName = userlist->text(idx);; 276 autoLoginName = userlist->text(idx);;
282 updateGUI(); 277 updateGUI();
283} 278}
284 279
285void Security::changePassCode() 280void Security::changePassCode()
286{ 281{
287 QString new1; 282 QString new1;
288 QString new2; 283 QString new2;
289 284
290 do { 285 do {
291 new1 = enterPassCode(tr("Enter new passcode")); 286 new1 = enterPassCode(tr("Enter new passcode"));
292 if ( new1.isNull() ) 287 if ( new1.isNull() )
293 return; 288 return;
294 new2 = enterPassCode(tr("Re-enter new passcode")); 289 new2 = enterPassCode(tr("Re-enter new passcode"));
295 if ( new2.isNull() ) 290 if ( new2.isNull() )
296 return; 291 return;
297 } while (new1 != new2); 292 } while (new1 != new2);
298 293
299 passcode = new1; 294 passcode = new1;
300 updateGUI(); 295 updateGUI();
301} 296}
302 297
303void Security::clearPassCode() 298void Security::clearPassCode()
304{ 299{
305 passcode = QString::null; 300 passcode = QString::null;
306 updateGUI(); 301 updateGUI();
307} 302}
308 303
309 304
310QString Security::enterPassCode(const QString& prompt) 305QString Security::enterPassCode(const QString& prompt)
311{ 306{
312 return Password::getPassword(prompt); 307 return Password::getPassword(prompt);
313} 308}
314 309
315bool Security::telnetAvailable() const 310bool Security::telnetAvailable() const
316{ 311{
317 // ### not implemented 312 // ### not implemented
318 return FALSE; 313 return FALSE;
319} 314}
320 315
321bool Security::sshAvailable() const 316bool Security::sshAvailable() const
322{ 317{
323 // ### not implemented 318 // ### not implemented
324 return FALSE; 319 return FALSE;
325} 320}