-rw-r--r-- | core/opie-login/main.cpp | 30 | ||||
-rw-r--r-- | core/opie-login/opie-login.conffiles | 1 |
2 files changed, 24 insertions, 7 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index d95a59b..7dcb5f6 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp | |||
@@ -41,52 +41,54 @@ | |||
41 | #include <string.h> | 41 | #include <string.h> |
42 | 42 | ||
43 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/qcopenvelope_qws.h> | 44 | #include <qpe/qcopenvelope_qws.h> |
45 | #include <qpe/qpestyle.h> | 45 | #include <qpe/qpestyle.h> |
46 | #include <qpe/power.h> | 46 | #include <qpe/power.h> |
47 | #include <qpe/config.h> | 47 | #include <qpe/config.h> |
48 | 48 | ||
49 | #include <opie/odevice.h> | 49 | #include <opie/odevice.h> |
50 | 50 | ||
51 | #include <qwindowsystem_qws.h> | 51 | #include <qwindowsystem_qws.h> |
52 | #include <qwsmouse_qws.h> | 52 | #include <qwsmouse_qws.h> |
53 | #include <qmessagebox.h> | 53 | #include <qmessagebox.h> |
54 | #include <qlabel.h> | 54 | #include <qlabel.h> |
55 | #include <qtimer.h> | 55 | #include <qtimer.h> |
56 | #include <qfile.h> | 56 | #include <qfile.h> |
57 | #include <qtextstream.h> | ||
57 | 58 | ||
58 | #include "loginapplication.h" | 59 | #include "loginapplication.h" |
59 | #include "loginwindowimpl.h" | 60 | #include "loginwindowimpl.h" |
60 | #include "calibrate.h" | 61 | #include "calibrate.h" |
61 | 62 | ||
62 | using namespace Opie; | 63 | using namespace Opie; |
63 | 64 | ||
64 | int login_main ( int argc, char **argv, pid_t ppid ); | 65 | int login_main ( int argc, char **argv, pid_t ppid ); |
65 | void sigterm ( int sig ); | 66 | void sigterm ( int sig ); |
66 | void sigint ( int sig ); | 67 | void sigint ( int sig ); |
67 | void exit_closelog ( ); | 68 | void exit_closelog ( ); |
68 | 69 | ||
69 | static struct option long_options [] = { | 70 | static struct option long_options [] = { |
70 | { "autologin", 1, 0, 'a' }, | 71 | { "autologin", 1, 0, 'a' }, |
71 | { 0, 0, 0, 0 } | 72 | { 0, 0, 0, 0 } |
72 | }; | 73 | }; |
73 | 74 | ||
74 | 75 | ||
75 | int main ( int argc, char **argv ) | 76 | int main ( int argc, char **argv ) |
76 | { | 77 | { |
78 | int userExited = 0; | ||
77 | pid_t ppid = ::getpid ( ); | 79 | pid_t ppid = ::getpid ( ); |
78 | 80 | ||
79 | if ( ::geteuid ( ) != 0 ) { | 81 | if ( ::geteuid ( ) != 0 ) { |
80 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | 82 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); |
81 | return 1; | 83 | return 1; |
82 | } | 84 | } |
83 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and | 85 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and |
84 | ::setuid ( 0 ); // messes up things like config files | 86 | ::setuid ( 0 ); // messes up things like config files |
85 | 87 | ||
86 | char *autolog = 0; | 88 | char *autolog = 0; |
87 | int c; | 89 | int c; |
88 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { | 90 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { |
89 | switch ( c ) { | 91 | switch ( c ) { |
90 | case 'a': | 92 | case 'a': |
91 | autolog = optarg; | 93 | autolog = optarg; |
92 | break; | 94 | break; |
@@ -124,88 +126,102 @@ int main ( int argc, char **argv ) | |||
124 | 126 | ||
125 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | 127 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } |
126 | 128 | ||
127 | LoginApplication::logout ( ); | 129 | LoginApplication::logout ( ); |
128 | 130 | ||
129 | if (( ::time ( 0 ) - started ) < 3 ) { | 131 | if (( ::time ( 0 ) - started ) < 3 ) { |
130 | if ( autolog ) { | 132 | if ( autolog ) { |
131 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); | 133 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); |
132 | autolog = 0; | 134 | autolog = 0; |
133 | } | 135 | } |
134 | else { | 136 | else { |
135 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); | 137 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); |
136 | break; | 138 | break; |
137 | } | 139 | } |
138 | } | 140 | } |
139 | int killedbysig = 0; | 141 | int killedbysig = 0; |
142 | userExited=0; | ||
143 | if (WIFEXITED(status)!=0 ) { | ||
144 | if (WEXITSTATUS(status)==137) { | ||
145 | userExited=1; | ||
146 | } | ||
147 | } | ||
140 | 148 | ||
141 | if ( WIFSIGNALED( status )) { | 149 | if ( WIFSIGNALED( status )) { |
142 | switch ( WTERMSIG( status )) { | 150 | switch ( WTERMSIG( status )) { |
143 | case SIGINT : | ||
144 | case SIGTERM: | 151 | case SIGTERM: |
152 | case SIGINT : | ||
145 | case SIGKILL: | 153 | case SIGKILL: |
146 | break; | 154 | break; |
147 | 155 | ||
148 | default : | 156 | default : |
149 | killedbysig = WTERMSIG( status ); | 157 | killedbysig = WTERMSIG( status ); |
150 | break; | 158 | break; |
151 | } | 159 | } |
152 | } | 160 | } |
153 | if ( killedbysig ) { // qpe was killed by an uncaught signal | 161 | if ( killedbysig ) { // qpe was killed by an uncaught signal |
154 | qApp = 0; | 162 | qApp = 0; |
155 | 163 | ||
156 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); | 164 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); |
157 | 165 | ||
158 | QWSServer::setDesktopBackground ( QImage ( )); | 166 | QWSServer::setDesktopBackground ( QImage ( )); |
159 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); | 167 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); |
160 | app-> setFont ( QFont ( "Helvetica", 10 )); | 168 | app-> setFont ( QFont ( "Helvetica", 10 )); |
161 | app-> setStyle ( new QPEStyle ( )); | 169 | app-> setStyle ( new QPEStyle ( )); |
162 | 170 | ||
163 | const char *sig = ::strsignal ( killedbysig ); | 171 | const char *sig = ::strsignal ( killedbysig ); |
164 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); | 172 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); |
165 | l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); | 173 | l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); |
166 | l-> setAlignment ( Qt::AlignCenter ); | 174 | l-> setAlignment ( Qt::AlignCenter ); |
167 | l-> move ( 0, 0 ); | 175 | l-> move ( 0, 0 ); |
168 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 176 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |
169 | l-> show ( ); | 177 | l-> show ( ); |
170 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); | 178 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); |
171 | app-> exec ( ); | 179 | app-> exec ( ); |
172 | delete app; | 180 | delete app; |
173 | qApp = 0; | 181 | qApp = 0; |
174 | } | 182 | } |
175 | } | 183 | } |
176 | else { | 184 | else { |
177 | if ( !autolog ) { | 185 | if ( !autolog ) { |
178 | Config cfg ( "opie-login" ); | 186 | QString confFile=QPEApplication::qpeDir() + "/etc/opie-login.conf"; |
187 | Config cfg ( confFile, Config::File ); | ||
179 | cfg. setGroup ( "General" ); | 188 | cfg. setGroup ( "General" ); |
180 | QString user = cfg. readEntry ( "AutoLogin" ); | 189 | QString user = cfg. readEntry ( "AutoLogin" ); |
181 | 190 | ||
182 | if ( !user. isEmpty ( )) | 191 | if ( !user. isEmpty ( )) |
183 | autolog = ::strdup ( user. latin1 ( )); | 192 | autolog = ::strdup ( user. latin1 ( )); |
184 | } | 193 | } |
185 | 194 | ||
186 | if ( autolog ) { | 195 | if ( autolog && !userExited ) { |
187 | LoginApplication::setLoginAs ( autolog ); | 196 | |
197 | QWSServer::setDesktopBackground( QImage() ); | ||
198 | ODevice::inst ( )-> setDisplayStatus ( true ); | ||
199 | ODevice::inst ( )-> setSoftSuspend ( false ); | ||
200 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | ||
201 | LoginApplication::setLoginAs ( autolog ); | ||
202 | |||
188 | 203 | ||
189 | if ( LoginApplication::changeIdentity ( )) | 204 | if ( LoginApplication::changeIdentity ( )) |
190 | ::exit ( LoginApplication::login ( )); | 205 | ::exit ( LoginApplication::login ( )); |
191 | else | 206 | else |
192 | ::exit ( 0 ); | 207 | ::exit ( 0 ); |
193 | } | 208 | } |
194 | else | 209 | else { |
195 | ::exit ( login_main ( argc, argv, ppid )); | 210 | ::exit ( login_main ( argc, argv, ppid )); |
211 | } | ||
196 | } | 212 | } |
197 | } | 213 | } |
198 | return 0; | 214 | return 0; |
199 | } | 215 | } |
200 | 216 | ||
201 | void sigterm ( int /*sig*/ ) | 217 | void sigterm ( int /*sig*/ ) |
202 | { | 218 | { |
203 | ::exit ( 0 ); | 219 | ::exit ( 0 ); |
204 | } | 220 | } |
205 | 221 | ||
206 | 222 | ||
207 | void exit_closelog ( ) | 223 | void exit_closelog ( ) |
208 | { | 224 | { |
209 | ::closelog ( ); | 225 | ::closelog ( ); |
210 | } | 226 | } |
211 | 227 | ||
@@ -342,28 +358,28 @@ int login_main ( int argc, char **argv, pid_t ppid ) | |||
342 | 358 | ||
343 | LoginWindowImpl *lw = new LoginWindowImpl ( ); | 359 | LoginWindowImpl *lw = new LoginWindowImpl ( ); |
344 | app-> setMainWidget ( lw ); | 360 | app-> setMainWidget ( lw ); |
345 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 361 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |
346 | lw-> show ( ); | 362 | lw-> show ( ); |
347 | 363 | ||
348 | int rc = app-> exec ( ); | 364 | int rc = app-> exec ( ); |
349 | 365 | ||
350 | ODevice::inst ( )-> setSoftSuspend ( false ); | 366 | ODevice::inst ( )-> setSoftSuspend ( false ); |
351 | 367 | ||
352 | if ( app-> loginAs ( )) { | 368 | if ( app-> loginAs ( )) { |
353 | if ( app-> changeIdentity ( )) { | 369 | if ( app-> changeIdentity ( )) { |
354 | app-> login ( ); | 370 | app-> login ( ); |
355 | 371 | ||
356 | // if login succeeds, it never comes back | 372 | // if login succeeds, it never comes back |
357 | 373 | ||
358 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start OPIE." )); | 374 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); |
359 | rc = 1; | 375 | rc = 1; |
360 | } | 376 | } |
361 | else { | 377 | else { |
362 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); | 378 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); |
363 | rc = 2; | 379 | rc = 2; |
364 | } | 380 | } |
365 | 381 | ||
366 | } | 382 | } |
367 | return rc; | 383 | return rc; |
368 | } | 384 | } |
369 | 385 | ||
diff --git a/core/opie-login/opie-login.conffiles b/core/opie-login/opie-login.conffiles new file mode 100644 index 0000000..90645ee --- a/dev/null +++ b/core/opie-login/opie-login.conffiles | |||
@@ -0,0 +1 @@ | |||
/opt/QtPalmtop/etc/opie-login.conf | |||