author | sandman <sandman> | 2002-10-14 00:59:28 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-14 00:59:28 (UTC) |
commit | 62c946c5a92ab11b5ad9495ff0bab158d38bce48 (patch) (unidiff) | |
tree | 01375a50aace755e808eef3103d3c4395530b4f1 /core/opie-login/loginwindowimpl.cpp | |
parent | 72c07a1db3bad19fa227fc6fb482afe517d18095 (diff) | |
download | opie-62c946c5a92ab11b5ad9495ff0bab158d38bce48.zip opie-62c946c5a92ab11b5ad9495ff0bab158d38bce48.tar.gz opie-62c946c5a92ab11b5ad9495ff0bab158d38bce48.tar.bz2 |
- last login name is saved
- wait image should be displayed right now
- the qApp object is destroyed before the launcher is started -- this
should prevent some semaphore permission problems
- added a (very basic) crash handler
- added a simple "respawned too fast" detection in case of qt/e fb problems
- if opie-login is started with -a <user> or --autologin <user> it doesn't
prompt for a username/password - instead it loads qpe directly using the
specified user account
So even if you are not running multiuser, you should now start qpe with:
opie-login --autologin=root
Diffstat (limited to 'core/opie-login/loginwindowimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/opie-login/loginwindowimpl.cpp | 270 |
1 files changed, 51 insertions, 219 deletions
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp index c59338f..3694513 100644 --- a/core/opie-login/loginwindowimpl.cpp +++ b/core/opie-login/loginwindowimpl.cpp | |||
@@ -1,345 +1,177 @@ | |||
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 | #include <qimage.h> |
13 | 13 | ||
14 | #include <qpe/resource.h> | 14 | #include <qpe/resource.h> |
15 | #include <qpe/qcopenvelope_qws.h> | 15 | #include <qpe/qcopenvelope_qws.h> |
16 | #include <qpe/config.h> | ||
16 | 17 | ||
17 | #include <opie/odevice.h> | 18 | #include <opie/odevice.h> |
18 | 19 | ||
19 | #include <stdio.h> | 20 | #include <stdio.h> |
20 | |||
21 | #include <pwd.h> | ||
22 | #include <grp.h> | ||
23 | #include <unistd.h> | ||
24 | #include <stdlib.h> | 21 | #include <stdlib.h> |
25 | #include <signal.h> | ||
26 | |||
27 | #ifdef USEPAM | ||
28 | extern "C" { | ||
29 | #include <security/pam_appl.h> | ||
30 | } | ||
31 | #else | ||
32 | #include <crypt.h> | ||
33 | #include <shadow.h> | ||
34 | #endif | ||
35 | 22 | ||
36 | #include "loginwindowimpl.h" | 23 | #include "loginwindowimpl.h" |
24 | #include "loginapplication.h" | ||
37 | #include "inputmethods.h" | 25 | #include "inputmethods.h" |
38 | 26 | ||
39 | using namespace Opie; | 27 | using namespace Opie; |
40 | 28 | ||
41 | 29 | ||
42 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) | 30 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) |
43 | { | 31 | { |
44 | QPopupMenu *pop = new QPopupMenu ( this ); | 32 | QPopupMenu *pop = new QPopupMenu ( this ); |
45 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); | 33 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); |
46 | pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); | 34 | pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); |
47 | m_menu-> setPopup ( pop ); | 35 | m_menu-> setPopup ( pop ); |
48 | 36 | ||
49 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); | 37 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); |
50 | m_input = new InputMethods ( m_taskbar ); | 38 | m_input = new InputMethods ( m_taskbar ); |
51 | lay-> addWidget ( m_input ); | 39 | lay-> addWidget ( m_input ); |
52 | lay-> addStretch ( 10 ); | 40 | lay-> addStretch ( 10 ); |
53 | 41 | ||
54 | setActiveWindow ( ); | 42 | setActiveWindow ( ); |
55 | m_password-> setFocus ( ); | 43 | m_password-> setFocus ( ); |
56 | 44 | ||
57 | m_user-> insertStringList ( getAllUsers ( )); | 45 | m_user-> insertStringList ( lApp-> allUsers ( )); |
58 | 46 | ||
59 | QTimer::singleShot ( 0, this, SLOT( showIM ( ))); | 47 | QTimer::singleShot ( 0, this, SLOT( showIM ( ))); |
60 | 48 | ||
61 | QString opiedir = ::getenv ( "OPIEDIR" ); | 49 | QString opiedir = ::getenv ( "OPIEDIR" ); |
62 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); | 50 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); |
63 | 51 | ||
64 | if ( !bgpix. isNull ( )) | 52 | if ( !bgpix. isNull ( )) |
65 | setBackgroundPixmap ( bgpix ); | 53 | setBackgroundPixmap ( bgpix ); |
66 | 54 | ||
67 | m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); | 55 | m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); |
56 | |||
57 | Config cfg ( "opie-login" ); | ||
58 | cfg. setGroup ( "General" ); | ||
59 | QString last = cfg. readEntry ( "LastLogin" ); | ||
60 | |||
61 | if ( !last. isEmpty ( )) | ||
62 | m_user-> setEditText ( last ); | ||
68 | } | 63 | } |
69 | 64 | ||
70 | LoginWindowImpl::~LoginWindowImpl ( ) | 65 | LoginWindowImpl::~LoginWindowImpl ( ) |
71 | { | 66 | { |
72 | } | 67 | } |
73 | 68 | ||
74 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) | 69 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) |
75 | { | 70 | { |
76 | switch ( e-> key ( )) { | 71 | switch ( e-> key ( )) { |
77 | case HardKey_Suspend: suspend ( ); | 72 | case HardKey_Suspend: suspend ( ); |
78 | break; | 73 | break; |
79 | case HardKey_Backlight: backlight ( ); | 74 | case HardKey_Backlight: backlight ( ); |
80 | break; | 75 | break; |
81 | default: e-> ignore ( ); | 76 | default: e-> ignore ( ); |
82 | break; | 77 | break; |
83 | } | 78 | } |
84 | LoginWindow::keyPressEvent ( e ); | 79 | LoginWindow::keyPressEvent ( e ); |
85 | } | 80 | } |
86 | 81 | ||
87 | 82 | ||
88 | void LoginWindowImpl::toggleEchoMode ( bool t ) | 83 | void LoginWindowImpl::toggleEchoMode ( bool t ) |
89 | { | 84 | { |
90 | m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); | 85 | m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); |
91 | } | 86 | } |
92 | 87 | ||
93 | |||
94 | QStringList LoginWindowImpl::getAllUsers ( ) | ||
95 | { | ||
96 | struct passwd *pwd; | ||
97 | QStringList sl; | ||
98 | |||
99 | while (( pwd = ::getpwent ( ))) { | ||
100 | if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) | ||
101 | sl << QString ( pwd-> pw_name ); | ||
102 | } | ||
103 | |||
104 | ::endpwent ( ); | ||
105 | |||
106 | return sl; | ||
107 | } | ||
108 | |||
109 | void LoginWindowImpl::showIM ( ) | 88 | void LoginWindowImpl::showIM ( ) |
110 | { | 89 | { |
111 | m_input-> showInputMethod ( ); | 90 | m_input-> showInputMethod ( ); |
112 | } | 91 | } |
113 | 92 | ||
114 | void LoginWindowImpl::restart ( ) | 93 | void LoginWindowImpl::restart ( ) |
115 | { | 94 | { |
116 | qApp-> quit ( ); | 95 | qApp-> quit ( ); |
117 | } | 96 | } |
118 | 97 | ||
119 | void LoginWindowImpl::quit ( ) | 98 | void LoginWindowImpl::quit ( ) |
120 | { | 99 | { |
121 | qApp-> quit ( ); | 100 | lApp-> quitToConsole ( ); |
122 | ::kill ( ::getppid ( ), SIGUSR1 ); | ||
123 | } | 101 | } |
124 | 102 | ||
125 | void LoginWindowImpl::suspend ( ) | 103 | void LoginWindowImpl::suspend ( ) |
126 | { | 104 | { |
127 | ODevice::inst ( )-> suspend ( ); | 105 | ODevice::inst ( )-> suspend ( ); |
128 | 106 | ||
129 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 107 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
130 | e << -3; // Force on | 108 | e << -3; // Force on |
131 | } | 109 | } |
132 | 110 | ||
133 | void LoginWindowImpl::backlight ( ) | 111 | void LoginWindowImpl::backlight ( ) |
134 | { | 112 | { |
135 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 113 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
136 | e << -2; // toggle | 114 | e << -2; // toggle |
137 | } | 115 | } |
138 | 116 | ||
139 | #ifdef USEPAM | 117 | class WaitLogo : public QLabel { |
140 | 118 | public: | |
141 | static const char *_PAM_SERVICE = "xdm"; | 119 | WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool ) |
142 | static const char *PAM_password; | 120 | { |
143 | 121 | QImage img = Resource::loadImage ( "launcher/new_wait" ); | |
144 | typedef const struct pam_message pam_message_type; | 122 | QPixmap pix; |
145 | 123 | pix. convertFromImage ( img ); | |
146 | static int PAM_conv( int, pam_message_type **, struct pam_response **, void * ); | 124 | setPixmap ( pix ); |
147 | 125 | setAlignment ( AlignCenter ); | |
148 | static struct pam_conv PAM_conversation = { | 126 | move ( 0, 0 ); |
149 | &PAM_conv, | 127 | resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( )); |
150 | NULL | 128 | |
151 | }; | 129 | m_visible = false; |
152 | 130 | show ( ); | |
153 | //---------------------------------------------------------------------------- | ||
154 | |||
155 | static char *COPY_STRING( const char * s ) { | ||
156 | return (s) ? strdup(s) : (char *)NULL; | ||
157 | } | ||
158 | |||
159 | #define GET_MEM if (reply) realloc(reply, size);\ | ||
160 | else reply = (struct pam_response *)malloc(size); \ | ||
161 | if (!reply) return PAM_CONV_ERR; \ | ||
162 | size += sizeof(struct pam_response) | ||
163 | |||
164 | |||
165 | static int PAM_conv( int num_msg, pam_message_type **msg, | ||
166 | struct pam_response **resp, void *) | ||
167 | { | ||
168 | int count = 0, replies = 0; | ||
169 | struct pam_response *reply = NULL; | ||
170 | int size = sizeof(struct pam_response); | ||
171 | |||
172 | for( count = 0; count < num_msg; count++ ) { | ||
173 | switch (msg[count]->msg_style) { | ||
174 | case PAM_PROMPT_ECHO_ON: | ||
175 | /* user name given to PAM already */ | ||
176 | return PAM_CONV_ERR; | ||
177 | |||
178 | case PAM_PROMPT_ECHO_OFF: | ||
179 | /* wants password */ | ||
180 | GET_MEM; | ||
181 | reply[replies].resp_retcode = PAM_SUCCESS; | ||
182 | reply[replies].resp = COPY_STRING(PAM_password); | ||
183 | replies++; | ||
184 | /* PAM frees resp */ | ||
185 | break; | ||
186 | case PAM_TEXT_INFO: | ||
187 | break; | ||
188 | default: | ||
189 | /* unknown or PAM_ERROR_MSG */ | ||
190 | if (reply) free (reply); | ||
191 | return PAM_CONV_ERR; | ||
192 | } | ||
193 | } | ||
194 | if (reply) *resp = reply; | ||
195 | return PAM_SUCCESS; | ||
196 | } | ||
197 | |||
198 | |||
199 | static bool pwcheck_PAM( const char *user, const char *password ) | ||
200 | { | ||
201 | bool pw_correct = false; | ||
202 | int pam_error; | ||
203 | int pam_return = 0; | ||
204 | pam_handle_t *pamh = 0; | ||
205 | PAM_password = password; | ||
206 | |||
207 | pam_error = pam_start( _PAM_SERVICE, user, &PAM_conversation, &pamh ); | ||
208 | if( pam_error == PAM_SUCCESS ) { | ||
209 | pam_error = pam_authenticate( pamh, 0 ); | ||
210 | if( pam_error == PAM_SUCCESS ) { | ||
211 | //-- password correct | ||
212 | pw_correct = true; | ||
213 | pam_return = PAM_SUCCESS; | ||
214 | } else { | ||
215 | pam_return = pam_error; | ||
216 | } | ||
217 | } else { | ||
218 | // cerr << "PAM error: " << pam_strerror( pamh, pam_error ) << endl; | ||
219 | } | ||
220 | pam_end( pamh, pam_return ); | ||
221 | return pw_correct; | ||
222 | } | ||
223 | |||
224 | #else | ||
225 | |||
226 | //---------------------------------------------------------------------------- | ||
227 | |||
228 | static bool pwcheck_Unix( const char *user, const char *pass ) | ||
229 | { | ||
230 | char *encrypted, *correct; | ||
231 | struct passwd *pw; | ||
232 | |||
233 | if ( !user || !pass ) | ||
234 | return false; | ||
235 | |||
236 | pw = getpwnam ( user ); | ||
237 | |||
238 | if ( !pw ) | ||
239 | return false; | ||
240 | |||
241 | if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) { | ||
242 | struct spwd *sp = getspnam ( pw-> pw_name ); | ||
243 | |||
244 | if ( !sp ) | ||
245 | return false; | ||
246 | |||
247 | correct = sp-> sp_pwdp; | ||
248 | } | 131 | } |
249 | else | ||
250 | correct = pw-> pw_passwd; | ||
251 | |||
252 | if ( correct == 0 || correct[0] == '\0' ) | ||
253 | return true; | ||
254 | 132 | ||
255 | encrypted = crypt ( pass, correct ); | 133 | virtual void showEvent ( QShowEvent *e ) |
256 | return ( strcmp ( encrypted, correct ) == 0 ); | 134 | { |
257 | } | 135 | QLabel::showEvent ( e ); |
258 | 136 | m_visible = true; | |
259 | #endif | 137 | } |
260 | |||
261 | |||
262 | bool LoginWindowImpl::changeIdentity ( const char *user ) | ||
263 | { | ||
264 | const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; | ||
265 | const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; | ||
266 | |||
267 | bool fail = false; | ||
268 | struct passwd *pw = getpwnam ( user ); | ||
269 | |||
270 | fail |= ( pw == 0 ); | ||
271 | fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid )); | ||
272 | endgrent ( ); | ||
273 | fail |= ( setgid ( pw-> pw_gid )); | ||
274 | fail |= ( setuid ( pw-> pw_uid )); | ||
275 | |||
276 | fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" )); | ||
277 | 138 | ||
278 | fail |= ( setenv ( "HOME", pw-> pw_dir, 1 )); | 139 | virtual void paintEvent ( QPaintEvent *e ) |
279 | fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 )); | 140 | { |
280 | fail |= ( setenv ( "USER", pw-> pw_name, 1 )); | 141 | QLabel::paintEvent ( e ); |
281 | fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 )); | 142 | if ( m_visible ) |
282 | fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); | 143 | qApp-> quit ( ); |
144 | } | ||
283 | 145 | ||
284 | return !fail; | 146 | private: |
285 | } | 147 | bool m_visible; |
148 | }; | ||
286 | 149 | ||
287 | void LoginWindowImpl::login ( ) | 150 | void LoginWindowImpl::login ( ) |
288 | { | 151 | { |
289 | const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); | 152 | const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); |
290 | const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); | 153 | const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); |
291 | bool ok; | ||
292 | 154 | ||
293 | if ( !user || !user [0] ) | 155 | if ( !user || !user [0] ) |
294 | return; | 156 | return; |
295 | if ( !pass ) | 157 | if ( !pass ) |
296 | pass = ""; | 158 | pass = ""; |
297 | 159 | ||
298 | #if defined( USEPAM ) | 160 | if ( lApp-> checkPassword ( user, pass )) { |
299 | ok = pwcheck_PAM ( user, pass ); | 161 | Config cfg ( "opie-login" ); |
300 | #else | 162 | cfg. setGroup ( "General" ); |
301 | ok = pwcheck_Unix ( user, pass ); | 163 | cfg. writeEntry ( "LastLogin", user ); |
302 | #endif | 164 | cfg. write ( ); |
303 | 165 | ||
304 | if ( ok ) { | 166 | lApp-> setLoginAs ( user ); |
305 | if ( changeIdentity ( user )) { | 167 | |
306 | // Draw a big wait icon, the image can be altered in later revisions | 168 | // Draw a big wait icon, the image can be altered in later revisions |
307 | QWidget *d = QApplication::desktop ( ); | 169 | m_input-> hideInputMethod ( ); |
308 | m_input-> hideInputMethod ( ); | 170 | new WaitLogo ( ); |
309 | 171 | // WaitLogo::showEvent() calls qApp-> quit() | |
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 | |||
319 | char *opie = ::getenv ( "OPIEDIR" ); | ||
320 | char *arg = new char [::strlen ( opie ) + 8 + 1]; | ||
321 | |||
322 | ::strcpy ( arg, opie ); | ||
323 | ::strcat ( arg, "/bin/qpe" ); | ||
324 | |||
325 | // start qpe via a login shell | ||
326 | ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); | ||
327 | |||
328 | w-> hide ( ); | ||
329 | delete w; | ||
330 | |||
331 | QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE\n(%1)." ). arg ( arg )); | ||
332 | delete [] arg; | ||
333 | |||
334 | restart ( ); | ||
335 | } | ||
336 | else { | ||
337 | QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" )); | ||
338 | restart ( ); | ||
339 | } | ||
340 | } | 172 | } |
341 | else { | 173 | else { |
342 | QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); | 174 | QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); |
343 | m_password-> clear ( ); | 175 | m_password-> clear ( ); |
344 | } | 176 | } |
345 | } | 177 | } |