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