summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/opie-login/main.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index 3f1077c..b76d2c7 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -63,60 +63,65 @@ void sigterm ( int sig );
63void sigint ( int sig ); 63void sigint ( int sig );
64void exit_closelog ( ); 64void exit_closelog ( );
65 65
66int main ( int argc, char **argv ) 66int main ( int argc, char **argv )
67{ 67{
68 int userExited = 0; 68 int userExited = 0;
69 pid_t ppid = ::getpid ( ); 69 pid_t ppid = ::getpid ( );
70 70
71 if ( ::geteuid ( ) != 0 ) { 71 if ( ::geteuid ( ) != 0 ) {
72 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)\n", argv [0] ); 72 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)\n", argv [0] );
73 return 1; 73 return 1;
74 } 74 }
75 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and 75 /*!
76 ::setuid ( 0 ); // messes up things like config files 76 * @bug
77 77 * Qte does not really like being set UID root. This is
78 //struct rlimit rl; 78 * largely because we do almost everything on config files
79 //::getrlimit ( RLIMIT_NOFILE, &rl ); 79 * in root context. So if you even want to use opie-login
80 80 * you are in for a world of hurt unless someone at least
81 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 81 * scrubs the settings area and the PIM apps to make sure that
82 // ::close ( i ); 82 * they are covered regarding perms and users.
83 */
84 if ( ::getuid ( ) != 0 )
85 ::setuid ( 0 );
83 86
84 ::setpgid ( 0, 0 ); 87 ::setpgid ( 0, 0 );
85 ::setsid ( ); 88 ::setsid ( );
86 89
87 ::signal ( SIGTERM, sigterm ); 90 ::signal ( SIGTERM, sigterm );
88 ::signal ( SIGINT, sigterm ); 91 ::signal ( SIGINT, sigterm );
89 92
90 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 93 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
91 ::atexit ( exit_closelog ); 94 ::atexit ( exit_closelog );
92 95
93 const char* autolog = 0; 96 const char* autolog = 0;
94 Config c( "opie-login" ); 97 Config c( "opie-login" );
95 c.setGroup( "autologin" ); 98 c.setGroup( "autologin" );
96 QString entry = c.readEntry( "user", "" ); 99 QString entry = c.readEntry( "user", "" );
97 if ( !entry.isEmpty() ) autolog = ::strdup( (const char*) entry ); 100 if ( !entry.isEmpty() )
101 autolog = ::strdup( (const char*) entry );
98 102
99 while ( true ) { 103 while ( true ) {
100 pid_t child = ::fork ( ); 104 pid_t child = ::fork ( );
101 105
102 if ( child < 0 ) { 106 if ( child < 0 ) {
103 ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); 107 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
104 break; 108 break;
105 } 109 }
106 else if ( child > 0 ) { 110 else if ( child > 0 ) {
107 int status = 0; 111 int status = 0;
108 time_t started = ::time ( 0 ); 112 time_t started = ::time ( 0 );
109 113
110 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 114 while ( ::waitpid ( child, &status, 0 ) < 0 )
115 ;
111 116
112 LoginApplication::logout ( ); 117 LoginApplication::logout ( );
113 118
114 if (( ::time ( 0 ) - started ) < 3 ) { 119 if (( ::time ( 0 ) - started ) < 3 ) {
115 if ( autolog ) { 120 if ( autolog ) {
116 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); 121 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
117 autolog = 0; 122 autolog = 0;
118 } 123 }
119 else { 124 else {
120 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); 125 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
121 break; 126 break;
122 } 127 }
@@ -171,31 +176,29 @@ int main ( int argc, char **argv )
171 else { 176 else {
172 if ( !autolog ) { 177 if ( !autolog ) {
173 QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf"; 178 QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf";
174 Config cfg ( confFile, Config::File ); 179 Config cfg ( confFile, Config::File );
175 cfg. setGroup ( "General" ); 180 cfg. setGroup ( "General" );
176 QString user = cfg. readEntry ( "AutoLogin" ); 181 QString user = cfg. readEntry ( "AutoLogin" );
177 182
178 if ( !user. isEmpty ( )) 183 if ( !user. isEmpty ( ))
179 autolog = ::strdup ( user. latin1 ( )); 184 autolog = ::strdup ( user. latin1 ( ));
180 } 185 }
181 186
182 if ( autolog && !userExited ) { 187 if ( autolog && !userExited ) {
183
184 QWSServer::setDesktopBackground( QImage() ); 188 QWSServer::setDesktopBackground( QImage() );
185 ODevice::inst()->setDisplayStatus( true ); 189 ODevice::inst()->setDisplayStatus( true );
186 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 190 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
187 LoginApplication::setLoginAs( autolog ); 191 LoginApplication::setLoginAs( autolog );
188 192
189
190 if ( LoginApplication::changeIdentity ( )) 193 if ( LoginApplication::changeIdentity ( ))
191 ::exit ( LoginApplication::login ( )); 194 ::exit ( LoginApplication::login ( ));
192 else 195 else
193 ::exit ( 0 ); 196 ::exit ( 0 );
194 } 197 }
195 else { 198 else {
196 ::exit ( login_main ( argc, argv, ppid )); 199 ::exit ( login_main ( argc, argv, ppid ));
197 } 200 }
198 } 201 }
199 } 202 }
200 return 0; 203 return 0;
201} 204}
@@ -236,36 +239,35 @@ public:
236 { 239 {
237 switch ( level ) { 240 switch ( level ) {
238 case 0: 241 case 0:
239 if ( backlight() > 1 ) 242 if ( backlight() > 1 )
240 setBacklight( 1 ); // lowest non-off 243 setBacklight( 1 ); // lowest non-off
241 return true; 244 return true;
242 break; 245 break;
243 case 1: 246 case 1:
244 setBacklight( 0 ); // off 247 setBacklight( 0 ); // off
245 return true; 248 return true;
246 break; 249 break;
247 case 2: 250 case 2:
251 default:
248 // We're going to suspend the whole machine 252 // We're going to suspend the whole machine
249 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 253 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
250 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 254 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
251 return true; 255 return true;
252 } 256 }
253 break; 257 break;
254 } 258 }
255 return false; 259 return false;
256 } 260 }
257 261
258private:
259public:
260 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) 262 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
261 { 263 {
262 int v [4]; 264 int v [4];
263 265
264 v [ 0 ] = QMAX( 1000 * i1, 100 ); 266 v [ 0 ] = QMAX( 1000 * i1, 100 );
265 v [ 1 ] = QMAX( 1000 * i2, 100 ); 267 v [ 1 ] = QMAX( 1000 * i2, 100 );
266 v [ 2 ] = QMAX( 1000 * i3, 100 ); 268 v [ 2 ] = QMAX( 1000 * i3, 100 );
267 v [ 3 ] = 0; 269 v [ 3 ] = 0;
268 270
269 if ( !i1 && !i2 && !i3 ) 271 if ( !i1 && !i2 && !i3 )
270 QWSServer::setScreenSaverInterval ( 0 ); 272 QWSServer::setScreenSaverInterval ( 0 );
271 else 273 else
@@ -280,84 +282,84 @@ public:
280 return m_backlight_bright; 282 return m_backlight_bright;
281 } 283 }
282 284
283 void setBacklight ( int bright ) 285 void setBacklight ( int bright )
284 { 286 {
285 if ( bright == -3 ) { 287 if ( bright == -3 ) {
286 // Forced on 288 // Forced on
287 m_backlight_forcedoff = false; 289 m_backlight_forcedoff = false;
288 bright = -1; 290 bright = -1;
289 } 291 }
290 if ( m_backlight_forcedoff && bright != -2 ) 292 if ( m_backlight_forcedoff && bright != -2 )
291 return ; 293 return ;
294
292 if ( bright == -2 ) { 295 if ( bright == -2 ) {
293 // Toggle between off and on 296 // Toggle between off and on
294 bright = m_backlight_bright ? 0 : -1; 297 bright = m_backlight_bright ? 0 : -1;
295 m_backlight_forcedoff = !bright; 298 m_backlight_forcedoff = !bright;
296 } 299 }
297 300
298 m_backlight_bright = bright; 301 m_backlight_bright = bright;
299 302
300 bright = backlight ( ); 303 bright = backlight ( );
301 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 304 ODevice::inst ( ) -> setDisplayBrightness ( bright );
302 305
303 m_backlight_bright = bright; 306 m_backlight_bright = bright;
304 } 307 }
305 308
306private: 309private:
307 bool m_lcd_status; 310 bool m_lcd_status;
308
309 int m_backlight_bright; 311 int m_backlight_bright;
310 bool m_backlight_forcedoff; 312 bool m_backlight_forcedoff;
311}; 313};
312 314
313 315
314int login_main ( int argc, char **argv, pid_t ppid ) 316int login_main ( int argc, char **argv, pid_t ppid )
315{ 317{
316 QWSServer::setDesktopBackground( QImage() ); 318 QWSServer::setDesktopBackground( QImage() );
317 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 319 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
318 320
319 app-> setFont ( QFont ( "Helvetica", 10 )); 321 app-> setFont ( QFont ( "Helvetica", 10 ));
320 app-> setStyle ( new QPEStyle ( )); 322 app-> setStyle ( new QPEStyle ( ));
321 323
322 if ( QWSServer::mouseHandler() && 324 if ( QWSServer::mouseHandler() &&
323 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { 325 QWSServer::mouseHandler()-> inherits("QCalibratedMouseHandler") )
326 {
324 if ( !QFile::exists ( "/etc/pointercal" )) { 327 if ( !QFile::exists ( "/etc/pointercal" )) {
325 // Make sure calibration widget starts on top. 328 // Make sure calibration widget starts on top.
326 Calibrate *cal = new Calibrate; 329 Calibrate *cal = new Calibrate;
327 cal-> exec ( ); 330 cal-> exec ( );
328 delete cal; 331 delete cal;
329 } 332 }
330 } 333 }
331 334
332 LoginScreenSaver *saver = new LoginScreenSaver; 335 LoginScreenSaver *saver = new LoginScreenSaver;
333 336
334 saver-> setIntervals ( ); 337 saver-> setIntervals ( );
335 QWSServer::setScreenSaver ( saver ); 338 QWSServer::setScreenSaver ( saver );
336 saver-> restore ( ); 339 saver-> restore ( );
337 340
338
339 LoginWindowImpl *lw = new LoginWindowImpl ( ); 341 LoginWindowImpl *lw = new LoginWindowImpl ( );
340 app-> setMainWidget ( lw ); 342 app-> setMainWidget ( lw );
341 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 343 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ),
344 app-> desktop ( )-> height ( ));
342 lw-> show ( ); 345 lw-> show ( );
343 346
344 int rc = app-> exec ( ); 347 int rc = app-> exec ( );
345 348
346 if ( app-> loginAs ( )) { 349 if ( app-> loginAs ( )) {
347 if ( app-> changeIdentity ( )) { 350 if ( app-> changeIdentity ( )) {
348 app-> login ( ); 351 app-> login ( );
349
350 // if login succeeds, it never comes back 352 // if login succeeds, it never comes back
351 353 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ),
352 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); 354 LoginWindowImpl::tr( "Could not start Opie." ));
353 rc = 1; 355 rc = 1;
354 } 356 }
355 else { 357 else {
356 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); 358 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ),
359 LoginWindowImpl::tr( "Could not switch to new user identity" ));
357 rc = 2; 360 rc = 2;
358 } 361 }
359
360 } 362 }
361 return rc; 363 return rc;
362} 364}
363 365