Diffstat (limited to 'core/opie-login/loginwindowimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/opie-login/loginwindowimpl.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp index 3265b46..f24ebb3 100644 --- a/core/opie-login/loginwindowimpl.cpp +++ b/core/opie-login/loginwindowimpl.cpp | |||
@@ -17,12 +17,13 @@ | |||
17 | #include <stdio.h> | 17 | #include <stdio.h> |
18 | 18 | ||
19 | #include <pwd.h> | 19 | #include <pwd.h> |
20 | #include <grp.h> | 20 | #include <grp.h> |
21 | #include <unistd.h> | 21 | #include <unistd.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <signal.h> | ||
23 | 24 | ||
24 | #ifdef USEPAM | 25 | #ifdef USEPAM |
25 | extern "C" { | 26 | extern "C" { |
26 | #include <security/pam_appl.h> | 27 | #include <security/pam_appl.h> |
27 | } | 28 | } |
28 | #else | 29 | #else |
@@ -34,12 +35,13 @@ extern "C" { | |||
34 | #include "inputmethods.h" | 35 | #include "inputmethods.h" |
35 | 36 | ||
36 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) | 37 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) |
37 | { | 38 | { |
38 | QPopupMenu *pop = new QPopupMenu ( this ); | 39 | QPopupMenu *pop = new QPopupMenu ( this ); |
39 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); | 40 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); |
41 | pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); | ||
40 | m_menu-> setPopup ( pop ); | 42 | m_menu-> setPopup ( pop ); |
41 | 43 | ||
42 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); | 44 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); |
43 | m_input = new InputMethods ( m_taskbar ); | 45 | m_input = new InputMethods ( m_taskbar ); |
44 | lay-> addWidget ( m_input ); | 46 | lay-> addWidget ( m_input ); |
45 | lay-> addStretch ( 10 ); | 47 | lay-> addStretch ( 10 ); |
@@ -54,25 +56,25 @@ LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_C | |||
54 | QString opiedir = ::getenv ( "OPIEDIR" ); | 56 | QString opiedir = ::getenv ( "OPIEDIR" ); |
55 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); | 57 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); |
56 | 58 | ||
57 | if ( !bgpix. isNull ( )) | 59 | if ( !bgpix. isNull ( )) |
58 | setBackgroundPixmap ( bgpix ); | 60 | setBackgroundPixmap ( bgpix ); |
59 | 61 | ||
60 | m_caption-> setText ( m_caption-> text ( ) + tr( "<center><h1><u>%1 %2</u></h1></center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); | 62 | m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); |
61 | } | 63 | } |
62 | 64 | ||
63 | LoginWindowImpl::~LoginWindowImpl ( ) | 65 | LoginWindowImpl::~LoginWindowImpl ( ) |
64 | { | 66 | { |
65 | } | 67 | } |
66 | 68 | ||
67 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) | 69 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) |
68 | { | 70 | { |
69 | switch ( e-> key ( )) { | 71 | switch ( e-> key ( )) { |
70 | case Key_F34: suspend ( ); | 72 | case HardKey_Suspend: suspend ( ); |
71 | break; | 73 | break; |
72 | case Key_F35: backlight ( ); | 74 | case HardKey_Backlight: backlight ( ); |
73 | break; | 75 | break; |
74 | default : e-> ignore ( ); | 76 | default : e-> ignore ( ); |
75 | break; | 77 | break; |
76 | } | 78 | } |
77 | LoginWindow::keyPressEvent ( e ); | 79 | LoginWindow::keyPressEvent ( e ); |
78 | } | 80 | } |
@@ -85,18 +87,18 @@ void LoginWindowImpl::toggleEchoMode ( bool t ) | |||
85 | 87 | ||
86 | QStringList LoginWindowImpl::getAllUsers ( ) | 88 | QStringList LoginWindowImpl::getAllUsers ( ) |
87 | { | 89 | { |
88 | struct passwd *pwd; | 90 | struct passwd *pwd; |
89 | QStringList sl; | 91 | QStringList sl; |
90 | 92 | ||
91 | while (( pwd = getpwent ( ))) { | 93 | while (( pwd = ::getpwent ( ))) { |
92 | if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) | 94 | if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) |
93 | sl << QString ( pwd-> pw_name ); | 95 | sl << QString ( pwd-> pw_name ); |
94 | } | 96 | } |
95 | 97 | ||
96 | endpwent ( ); | 98 | ::endpwent ( ); |
97 | 99 | ||
98 | return sl; | 100 | return sl; |
99 | } | 101 | } |
100 | 102 | ||
101 | void LoginWindowImpl::showIM ( ) | 103 | void LoginWindowImpl::showIM ( ) |
102 | { | 104 | { |
@@ -105,29 +107,31 @@ void LoginWindowImpl::showIM ( ) | |||
105 | 107 | ||
106 | void LoginWindowImpl::restart ( ) | 108 | void LoginWindowImpl::restart ( ) |
107 | { | 109 | { |
108 | qApp-> quit ( ); | 110 | qApp-> quit ( ); |
109 | } | 111 | } |
110 | 112 | ||
111 | void LoginWindowImpl::suspend ( ) | 113 | void LoginWindowImpl::quit ( ) |
112 | { | 114 | { |
113 | system ( "apm -s" ); | 115 | qApp-> quit ( ); |
114 | usleep ( 1 * 1000 * 1000 ); | 116 | ::kill ( ::getppid ( ), SIGUSR1 ); |
117 | } | ||
118 | |||
119 | void LoginWindowImpl::suspend ( ) | ||
115 | { | 120 | { |
121 | ODevice::inst ( )-> suspend ( ); | ||
122 | |||
116 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 123 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
117 | e << -3; // Force on | 124 | e << -3; // Force on |
118 | } | 125 | } |
119 | } | ||
120 | 126 | ||
121 | void LoginWindowImpl::backlight ( ) | 127 | void LoginWindowImpl::backlight ( ) |
122 | { | 128 | { |
123 | { | ||
124 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 129 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
125 | e << -2; // toggle | 130 | e << -2; // toggle |
126 | } | 131 | } |
127 | } | ||
128 | 132 | ||
129 | #ifdef USEPAM | 133 | #ifdef USEPAM |
130 | 134 | ||
131 | static const char *_PAM_SERVICE = "xdm"; | 135 | static const char *_PAM_SERVICE = "xdm"; |
132 | static const char *PAM_password; | 136 | static const char *PAM_password; |
133 | 137 | ||
@@ -255,42 +259,32 @@ bool LoginWindowImpl::changeIdentity ( const char *user ) | |||
255 | const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; | 259 | const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; |
256 | 260 | ||
257 | bool fail = false; | 261 | bool fail = false; |
258 | struct passwd *pw = getpwnam ( user ); | 262 | struct passwd *pw = getpwnam ( user ); |
259 | 263 | ||
260 | fail |= ( pw == 0 ); | 264 | fail |= ( pw == 0 ); |
261 | printf ( "1 %d\n", fail ); | ||
262 | fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid )); | 265 | fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid )); |
263 | endgrent ( ); | 266 | endgrent ( ); |
264 | printf ( "2 %d\n", fail ); | ||
265 | fail |= ( setgid ( pw-> pw_gid )); | 267 | fail |= ( setgid ( pw-> pw_gid )); |
266 | printf ( "3 %d\n", fail ); | ||
267 | fail |= ( setuid ( pw-> pw_uid )); | 268 | fail |= ( setuid ( pw-> pw_uid )); |
268 | 269 | ||
269 | printf ( "4 %d\n", fail ); | ||
270 | fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" )); | 270 | fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" )); |
271 | 271 | ||
272 | printf ( "5 %d\n", fail ); | ||
273 | fail |= ( setenv ( "HOME", pw-> pw_dir, 1 )); | 272 | fail |= ( setenv ( "HOME", pw-> pw_dir, 1 )); |
274 | printf ( "6 %d\n", fail ); | ||
275 | fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 )); | 273 | fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 )); |
276 | printf ( "7 %d\n", fail ); | ||
277 | fail |= ( setenv ( "USER", pw-> pw_name, 1 )); | 274 | fail |= ( setenv ( "USER", pw-> pw_name, 1 )); |
278 | printf ( "8 %d\n", fail ); | ||
279 | fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 )); | 275 | fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 )); |
280 | printf ( "9 %d\n", fail ); | ||
281 | fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); | 276 | fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); |
282 | printf ( "10 %d\n", fail ); | ||
283 | 277 | ||
284 | return !fail; | 278 | return !fail; |
285 | } | 279 | } |
286 | 280 | ||
287 | void LoginWindowImpl::login ( ) | 281 | void LoginWindowImpl::login ( ) |
288 | { | 282 | { |
289 | const char *user = strdup ( m_user-> currentText ( ). local8Bit ( )); | 283 | const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); |
290 | const char *pass = strdup ( m_password-> text ( ). local8Bit ( )); | 284 | const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); |
291 | bool ok; | 285 | bool ok; |
292 | 286 | ||
293 | if ( !user || !user [0] ) | 287 | if ( !user || !user [0] ) |
294 | return; | 288 | return; |
295 | if ( !pass ) | 289 | if ( !pass ) |
296 | pass = ""; | 290 | pass = ""; |
@@ -300,18 +294,24 @@ void LoginWindowImpl::login ( ) | |||
300 | #else | 294 | #else |
301 | ok = pwcheck_Unix ( user, pass ); | 295 | ok = pwcheck_Unix ( user, pass ); |
302 | #endif | 296 | #endif |
303 | 297 | ||
304 | if ( ok ) { | 298 | if ( ok ) { |
305 | if ( changeIdentity ( user )) { | 299 | if ( changeIdentity ( user )) { |
306 | QString opie = getenv ( "OPIEDIR" ); | 300 | char *opie = ::getenv ( "OPIEDIR" ); |
307 | opie += "/bin/qpe"; | 301 | char *arg = new char [::strlen ( opie ) + 8 + 1]; |
302 | |||
303 | ::strcpy ( arg, opie ); | ||
304 | ::strcat ( arg, "/bin/qpe" ); | ||
305 | |||
306 | // start qpe via a login shell | ||
307 | ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); | ||
308 | 308 | ||
309 | execl ( opie. latin1 ( ), "qpe", 0 ); | 309 | QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE\n(%1)." ). arg ( arg )); |
310 | delete [] arg; | ||
310 | 311 | ||
311 | QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE." )); | ||
312 | restart ( ); | 312 | restart ( ); |
313 | } | 313 | } |
314 | else { | 314 | else { |
315 | QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" )); | 315 | QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" )); |
316 | restart ( ); | 316 | restart ( ); |
317 | } | 317 | } |