summaryrefslogtreecommitdiff
path: root/core/opie-login/loginwindowimpl.cpp
Unidiff
Diffstat (limited to 'core/opie-login/loginwindowimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/loginwindowimpl.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp
index 63baaa6..c59338f 100644
--- a/core/opie-login/loginwindowimpl.cpp
+++ b/core/opie-login/loginwindowimpl.cpp
@@ -1,138 +1,141 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qlayout.h> 3#include <qlayout.h>
4#include <qframe.h> 4#include <qframe.h>
5#include <qlineedit.h> 5#include <qlineedit.h>
6#include <qtimer.h> 6#include <qtimer.h>
7#include <qcombobox.h> 7#include <qcombobox.h>
8#include <qpixmap.h> 8#include <qpixmap.h>
9#include <qlabel.h> 9#include <qlabel.h>
10#include <qpopupmenu.h> 10#include <qpopupmenu.h>
11#include <qmessagebox.h> 11#include <qmessagebox.h>
12#include <qimage.h>
12 13
14#include <qpe/resource.h>
13#include <qpe/qcopenvelope_qws.h> 15#include <qpe/qcopenvelope_qws.h>
14 16
15#include <opie/odevice.h> 17#include <opie/odevice.h>
16 18
17#include <stdio.h> 19#include <stdio.h>
18 20
19#include <pwd.h> 21#include <pwd.h>
20#include <grp.h> 22#include <grp.h>
21#include <unistd.h> 23#include <unistd.h>
22#include <stdlib.h> 24#include <stdlib.h>
23#include <signal.h> 25#include <signal.h>
24 26
25#ifdef USEPAM 27#ifdef USEPAM
26extern "C" { 28extern "C" {
27#include <security/pam_appl.h> 29#include <security/pam_appl.h>
28} 30}
29#else 31#else
30#include <crypt.h> 32#include <crypt.h>
31#include <shadow.h> 33#include <shadow.h>
32#endif 34#endif
33 35
34#include "loginwindowimpl.h" 36#include "loginwindowimpl.h"
35#include "inputmethods.h" 37#include "inputmethods.h"
36 38
37using namespace Opie; 39using namespace Opie;
38 40
39 41
40LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) 42LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose )
41{ 43{
42 QPopupMenu *pop = new QPopupMenu ( this ); 44 QPopupMenu *pop = new QPopupMenu ( this );
43 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); 45 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( )));
44 pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); 46 pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( )));
45 m_menu-> setPopup ( pop ); 47 m_menu-> setPopup ( pop );
46 48
47 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); 49 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 );
48 m_input = new InputMethods ( m_taskbar ); 50 m_input = new InputMethods ( m_taskbar );
49 lay-> addWidget ( m_input ); 51 lay-> addWidget ( m_input );
50 lay-> addStretch ( 10 ); 52 lay-> addStretch ( 10 );
51 53
52 setActiveWindow ( ); 54 setActiveWindow ( );
53 m_password-> setFocus ( ); 55 m_password-> setFocus ( );
54 56
55 m_user-> insertStringList ( getAllUsers ( )); 57 m_user-> insertStringList ( getAllUsers ( ));
56 58
57 QTimer::singleShot ( 0, this, SLOT( showIM ( ))); 59 QTimer::singleShot ( 0, this, SLOT( showIM ( )));
58 60
59 QString opiedir = ::getenv ( "OPIEDIR" ); 61 QString opiedir = ::getenv ( "OPIEDIR" );
60 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); 62 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" );
61 63
62 if ( !bgpix. isNull ( )) 64 if ( !bgpix. isNull ( ))
63 setBackgroundPixmap ( bgpix ); 65 setBackgroundPixmap ( bgpix );
64 66
65 m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); 67 m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( )));
66} 68}
67 69
68LoginWindowImpl::~LoginWindowImpl ( ) 70LoginWindowImpl::~LoginWindowImpl ( )
69{ 71{
70} 72}
71 73
72void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) 74void LoginWindowImpl::keyPressEvent ( QKeyEvent *e )
73{ 75{
74 switch ( e-> key ( )) { 76 switch ( e-> key ( )) {
75 case HardKey_Suspend: suspend ( ); 77 case HardKey_Suspend: suspend ( );
76 break; 78 break;
77 case HardKey_Backlight: backlight ( ); 79 case HardKey_Backlight: backlight ( );
78 break; 80 break;
79 default: e-> ignore ( ); 81 default: e-> ignore ( );
80 break; 82 break;
81 } 83 }
82 LoginWindow::keyPressEvent ( e ); 84 LoginWindow::keyPressEvent ( e );
83} 85}
84 86
85 87
86void LoginWindowImpl::toggleEchoMode ( bool t ) 88void LoginWindowImpl::toggleEchoMode ( bool t )
87{ 89{
88 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); 90 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password );
89} 91}
90 92
93
91QStringList LoginWindowImpl::getAllUsers ( ) 94QStringList LoginWindowImpl::getAllUsers ( )
92{ 95{
93 struct passwd *pwd; 96 struct passwd *pwd;
94 QStringList sl; 97 QStringList sl;
95 98
96 while (( pwd = ::getpwent ( ))) { 99 while (( pwd = ::getpwent ( ))) {
97 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) 100 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 ))
98 sl << QString ( pwd-> pw_name ); 101 sl << QString ( pwd-> pw_name );
99 } 102 }
100 103
101 ::endpwent ( ); 104 ::endpwent ( );
102 105
103 return sl; 106 return sl;
104} 107}
105 108
106void LoginWindowImpl::showIM ( ) 109void LoginWindowImpl::showIM ( )
107{ 110{
108 m_input-> showInputMethod ( ); 111 m_input-> showInputMethod ( );
109} 112}
110 113
111void LoginWindowImpl::restart ( ) 114void LoginWindowImpl::restart ( )
112{ 115{
113 qApp-> quit ( ); 116 qApp-> quit ( );
114} 117}
115 118
116void LoginWindowImpl::quit ( ) 119void LoginWindowImpl::quit ( )
117{ 120{
118 qApp-> quit ( ); 121 qApp-> quit ( );
119 ::kill ( ::getppid ( ), SIGUSR1 ); 122 ::kill ( ::getppid ( ), SIGUSR1 );
120} 123}
121 124
122void LoginWindowImpl::suspend ( ) 125void LoginWindowImpl::suspend ( )
123{ 126{
124 ODevice::inst ( )-> suspend ( ); 127 ODevice::inst ( )-> suspend ( );
125 128
126 QCopEnvelope e("QPE/System", "setBacklight(int)"); 129 QCopEnvelope e("QPE/System", "setBacklight(int)");
127 e << -3; // Force on 130 e << -3; // Force on
128} 131}
129 132
130void LoginWindowImpl::backlight ( ) 133void LoginWindowImpl::backlight ( )
131{ 134{
132 QCopEnvelope e("QPE/System", "setBacklight(int)"); 135 QCopEnvelope e("QPE/System", "setBacklight(int)");
133 e << -2; // toggle 136 e << -2; // toggle
134} 137}
135 138
136#ifdef USEPAM 139#ifdef USEPAM
137 140
138static const char *_PAM_SERVICE = "xdm"; 141static const char *_PAM_SERVICE = "xdm";
@@ -255,72 +258,88 @@ static bool pwcheck_Unix( const char *user, const char *pass )
255 258
256#endif 259#endif
257 260
258 261
259bool LoginWindowImpl::changeIdentity ( const char *user ) 262bool LoginWindowImpl::changeIdentity ( const char *user )
260{ 263{
261 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; 264 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin";
262 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; 265 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin";
263 266
264 bool fail = false; 267 bool fail = false;
265 struct passwd *pw = getpwnam ( user ); 268 struct passwd *pw = getpwnam ( user );
266 269
267 fail |= ( pw == 0 ); 270 fail |= ( pw == 0 );
268 fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid )); 271 fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid ));
269 endgrent ( ); 272 endgrent ( );
270 fail |= ( setgid ( pw-> pw_gid )); 273 fail |= ( setgid ( pw-> pw_gid ));
271 fail |= ( setuid ( pw-> pw_uid )); 274 fail |= ( setuid ( pw-> pw_uid ));
272 275
273 fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" )); 276 fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" ));
274 277
275 fail |= ( setenv ( "HOME", pw-> pw_dir, 1 )); 278 fail |= ( setenv ( "HOME", pw-> pw_dir, 1 ));
276 fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 )); 279 fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 ));
277 fail |= ( setenv ( "USER", pw-> pw_name, 1 )); 280 fail |= ( setenv ( "USER", pw-> pw_name, 1 ));
278 fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 )); 281 fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 ));
279 fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); 282 fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 ));
280 283
281 return !fail; 284 return !fail;
282} 285}
283 286
284void LoginWindowImpl::login ( ) 287void LoginWindowImpl::login ( )
285{ 288{
286 const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); 289 const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( ));
287 const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); 290 const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( ));
288 bool ok; 291 bool ok;
289 292
290 if ( !user || !user [0] ) 293 if ( !user || !user [0] )
291 return; 294 return;
292 if ( !pass ) 295 if ( !pass )
293 pass = ""; 296 pass = "";
294 297
295#if defined( USEPAM ) 298#if defined( USEPAM )
296 ok = pwcheck_PAM ( user, pass ); 299 ok = pwcheck_PAM ( user, pass );
297#else 300#else
298 ok = pwcheck_Unix ( user, pass ); 301 ok = pwcheck_Unix ( user, pass );
299#endif 302#endif
300 303
301 if ( ok ) { 304 if ( ok ) {
302 if ( changeIdentity ( user )) { 305 if ( changeIdentity ( user )) {
306 // Draw a big wait icon, the image can be altered in later revisions
307 QWidget *d = QApplication::desktop ( );
308 m_input-> hideInputMethod ( );
309
310 QImage img = Resource::loadImage( "launcher/new_wait" );
311 QPixmap pix;
312 pix. convertFromImage ( img );
313 QLabel *w = new QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool );
314 w-> setPixmap ( pix );
315 w-> setAlignment ( AlignCenter );
316 w-> showMaximized ( );
317 qApp-> processEvents ( );
318
303 char *opie = ::getenv ( "OPIEDIR" ); 319 char *opie = ::getenv ( "OPIEDIR" );
304 char *arg = new char [::strlen ( opie ) + 8 + 1]; 320 char *arg = new char [::strlen ( opie ) + 8 + 1];
305 321
306 ::strcpy ( arg, opie ); 322 ::strcpy ( arg, opie );
307 ::strcat ( arg, "/bin/qpe" ); 323 ::strcat ( arg, "/bin/qpe" );
308 324
309 // start qpe via a login shell 325 // start qpe via a login shell
310 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); 326 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 );
311 327
328 w-> hide ( );
329 delete w;
330
312 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE\n(%1)." ). arg ( arg )); 331 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE\n(%1)." ). arg ( arg ));
313 delete [] arg; 332 delete [] arg;
314 333
315 restart ( ); 334 restart ( );
316 } 335 }
317 else { 336 else {
318 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" )); 337 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" ));
319 restart ( ); 338 restart ( );
320 } 339 }
321 } 340 }
322 else { 341 else {
323 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); 342 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." ));
324 m_password-> clear ( ); 343 m_password-> clear ( );
325 } 344 }
326} 345}