summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/loginwindowimpl.cpp3
-rw-r--r--core/opie-login/main.cpp13
2 files changed, 8 insertions, 8 deletions
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp
index f24ebb3..63baaa6 100644
--- a/core/opie-login/loginwindowimpl.cpp
+++ b/core/opie-login/loginwindowimpl.cpp
@@ -1,323 +1,326 @@
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 12
13#include <qpe/qcopenvelope_qws.h> 13#include <qpe/qcopenvelope_qws.h>
14 14
15#include <opie/odevice.h> 15#include <opie/odevice.h>
16 16
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#include <signal.h>
24 24
25#ifdef USEPAM 25#ifdef USEPAM
26extern "C" { 26extern "C" {
27#include <security/pam_appl.h> 27#include <security/pam_appl.h>
28} 28}
29#else 29#else
30#include <crypt.h> 30#include <crypt.h>
31#include <shadow.h> 31#include <shadow.h>
32#endif 32#endif
33 33
34#include "loginwindowimpl.h" 34#include "loginwindowimpl.h"
35#include "inputmethods.h" 35#include "inputmethods.h"
36 36
37using namespace Opie;
38
39
37LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) 40LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose )
38{ 41{
39 QPopupMenu *pop = new QPopupMenu ( this ); 42 QPopupMenu *pop = new QPopupMenu ( this );
40 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); 43 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( )));
41 pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); 44 pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( )));
42 m_menu-> setPopup ( pop ); 45 m_menu-> setPopup ( pop );
43 46
44 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); 47 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 );
45 m_input = new InputMethods ( m_taskbar ); 48 m_input = new InputMethods ( m_taskbar );
46 lay-> addWidget ( m_input ); 49 lay-> addWidget ( m_input );
47 lay-> addStretch ( 10 ); 50 lay-> addStretch ( 10 );
48 51
49 setActiveWindow ( ); 52 setActiveWindow ( );
50 m_password-> setFocus ( ); 53 m_password-> setFocus ( );
51 54
52 m_user-> insertStringList ( getAllUsers ( )); 55 m_user-> insertStringList ( getAllUsers ( ));
53 56
54 QTimer::singleShot ( 0, this, SLOT( showIM ( ))); 57 QTimer::singleShot ( 0, this, SLOT( showIM ( )));
55 58
56 QString opiedir = ::getenv ( "OPIEDIR" ); 59 QString opiedir = ::getenv ( "OPIEDIR" );
57 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); 60 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" );
58 61
59 if ( !bgpix. isNull ( )) 62 if ( !bgpix. isNull ( ))
60 setBackgroundPixmap ( bgpix ); 63 setBackgroundPixmap ( bgpix );
61 64
62 m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); 65 m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( )));
63} 66}
64 67
65LoginWindowImpl::~LoginWindowImpl ( ) 68LoginWindowImpl::~LoginWindowImpl ( )
66{ 69{
67} 70}
68 71
69void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) 72void LoginWindowImpl::keyPressEvent ( QKeyEvent *e )
70{ 73{
71 switch ( e-> key ( )) { 74 switch ( e-> key ( )) {
72 case HardKey_Suspend: suspend ( ); 75 case HardKey_Suspend: suspend ( );
73 break; 76 break;
74 case HardKey_Backlight: backlight ( ); 77 case HardKey_Backlight: backlight ( );
75 break; 78 break;
76 default: e-> ignore ( ); 79 default: e-> ignore ( );
77 break; 80 break;
78 } 81 }
79 LoginWindow::keyPressEvent ( e ); 82 LoginWindow::keyPressEvent ( e );
80} 83}
81 84
82 85
83void LoginWindowImpl::toggleEchoMode ( bool t ) 86void LoginWindowImpl::toggleEchoMode ( bool t )
84{ 87{
85 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); 88 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password );
86} 89}
87 90
88QStringList LoginWindowImpl::getAllUsers ( ) 91QStringList LoginWindowImpl::getAllUsers ( )
89{ 92{
90 struct passwd *pwd; 93 struct passwd *pwd;
91 QStringList sl; 94 QStringList sl;
92 95
93 while (( pwd = ::getpwent ( ))) { 96 while (( pwd = ::getpwent ( ))) {
94 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) 97 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 ))
95 sl << QString ( pwd-> pw_name ); 98 sl << QString ( pwd-> pw_name );
96 } 99 }
97 100
98 ::endpwent ( ); 101 ::endpwent ( );
99 102
100 return sl; 103 return sl;
101} 104}
102 105
103void LoginWindowImpl::showIM ( ) 106void LoginWindowImpl::showIM ( )
104{ 107{
105 m_input-> showInputMethod ( ); 108 m_input-> showInputMethod ( );
106} 109}
107 110
108void LoginWindowImpl::restart ( ) 111void LoginWindowImpl::restart ( )
109{ 112{
110 qApp-> quit ( ); 113 qApp-> quit ( );
111} 114}
112 115
113void LoginWindowImpl::quit ( ) 116void LoginWindowImpl::quit ( )
114{ 117{
115 qApp-> quit ( ); 118 qApp-> quit ( );
116 ::kill ( ::getppid ( ), SIGUSR1 ); 119 ::kill ( ::getppid ( ), SIGUSR1 );
117} 120}
118 121
119void LoginWindowImpl::suspend ( ) 122void LoginWindowImpl::suspend ( )
120{ 123{
121 ODevice::inst ( )-> suspend ( ); 124 ODevice::inst ( )-> suspend ( );
122 125
123 QCopEnvelope e("QPE/System", "setBacklight(int)"); 126 QCopEnvelope e("QPE/System", "setBacklight(int)");
124 e << -3; // Force on 127 e << -3; // Force on
125} 128}
126 129
127void LoginWindowImpl::backlight ( ) 130void LoginWindowImpl::backlight ( )
128{ 131{
129 QCopEnvelope e("QPE/System", "setBacklight(int)"); 132 QCopEnvelope e("QPE/System", "setBacklight(int)");
130 e << -2; // toggle 133 e << -2; // toggle
131} 134}
132 135
133#ifdef USEPAM 136#ifdef USEPAM
134 137
135static const char *_PAM_SERVICE = "xdm"; 138static const char *_PAM_SERVICE = "xdm";
136static const char *PAM_password; 139static const char *PAM_password;
137 140
138typedef const struct pam_message pam_message_type; 141typedef const struct pam_message pam_message_type;
139 142
140static int PAM_conv( int, pam_message_type **, struct pam_response **, void * ); 143static int PAM_conv( int, pam_message_type **, struct pam_response **, void * );
141 144
142static struct pam_conv PAM_conversation = { 145static struct pam_conv PAM_conversation = {
143 &PAM_conv, 146 &PAM_conv,
144 NULL 147 NULL
145}; 148};
146 149
147//---------------------------------------------------------------------------- 150//----------------------------------------------------------------------------
148 151
149static char *COPY_STRING( const char * s ) { 152static char *COPY_STRING( const char * s ) {
150 return (s) ? strdup(s) : (char *)NULL; 153 return (s) ? strdup(s) : (char *)NULL;
151} 154}
152 155
153#define GET_MEM if (reply) realloc(reply, size);\ 156#define GET_MEM if (reply) realloc(reply, size);\
154 else reply = (struct pam_response *)malloc(size); \ 157 else reply = (struct pam_response *)malloc(size); \
155 if (!reply) return PAM_CONV_ERR; \ 158 if (!reply) return PAM_CONV_ERR; \
156 size += sizeof(struct pam_response) 159 size += sizeof(struct pam_response)
157 160
158 161
159static int PAM_conv( int num_msg, pam_message_type **msg, 162static int PAM_conv( int num_msg, pam_message_type **msg,
160 struct pam_response **resp, void *) 163 struct pam_response **resp, void *)
161{ 164{
162 int count = 0, replies = 0; 165 int count = 0, replies = 0;
163 struct pam_response *reply = NULL; 166 struct pam_response *reply = NULL;
164 int size = sizeof(struct pam_response); 167 int size = sizeof(struct pam_response);
165 168
166 for( count = 0; count < num_msg; count++ ) { 169 for( count = 0; count < num_msg; count++ ) {
167 switch (msg[count]->msg_style) { 170 switch (msg[count]->msg_style) {
168 case PAM_PROMPT_ECHO_ON: 171 case PAM_PROMPT_ECHO_ON:
169 /* user name given to PAM already */ 172 /* user name given to PAM already */
170 return PAM_CONV_ERR; 173 return PAM_CONV_ERR;
171 174
172 case PAM_PROMPT_ECHO_OFF: 175 case PAM_PROMPT_ECHO_OFF:
173 /* wants password */ 176 /* wants password */
174 GET_MEM; 177 GET_MEM;
175 reply[replies].resp_retcode = PAM_SUCCESS; 178 reply[replies].resp_retcode = PAM_SUCCESS;
176 reply[replies].resp = COPY_STRING(PAM_password); 179 reply[replies].resp = COPY_STRING(PAM_password);
177 replies++; 180 replies++;
178 /* PAM frees resp */ 181 /* PAM frees resp */
179 break; 182 break;
180 case PAM_TEXT_INFO: 183 case PAM_TEXT_INFO:
181 break; 184 break;
182 default: 185 default:
183 /* unknown or PAM_ERROR_MSG */ 186 /* unknown or PAM_ERROR_MSG */
184 if (reply) free (reply); 187 if (reply) free (reply);
185 return PAM_CONV_ERR; 188 return PAM_CONV_ERR;
186 } 189 }
187 } 190 }
188 if (reply) *resp = reply; 191 if (reply) *resp = reply;
189 return PAM_SUCCESS; 192 return PAM_SUCCESS;
190} 193}
191 194
192 195
193static bool pwcheck_PAM( const char *user, const char *password ) 196static bool pwcheck_PAM( const char *user, const char *password )
194{ 197{
195 bool pw_correct = false; 198 bool pw_correct = false;
196 int pam_error; 199 int pam_error;
197 int pam_return = 0; 200 int pam_return = 0;
198 pam_handle_t *pamh = 0; 201 pam_handle_t *pamh = 0;
199 PAM_password = password; 202 PAM_password = password;
200 203
201 pam_error = pam_start( _PAM_SERVICE, user, &PAM_conversation, &pamh ); 204 pam_error = pam_start( _PAM_SERVICE, user, &PAM_conversation, &pamh );
202 if( pam_error == PAM_SUCCESS ) { 205 if( pam_error == PAM_SUCCESS ) {
203 pam_error = pam_authenticate( pamh, 0 ); 206 pam_error = pam_authenticate( pamh, 0 );
204 if( pam_error == PAM_SUCCESS ) { 207 if( pam_error == PAM_SUCCESS ) {
205 //-- password correct 208 //-- password correct
206 pw_correct = true; 209 pw_correct = true;
207 pam_return = PAM_SUCCESS; 210 pam_return = PAM_SUCCESS;
208 } else { 211 } else {
209 pam_return = pam_error; 212 pam_return = pam_error;
210 } 213 }
211 } else { 214 } else {
212 // cerr << "PAM error: " << pam_strerror( pamh, pam_error ) << endl; 215 // cerr << "PAM error: " << pam_strerror( pamh, pam_error ) << endl;
213 } 216 }
214 pam_end( pamh, pam_return ); 217 pam_end( pamh, pam_return );
215 return pw_correct; 218 return pw_correct;
216} 219}
217 220
218#else 221#else
219 222
220//---------------------------------------------------------------------------- 223//----------------------------------------------------------------------------
221 224
222static bool pwcheck_Unix( const char *user, const char *pass ) 225static bool pwcheck_Unix( const char *user, const char *pass )
223{ 226{
224 char *encrypted, *correct; 227 char *encrypted, *correct;
225 struct passwd *pw; 228 struct passwd *pw;
226 229
227 if ( !user || !pass ) 230 if ( !user || !pass )
228 return false; 231 return false;
229 232
230 pw = getpwnam ( user ); 233 pw = getpwnam ( user );
231 234
232 if ( !pw ) 235 if ( !pw )
233 return false; 236 return false;
234 237
235 if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) { 238 if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) {
236 struct spwd *sp = getspnam ( pw-> pw_name ); 239 struct spwd *sp = getspnam ( pw-> pw_name );
237 240
238 if ( !sp ) 241 if ( !sp )
239 return false; 242 return false;
240 243
241 correct = sp-> sp_pwdp; 244 correct = sp-> sp_pwdp;
242 } 245 }
243 else 246 else
244 correct = pw-> pw_passwd; 247 correct = pw-> pw_passwd;
245 248
246 if ( correct == 0 || correct[0] == '\0' ) 249 if ( correct == 0 || correct[0] == '\0' )
247 return true; 250 return true;
248 251
249 encrypted = crypt ( pass, correct ); 252 encrypted = crypt ( pass, correct );
250 return ( strcmp ( encrypted, correct ) == 0 ); 253 return ( strcmp ( encrypted, correct ) == 0 );
251} 254}
252 255
253#endif 256#endif
254 257
255 258
256bool LoginWindowImpl::changeIdentity ( const char *user ) 259bool LoginWindowImpl::changeIdentity ( const char *user )
257{ 260{
258 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; 261 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin";
259 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; 262 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin";
260 263
261 bool fail = false; 264 bool fail = false;
262 struct passwd *pw = getpwnam ( user ); 265 struct passwd *pw = getpwnam ( user );
263 266
264 fail |= ( pw == 0 ); 267 fail |= ( pw == 0 );
265 fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid )); 268 fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid ));
266 endgrent ( ); 269 endgrent ( );
267 fail |= ( setgid ( pw-> pw_gid )); 270 fail |= ( setgid ( pw-> pw_gid ));
268 fail |= ( setuid ( pw-> pw_uid )); 271 fail |= ( setuid ( pw-> pw_uid ));
269 272
270 fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" )); 273 fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" ));
271 274
272 fail |= ( setenv ( "HOME", pw-> pw_dir, 1 )); 275 fail |= ( setenv ( "HOME", pw-> pw_dir, 1 ));
273 fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 )); 276 fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 ));
274 fail |= ( setenv ( "USER", pw-> pw_name, 1 )); 277 fail |= ( setenv ( "USER", pw-> pw_name, 1 ));
275 fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 )); 278 fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 ));
276 fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); 279 fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 ));
277 280
278 return !fail; 281 return !fail;
279} 282}
280 283
281void LoginWindowImpl::login ( ) 284void LoginWindowImpl::login ( )
282{ 285{
283 const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); 286 const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( ));
284 const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); 287 const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( ));
285 bool ok; 288 bool ok;
286 289
287 if ( !user || !user [0] ) 290 if ( !user || !user [0] )
288 return; 291 return;
289 if ( !pass ) 292 if ( !pass )
290 pass = ""; 293 pass = "";
291 294
292#if defined( USEPAM ) 295#if defined( USEPAM )
293 ok = pwcheck_PAM ( user, pass ); 296 ok = pwcheck_PAM ( user, pass );
294#else 297#else
295 ok = pwcheck_Unix ( user, pass ); 298 ok = pwcheck_Unix ( user, pass );
296#endif 299#endif
297 300
298 if ( ok ) { 301 if ( ok ) {
299 if ( changeIdentity ( user )) { 302 if ( changeIdentity ( user )) {
300 char *opie = ::getenv ( "OPIEDIR" ); 303 char *opie = ::getenv ( "OPIEDIR" );
301 char *arg = new char [::strlen ( opie ) + 8 + 1]; 304 char *arg = new char [::strlen ( opie ) + 8 + 1];
302 305
303 ::strcpy ( arg, opie ); 306 ::strcpy ( arg, opie );
304 ::strcat ( arg, "/bin/qpe" ); 307 ::strcat ( arg, "/bin/qpe" );
305 308
306 // start qpe via a login shell 309 // start qpe via a login shell
307 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); 310 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 );
308 311
309 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE\n(%1)." ). arg ( arg )); 312 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE\n(%1)." ). arg ( arg ));
310 delete [] arg; 313 delete [] arg;
311 314
312 restart ( ); 315 restart ( );
313 } 316 }
314 else { 317 else {
315 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" )); 318 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" ));
316 restart ( ); 319 restart ( );
317 } 320 }
318 } 321 }
319 else { 322 else {
320 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); 323 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." ));
321 m_password-> clear ( ); 324 m_password-> clear ( );
322 } 325 }
323} 326}
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index 718009a..df9451d 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -1,224 +1,221 @@
1#include <sys/time.h> 1#include <sys/time.h>
2#include <sys/resource.h> 2#include <sys/resource.h>
3#include <unistd.h> 3#include <unistd.h>
4#include <syslog.h> 4#include <syslog.h>
5#include <sys/types.h> 5#include <sys/types.h>
6#include <sys/wait.h> 6#include <sys/wait.h>
7#include <stdio.h> 7#include <stdio.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <signal.h> 9#include <signal.h>
10 10
11#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
12#include <qpe/qcopenvelope_qws.h> 12#include <qpe/qcopenvelope_qws.h>
13#include <qpe/qpestyle.h> 13#include <qpe/qpestyle.h>
14#include <qpe/power.h> 14#include <qpe/power.h>
15 15
16#include <opie/odevice.h> 16#include <opie/odevice.h>
17 17
18#include <qwindowsystem_qws.h> 18#include <qwindowsystem_qws.h>
19#include <qfile.h> 19#include <qfile.h>
20 20
21#include "loginwindowimpl.h" 21#include "loginwindowimpl.h"
22#include "calibrate.h" 22#include "calibrate.h"
23 23
24using namespace Opie;
25
24int login_main ( int argc, char **argv ); 26int login_main ( int argc, char **argv );
25void sigusr1 ( int sig ); 27void sigusr1 ( int sig );
26void exit_closelog ( ); 28void exit_closelog ( );
27 29
28 30
29 31
30int main ( int argc, char **argv ) 32int main ( int argc, char **argv )
31{ 33{
32 if ( ::geteuid ( ) != 0 ) { 34 if ( ::geteuid ( ) != 0 ) {
33 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); 35 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] );
34 return 1; 36 return 1;
35 } 37 }
36 38
37 //struct rlimit rl; 39 //struct rlimit rl;
38 //::getrlimit ( RLIMIT_NOFILE, &rl ); 40 //::getrlimit ( RLIMIT_NOFILE, &rl );
39 41
40 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 42 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
41 // ::close ( i ); 43 // ::close ( i );
42 44
43 ::setpgid ( 0, 0 ); 45 ::setpgid ( 0, 0 );
44 ::setsid ( ); 46 ::setsid ( );
45 47
46 ::signal ( SIGUSR1, sigusr1 ); 48 ::signal ( SIGUSR1, sigusr1 );
47 49
48 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 50 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
49 ::atexit ( exit_closelog ); 51 ::atexit ( exit_closelog );
50 52
51 while ( true ) { 53 while ( true ) {
52 pid_t child = ::fork ( ); 54 pid_t child = ::fork ( );
53 55
54 if ( child < 0 ) { 56 if ( child < 0 ) {
55 ::syslog ( LOG_ERR, "Could not fork process" ); 57 ::syslog ( LOG_ERR, "Could not fork process" );
56 break; 58 break;
57 59
58 } 60 }
59 else if ( child > 0 ) { 61 else if ( child > 0 ) {
60 int status = 0; 62 int status = 0;
61 63
62 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 64 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
63 } 65 }
64 else { 66 else {
65 ::exit ( login_main ( argc, argv )); 67 ::exit ( login_main ( argc, argv ));
66 } 68 }
67 } 69 }
68 return 0; 70 return 0;
69} 71}
70 72
71void sigusr1 ( int /*sig*/ ) 73void sigusr1 ( int /*sig*/ )
72{ 74{
73 ::exit ( 0 ); 75 ::exit ( 0 );
74} 76}
75 77
76void exit_closelog ( ) 78void exit_closelog ( )
77{ 79{
78 ::closelog ( ); 80 ::closelog ( );
79} 81}
80 82
81 83
82class LoginScreenSaver : public QWSScreenSaver 84class LoginScreenSaver : public QWSScreenSaver
83{ 85{
84public: 86public:
85 LoginScreenSaver ( ) 87 LoginScreenSaver ( )
86 { 88 {
87 m_lcd_status = true; 89 m_lcd_status = true;
88 90
89 m_backlight_bright = -1; 91 m_backlight_bright = -1;
90 m_backlight_forcedoff = false; 92 m_backlight_forcedoff = false;
91 93
92 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 94 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
93 ODevice::inst ( ) -> setDisplayStatus ( true ); 95 ODevice::inst ( )-> setDisplayStatus ( true );
94 } 96 }
95 void restore() 97 void restore()
96 { 98 {
97 if ( !m_lcd_status ) // We must have turned it off 99 if ( !m_lcd_status ) // We must have turned it off
98 ODevice::inst ( ) -> setDisplayStatus ( true ); 100 ODevice::inst ( ) -> setDisplayStatus ( true );
99 101
100 setBacklight ( -1 ); 102 setBacklight ( -3 );
101 } 103 }
102 bool save( int level ) 104 bool save( int level )
103 { 105 {
104 switch ( level ) { 106 switch ( level ) {
105 case 0: 107 case 0:
106 if ( backlight() > 1 ) 108 if ( backlight() > 1 )
107 setBacklight( 1 ); // lowest non-off 109 setBacklight( 1 ); // lowest non-off
108 return true; 110 return true;
109 break; 111 break;
110 case 1: 112 case 1:
111 setBacklight( 0 ); // off 113 setBacklight( 0 ); // off
112 return true; 114 return true;
113 break; 115 break;
114 case 2: 116 case 2:
115 // We're going to suspend the whole machine 117 // We're going to suspend the whole machine
116 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 118 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
117 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 119 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
118 return true; 120 return true;
119 } 121 }
120 break; 122 break;
121 } 123 }
122 return false; 124 return false;
123 } 125 }
124 126
125private: 127private:
126public: 128public:
127 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) 129 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
128 { 130 {
129 int v [4]; 131 int v [4];
130 132
131 v [ 0 ] = QMAX( 1000 * i1, 100 ); 133 v [ 0 ] = QMAX( 1000 * i1, 100 );
132 v [ 1 ] = QMAX( 1000 * i2, 100 ); 134 v [ 1 ] = QMAX( 1000 * i2, 100 );
133 v [ 2 ] = QMAX( 1000 * i3, 100 ); 135 v [ 2 ] = QMAX( 1000 * i3, 100 );
134 v [ 3 ] = 0; 136 v [ 3 ] = 0;
135 137
136 if ( !i1 && !i2 && !i3 ) 138 if ( !i1 && !i2 && !i3 )
137 QWSServer::setScreenSaverInterval ( 0 ); 139 QWSServer::setScreenSaverInterval ( 0 );
138 else 140 else
139 QWSServer::setScreenSaverIntervals ( v ); 141 QWSServer::setScreenSaverIntervals ( v );
140 } 142 }
141 143
142 int backlight ( ) 144 int backlight ( )
143 { 145 {
144 if ( m_backlight_bright == -1 ) 146 if ( m_backlight_bright == -1 )
145 m_backlight_bright = 255; 147 m_backlight_bright = 255;
146 148
147 return m_backlight_bright; 149 return m_backlight_bright;
148 } 150 }
149 151
150 void setBacklight ( int bright ) 152 void setBacklight ( int bright )
151 { 153 {
152 if ( bright == -3 ) { 154 if ( bright == -3 ) {
153 // Forced on 155 // Forced on
154 m_backlight_forcedoff = false; 156 m_backlight_forcedoff = false;
155 bright = -1; 157 bright = -1;
156 } 158 }
157 if ( m_backlight_forcedoff && bright != -2 ) 159 if ( m_backlight_forcedoff && bright != -2 )
158 return ; 160 return ;
159 if ( bright == -2 ) { 161 if ( bright == -2 ) {
160 // Toggle between off and on 162 // Toggle between off and on
161 bright = m_backlight_bright ? 0 : -1; 163 bright = m_backlight_bright ? 0 : -1;
162 m_backlight_forcedoff = !bright; 164 m_backlight_forcedoff = !bright;
163 } 165 }
164 166
165 m_backlight_bright = bright; 167 m_backlight_bright = bright;
166 168
167 bright = backlight ( ); 169 bright = backlight ( );
168 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 170 ODevice::inst ( ) -> setDisplayBrightness ( bright );
169 171
170 m_backlight_bright = bright; 172 m_backlight_bright = bright;
171 } 173 }
172 174
173private: 175private:
174 bool m_lcd_status; 176 bool m_lcd_status;
175 177
176 int m_backlight_bright; 178 int m_backlight_bright;
177 bool m_backlight_forcedoff; 179 bool m_backlight_forcedoff;
178}; 180};
179 181
180 182
181 183
182int login_main ( int argc, char **argv ) 184int login_main ( int argc, char **argv )
183{ 185{
184 QWSServer::setDesktopBackground( QImage() ); 186 QWSServer::setDesktopBackground( QImage() );
185 QPEApplication app ( argc, argv, QApplication::GuiServer ); 187 QPEApplication app ( argc, argv, QApplication::GuiServer );
186 188
187 app. setFont ( QFont ( "Helvetica", 10 )); 189 app. setFont ( QFont ( "Helvetica", 10 ));
188 app. setStyle ( new QPEStyle ( )); 190 app. setStyle ( new QPEStyle ( ));
189 191
190 ODevice::inst ( )-> setSoftSuspend ( true ); 192 ODevice::inst ( )-> setSoftSuspend ( true );
191 193
192 {
193 QCopEnvelope e("QPE/System", "setBacklight(int)" );
194 e << -3; // Forced on
195 }
196
197#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 194#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
198 if ( !QFile::exists ( "/etc/pointercal" )) { 195 if ( !QFile::exists ( "/etc/pointercal" )) {
199 // Make sure calibration widget starts on top. 196 // Make sure calibration widget starts on top.
200 Calibrate *cal = new Calibrate; 197 Calibrate *cal = new Calibrate;
201 cal-> exec ( ); 198 cal-> exec ( );
202 delete cal; 199 delete cal;
203 } 200 }
204#endif 201#endif
205 202
206
207 LoginScreenSaver *saver = new LoginScreenSaver; 203 LoginScreenSaver *saver = new LoginScreenSaver;
208 204
209 saver-> setIntervals ( ); 205 saver-> setIntervals ( );
210 QWSServer::setScreenSaver ( saver ); 206 QWSServer::setScreenSaver ( saver );
207 saver-> restore ( );
211 208
212 209
213 LoginWindowImpl *lw = new LoginWindowImpl ( ); 210 LoginWindowImpl *lw = new LoginWindowImpl ( );
214 app. setMainWidget ( lw ); 211 app. setMainWidget ( lw );
215 lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( )); 212 lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( ));
216 lw-> show ( ); 213 lw-> show ( );
217 214
218 int rc = app. exec ( ); 215 int rc = app. exec ( );
219 216
220 ODevice::inst ( )-> setSoftSuspend ( false ); 217 ODevice::inst ( )-> setSoftSuspend ( false );
221 218
222 return rc; 219 return rc;
223} 220}
224 221