-rw-r--r-- | core/opie-login/loginapplication.cpp | 27 | ||||
-rw-r--r-- | core/opie-login/loginapplication.h | 27 | ||||
-rw-r--r-- | core/opie-login/loginwindowimpl.cpp | 29 | ||||
-rw-r--r-- | core/opie-login/loginwindowimpl.h | 27 | ||||
-rw-r--r-- | core/opie-login/main.cpp | 27 |
5 files changed, 136 insertions, 1 deletions
diff --git a/core/opie-login/loginapplication.cpp b/core/opie-login/loginapplication.cpp index cd58c47..103d63b 100644 --- a/core/opie-login/loginapplication.cpp +++ b/core/opie-login/loginapplication.cpp | |||
@@ -1,192 +1,219 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This file is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This file is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
17 | ..}^=.= = ; Public License for more details. | ||
18 | ++= -. .` .: | ||
19 | : = ...= . :.=- You should have received a copy of the GNU | ||
20 | -. .:....=;==+<; General Public License along with this file; | ||
21 | -_. . . )=. = see the file COPYING. If not, write to the | ||
22 | -- :-=` Free Software Foundation, Inc., | ||
23 | 59 Temple Place - Suite 330, | ||
24 | Boston, MA 02111-1307, USA. | ||
25 | |||
26 | */ | ||
27 | |||
1 | #include <pwd.h> | 28 | #include <pwd.h> |
2 | #include <grp.h> | 29 | #include <grp.h> |
3 | #include <unistd.h> | 30 | #include <unistd.h> |
4 | #include <stdlib.h> | 31 | #include <stdlib.h> |
5 | #include <signal.h> | 32 | #include <signal.h> |
6 | 33 | ||
7 | #ifdef USEPAM | 34 | #ifdef USEPAM |
8 | extern "C" { | 35 | extern "C" { |
9 | #include <security/pam_appl.h> | 36 | #include <security/pam_appl.h> |
10 | } | 37 | } |
11 | #else | 38 | #else |
12 | #include <crypt.h> | 39 | #include <crypt.h> |
13 | #include <shadow.h> | 40 | #include <shadow.h> |
14 | #endif | 41 | #endif |
15 | 42 | ||
16 | #include "loginapplication.h" | 43 | #include "loginapplication.h" |
17 | 44 | ||
18 | LoginApplication *lApp; | 45 | LoginApplication *lApp; |
19 | 46 | ||
20 | LoginApplication::LoginApplication ( int &argc, char **argv ) | 47 | LoginApplication::LoginApplication ( int &argc, char **argv ) |
21 | : QPEApplication ( argc, argv, GuiServer ) | 48 | : QPEApplication ( argc, argv, GuiServer ) |
22 | { | 49 | { |
23 | lApp = this; | 50 | lApp = this; |
24 | } | 51 | } |
25 | 52 | ||
26 | const char *LoginApplication::s_username = 0; | 53 | const char *LoginApplication::s_username = 0; |
27 | 54 | ||
28 | #ifdef USEPAM | 55 | #ifdef USEPAM |
29 | 56 | ||
30 | const char *LoginApplication::s_pam_password = 0; | 57 | const char *LoginApplication::s_pam_password = 0; |
31 | 58 | ||
32 | int LoginApplication::pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ) | 59 | int LoginApplication::pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ) |
33 | { | 60 | { |
34 | int replies = 0; | 61 | int replies = 0; |
35 | struct pam_response *reply = 0; | 62 | struct pam_response *reply = 0; |
36 | int size = sizeof( struct pam_response ); | 63 | int size = sizeof( struct pam_response ); |
37 | 64 | ||
38 | for ( int i = 0; i < num_msg; i++ ) { | 65 | for ( int i = 0; i < num_msg; i++ ) { |
39 | switch ( msg [i]-> msg_style ) { | 66 | switch ( msg [i]-> msg_style ) { |
40 | case PAM_PROMPT_ECHO_ON: // user name given to PAM already | 67 | case PAM_PROMPT_ECHO_ON: // user name given to PAM already |
41 | return PAM_CONV_ERR; | 68 | return PAM_CONV_ERR; |
42 | 69 | ||
43 | case PAM_PROMPT_ECHO_OFF: // wants password | 70 | case PAM_PROMPT_ECHO_OFF: // wants password |
44 | reply = (struct pam_response *) ::realloc ( reply, size ); | 71 | reply = (struct pam_response *) ::realloc ( reply, size ); |
45 | if ( !reply ) | 72 | if ( !reply ) |
46 | return PAM_CONV_ERR; | 73 | return PAM_CONV_ERR; |
47 | size += sizeof( struct pam_response ); | 74 | size += sizeof( struct pam_response ); |
48 | 75 | ||
49 | reply [replies]. resp_retcode = PAM_SUCCESS; | 76 | reply [replies]. resp_retcode = PAM_SUCCESS; |
50 | reply [replies]. resp = ::strdup ( s_pam_password ); | 77 | reply [replies]. resp = ::strdup ( s_pam_password ); |
51 | replies++; // PAM frees resp | 78 | replies++; // PAM frees resp |
52 | break; | 79 | break; |
53 | 80 | ||
54 | case PAM_TEXT_INFO: | 81 | case PAM_TEXT_INFO: |
55 | break; | 82 | break; |
56 | 83 | ||
57 | default: | 84 | default: |
58 | /* unknown or PAM_ERROR_MSG */ | 85 | /* unknown or PAM_ERROR_MSG */ |
59 | if ( reply ) | 86 | if ( reply ) |
60 | ::free ( reply ); | 87 | ::free ( reply ); |
61 | return PAM_CONV_ERR; | 88 | return PAM_CONV_ERR; |
62 | } | 89 | } |
63 | } | 90 | } |
64 | if ( reply ) | 91 | if ( reply ) |
65 | *resp = reply; | 92 | *resp = reply; |
66 | return PAM_SUCCESS; | 93 | return PAM_SUCCESS; |
67 | } | 94 | } |
68 | 95 | ||
69 | 96 | ||
70 | bool LoginApplication::checkPassword ( const char *user, const char *pass ) | 97 | bool LoginApplication::checkPassword ( const char *user, const char *pass ) |
71 | { | 98 | { |
72 | static struct pam_conv conv = { &LoginApplication::pam_helper, 0 }; | 99 | static struct pam_conv conv = { &LoginApplication::pam_helper, 0 }; |
73 | 100 | ||
74 | int pam_error; | 101 | int pam_error; |
75 | pam_handle_t *pamh = 0; | 102 | pam_handle_t *pamh = 0; |
76 | 103 | ||
77 | pam_error = ::pam_start( "xdm", user, &conv, &pamh ); | 104 | pam_error = ::pam_start( "xdm", user, &conv, &pamh ); |
78 | if ( pam_error == PAM_SUCCESS ) { | 105 | if ( pam_error == PAM_SUCCESS ) { |
79 | s_pam_password = pass; | 106 | s_pam_password = pass; |
80 | pam_error = ::pam_authenticate ( pamh, 0 ); | 107 | pam_error = ::pam_authenticate ( pamh, 0 ); |
81 | s_pam_password = 0; | 108 | s_pam_password = 0; |
82 | } | 109 | } |
83 | ::pam_end ( pamh, pam_error ); | 110 | ::pam_end ( pamh, pam_error ); |
84 | return ( pam_error == PAM_SUCCESS ); | 111 | return ( pam_error == PAM_SUCCESS ); |
85 | } | 112 | } |
86 | 113 | ||
87 | #else | 114 | #else |
88 | 115 | ||
89 | bool LoginApplication::checkPassword ( const char *user, const char *pass ) | 116 | bool LoginApplication::checkPassword ( const char *user, const char *pass ) |
90 | { | 117 | { |
91 | char *encrypted, *correct; | 118 | char *encrypted, *correct; |
92 | struct passwd *pw; | 119 | struct passwd *pw; |
93 | 120 | ||
94 | if ( !user || !pass ) | 121 | if ( !user || !pass ) |
95 | return false; | 122 | return false; |
96 | 123 | ||
97 | pw = ::getpwnam ( user ); | 124 | pw = ::getpwnam ( user ); |
98 | 125 | ||
99 | if ( !pw ) | 126 | if ( !pw ) |
100 | return false; | 127 | return false; |
101 | 128 | ||
102 | if (( ::strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( ::strcmp ( pw-> pw_passwd, "*" ) == 0 )) { | 129 | if (( ::strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( ::strcmp ( pw-> pw_passwd, "*" ) == 0 )) { |
103 | struct spwd *sp = ::getspnam ( pw-> pw_name ); | 130 | struct spwd *sp = ::getspnam ( pw-> pw_name ); |
104 | 131 | ||
105 | if ( !sp ) | 132 | if ( !sp ) |
106 | return false; | 133 | return false; |
107 | 134 | ||
108 | correct = sp-> sp_pwdp; | 135 | correct = sp-> sp_pwdp; |
109 | } | 136 | } |
110 | else | 137 | else |
111 | correct = pw-> pw_passwd; | 138 | correct = pw-> pw_passwd; |
112 | 139 | ||
113 | if ( correct == 0 || correct[0] == '\0' ) | 140 | if ( correct == 0 || correct[0] == '\0' ) |
114 | return true; | 141 | return true; |
115 | 142 | ||
116 | encrypted = ::crypt ( pass, correct ); | 143 | encrypted = ::crypt ( pass, correct ); |
117 | return ( ::strcmp ( encrypted, correct ) == 0 ); | 144 | return ( ::strcmp ( encrypted, correct ) == 0 ); |
118 | } | 145 | } |
119 | 146 | ||
120 | #endif | 147 | #endif |
121 | 148 | ||
122 | bool LoginApplication::changeIdentity ( ) | 149 | bool LoginApplication::changeIdentity ( ) |
123 | { | 150 | { |
124 | const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; | 151 | const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; |
125 | const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; | 152 | const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; |
126 | 153 | ||
127 | if ( !s_username ) | 154 | if ( !s_username ) |
128 | return false; | 155 | return false; |
129 | struct passwd *pw = ::getpwnam ( s_username ); | 156 | struct passwd *pw = ::getpwnam ( s_username ); |
130 | if ( !pw ) | 157 | if ( !pw ) |
131 | return false; | 158 | return false; |
132 | 159 | ||
133 | bool fail = false; | 160 | bool fail = false; |
134 | fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid )); | 161 | fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid )); |
135 | ::endgrent ( ); | 162 | ::endgrent ( ); |
136 | fail |= ( ::setgid ( pw-> pw_gid )); | 163 | fail |= ( ::setgid ( pw-> pw_gid )); |
137 | fail |= ( ::setuid ( pw-> pw_uid )); | 164 | fail |= ( ::setuid ( pw-> pw_uid )); |
138 | 165 | ||
139 | fail |= ( ::chdir ( pw-> pw_dir ) && ::chdir ( "/" )); | 166 | fail |= ( ::chdir ( pw-> pw_dir ) && ::chdir ( "/" )); |
140 | 167 | ||
141 | fail |= ( ::setenv ( "HOME", pw-> pw_dir, 1 )); | 168 | fail |= ( ::setenv ( "HOME", pw-> pw_dir, 1 )); |
142 | fail |= ( ::setenv ( "SHELL", pw-> pw_shell, 1 )); | 169 | fail |= ( ::setenv ( "SHELL", pw-> pw_shell, 1 )); |
143 | fail |= ( ::setenv ( "USER", pw-> pw_name, 1 )); | 170 | fail |= ( ::setenv ( "USER", pw-> pw_name, 1 )); |
144 | fail |= ( ::setenv ( "LOGNAME", pw-> pw_name, 1 )); | 171 | fail |= ( ::setenv ( "LOGNAME", pw-> pw_name, 1 )); |
145 | fail |= ( ::setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); | 172 | fail |= ( ::setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); |
146 | 173 | ||
147 | return !fail; | 174 | return !fail; |
148 | } | 175 | } |
149 | 176 | ||
150 | bool LoginApplication::login ( ) | 177 | bool LoginApplication::login ( ) |
151 | { | 178 | { |
152 | char *opie = ::getenv ( "OPIEDIR" ); | 179 | char *opie = ::getenv ( "OPIEDIR" ); |
153 | char *arg = new char [::strlen ( opie ) + 8 + 1]; | 180 | char *arg = new char [::strlen ( opie ) + 8 + 1]; |
154 | 181 | ||
155 | ::strcpy ( arg, opie ); | 182 | ::strcpy ( arg, opie ); |
156 | ::strcat ( arg, "/bin/qpe" ); | 183 | ::strcat ( arg, "/bin/qpe" ); |
157 | 184 | ||
158 | // start qpe via a login shell | 185 | // start qpe via a login shell |
159 | ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); | 186 | ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); |
160 | 187 | ||
161 | return false; | 188 | return false; |
162 | } | 189 | } |
163 | 190 | ||
164 | const char *LoginApplication::loginAs ( ) | 191 | const char *LoginApplication::loginAs ( ) |
165 | { | 192 | { |
166 | return s_username; | 193 | return s_username; |
167 | } | 194 | } |
168 | 195 | ||
169 | void LoginApplication::setLoginAs ( const char *name ) | 196 | void LoginApplication::setLoginAs ( const char *name ) |
170 | { | 197 | { |
171 | s_username = name; | 198 | s_username = name; |
172 | } | 199 | } |
173 | 200 | ||
174 | QStringList LoginApplication::allUsers ( ) | 201 | QStringList LoginApplication::allUsers ( ) |
175 | { | 202 | { |
176 | struct passwd *pwd; | 203 | struct passwd *pwd; |
177 | QStringList sl; | 204 | QStringList sl; |
178 | 205 | ||
179 | while (( pwd = ::getpwent ( ))) { | 206 | while (( pwd = ::getpwent ( ))) { |
180 | if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) | 207 | if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) |
181 | sl << QString ( pwd-> pw_name ); | 208 | sl << QString ( pwd-> pw_name ); |
182 | } | 209 | } |
183 | 210 | ||
184 | ::endpwent ( ); | 211 | ::endpwent ( ); |
185 | 212 | ||
186 | return sl; | 213 | return sl; |
187 | } | 214 | } |
188 | 215 | ||
189 | void LoginApplication::quitToConsole ( ) | 216 | void LoginApplication::quitToConsole ( ) |
190 | { | 217 | { |
191 | QPEApplication::quit ( ); | 218 | QPEApplication::quit ( ); |
192 | ::kill ( ::getppid ( ), SIGTERM ); | 219 | ::kill ( ::getppid ( ), SIGTERM ); |
diff --git a/core/opie-login/loginapplication.h b/core/opie-login/loginapplication.h index a709c5b..062c088 100644 --- a/core/opie-login/loginapplication.h +++ b/core/opie-login/loginapplication.h | |||
@@ -1,40 +1,67 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This file is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This file is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
17 | ..}^=.= = ; Public License for more details. | ||
18 | ++= -. .` .: | ||
19 | : = ...= . :.=- You should have received a copy of the GNU | ||
20 | -. .:....=;==+<; General Public License along with this file; | ||
21 | -_. . . )=. = see the file COPYING. If not, write to the | ||
22 | -- :-=` Free Software Foundation, Inc., | ||
23 | 59 Temple Place - Suite 330, | ||
24 | Boston, MA 02111-1307, USA. | ||
25 | |||
26 | */ | ||
27 | |||
1 | #ifndef __OPIE_LOGINAPPLICATION_H__ | 28 | #ifndef __OPIE_LOGINAPPLICATION_H__ |
2 | #define __OPIE_LOGINAPPLICATION_H__ | 29 | #define __OPIE_LOGINAPPLICATION_H__ |
3 | 30 | ||
4 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
5 | 32 | ||
6 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
7 | 34 | ||
8 | #ifdef USEPAM | 35 | #ifdef USEPAM |
9 | struct pam_message; | 36 | struct pam_message; |
10 | struct pam_response; | 37 | struct pam_response; |
11 | #endif | 38 | #endif |
12 | 39 | ||
13 | class LoginApplication : public QPEApplication { | 40 | class LoginApplication : public QPEApplication { |
14 | public: | 41 | public: |
15 | LoginApplication ( int &argc, char **argv ); | 42 | LoginApplication ( int &argc, char **argv ); |
16 | 43 | ||
17 | static bool checkPassword ( const char *user, const char *password ); | 44 | static bool checkPassword ( const char *user, const char *password ); |
18 | 45 | ||
19 | static const char *loginAs ( ); | 46 | static const char *loginAs ( ); |
20 | static void setLoginAs ( const char *user ); | 47 | static void setLoginAs ( const char *user ); |
21 | 48 | ||
22 | static bool changeIdentity ( ); | 49 | static bool changeIdentity ( ); |
23 | static bool login ( ); | 50 | static bool login ( ); |
24 | 51 | ||
25 | static QStringList allUsers ( ); | 52 | static QStringList allUsers ( ); |
26 | 53 | ||
27 | void quitToConsole ( ); | 54 | void quitToConsole ( ); |
28 | 55 | ||
29 | private: | 56 | private: |
30 | static const char *s_username; | 57 | static const char *s_username; |
31 | 58 | ||
32 | #ifdef USEPAM | 59 | #ifdef USEPAM |
33 | static int pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ); | 60 | static int pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ); |
34 | static const char *s_pam_password; | 61 | static const char *s_pam_password; |
35 | #endif | 62 | #endif |
36 | }; | 63 | }; |
37 | 64 | ||
38 | extern LoginApplication *lApp; | 65 | extern LoginApplication *lApp; |
39 | 66 | ||
40 | #endif | 67 | #endif |
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp index 3694513..fe2906a 100644 --- a/core/opie-login/loginwindowimpl.cpp +++ b/core/opie-login/loginwindowimpl.cpp | |||
@@ -1,177 +1,204 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This file is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This file is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
17 | ..}^=.= = ; Public License for more details. | ||
18 | ++= -. .` .: | ||
19 | : = ...= . :.=- You should have received a copy of the GNU | ||
20 | -. .:....=;==+<; General Public License along with this file; | ||
21 | -_. . . )=. = see the file COPYING. If not, write to the | ||
22 | -- :-=` Free Software Foundation, Inc., | ||
23 | 59 Temple Place - Suite 330, | ||
24 | Boston, MA 02111-1307, USA. | ||
25 | |||
26 | */ | ||
27 | |||
1 | #include <qapplication.h> | 28 | #include <qapplication.h> |
2 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
3 | #include <qlayout.h> | 30 | #include <qlayout.h> |
4 | #include <qframe.h> | 31 | #include <qframe.h> |
5 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
6 | #include <qtimer.h> | 33 | #include <qtimer.h> |
7 | #include <qcombobox.h> | 34 | #include <qcombobox.h> |
8 | #include <qpixmap.h> | 35 | #include <qpixmap.h> |
9 | #include <qlabel.h> | 36 | #include <qlabel.h> |
10 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
11 | #include <qmessagebox.h> | 38 | #include <qmessagebox.h> |
12 | #include <qimage.h> | 39 | #include <qimage.h> |
13 | 40 | ||
14 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
15 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
16 | #include <qpe/config.h> | 43 | #include <qpe/config.h> |
17 | 44 | ||
18 | #include <opie/odevice.h> | 45 | #include <opie/odevice.h> |
19 | 46 | ||
20 | #include <stdio.h> | 47 | #include <stdio.h> |
21 | #include <stdlib.h> | 48 | #include <stdlib.h> |
22 | 49 | ||
23 | #include "loginwindowimpl.h" | 50 | #include "loginwindowimpl.h" |
24 | #include "loginapplication.h" | 51 | #include "loginapplication.h" |
25 | #include "inputmethods.h" | 52 | #include "inputmethods.h" |
26 | 53 | ||
27 | using namespace Opie; | 54 | using namespace Opie; |
28 | 55 | ||
29 | 56 | ||
30 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) | 57 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) |
31 | { | 58 | { |
32 | QPopupMenu *pop = new QPopupMenu ( this ); | 59 | QPopupMenu *pop = new QPopupMenu ( this ); |
33 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); | 60 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); |
34 | pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); | 61 | pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); |
35 | m_menu-> setPopup ( pop ); | 62 | m_menu-> setPopup ( pop ); |
36 | 63 | ||
37 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); | 64 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); |
38 | m_input = new InputMethods ( m_taskbar ); | 65 | m_input = new InputMethods ( m_taskbar ); |
39 | lay-> addWidget ( m_input ); | 66 | lay-> addWidget ( m_input ); |
40 | lay-> addStretch ( 10 ); | 67 | lay-> addStretch ( 10 ); |
41 | 68 | ||
42 | setActiveWindow ( ); | 69 | setActiveWindow ( ); |
43 | m_password-> setFocus ( ); | 70 | m_password-> setFocus ( ); |
44 | 71 | ||
45 | m_user-> insertStringList ( lApp-> allUsers ( )); | 72 | m_user-> insertStringList ( lApp-> allUsers ( )); |
46 | 73 | ||
47 | QTimer::singleShot ( 0, this, SLOT( showIM ( ))); | 74 | QTimer::singleShot ( 0, this, SLOT( showIM ( ))); |
48 | 75 | ||
49 | QString opiedir = ::getenv ( "OPIEDIR" ); | 76 | QString opiedir = ::getenv ( "OPIEDIR" ); |
50 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); | 77 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); |
51 | 78 | ||
52 | if ( !bgpix. isNull ( )) | 79 | if ( !bgpix. isNull ( )) |
53 | setBackgroundPixmap ( bgpix ); | 80 | setBackgroundPixmap ( bgpix ); |
54 | 81 | ||
55 | m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); | 82 | m_caption-> setText ( m_caption-> text ( ) + tr( "<center>%1 %2</center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); |
56 | 83 | ||
57 | Config cfg ( "opie-login" ); | 84 | Config cfg ( "opie-login" ); |
58 | cfg. setGroup ( "General" ); | 85 | cfg. setGroup ( "General" ); |
59 | QString last = cfg. readEntry ( "LastLogin" ); | 86 | QString last = cfg. readEntry ( "LastLogin" ); |
60 | 87 | ||
61 | if ( !last. isEmpty ( )) | 88 | if ( !last. isEmpty ( )) |
62 | m_user-> setEditText ( last ); | 89 | m_user-> setEditText ( last ); |
63 | } | 90 | } |
64 | 91 | ||
65 | LoginWindowImpl::~LoginWindowImpl ( ) | 92 | LoginWindowImpl::~LoginWindowImpl ( ) |
66 | { | 93 | { |
67 | } | 94 | } |
68 | 95 | ||
69 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) | 96 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) |
70 | { | 97 | { |
71 | switch ( e-> key ( )) { | 98 | switch ( e-> key ( )) { |
72 | case HardKey_Suspend: suspend ( ); | 99 | case HardKey_Suspend: suspend ( ); |
73 | break; | 100 | break; |
74 | case HardKey_Backlight: backlight ( ); | 101 | case HardKey_Backlight: backlight ( ); |
75 | break; | 102 | break; |
76 | default: e-> ignore ( ); | 103 | default: e-> ignore ( ); |
77 | break; | 104 | break; |
78 | } | 105 | } |
79 | LoginWindow::keyPressEvent ( e ); | 106 | LoginWindow::keyPressEvent ( e ); |
80 | } | 107 | } |
81 | 108 | ||
82 | 109 | ||
83 | void LoginWindowImpl::toggleEchoMode ( bool t ) | 110 | void LoginWindowImpl::toggleEchoMode ( bool t ) |
84 | { | 111 | { |
85 | m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); | 112 | m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); |
86 | } | 113 | } |
87 | 114 | ||
88 | void LoginWindowImpl::showIM ( ) | 115 | void LoginWindowImpl::showIM ( ) |
89 | { | 116 | { |
90 | m_input-> showInputMethod ( ); | 117 | m_input-> showInputMethod ( ); |
91 | } | 118 | } |
92 | 119 | ||
93 | void LoginWindowImpl::restart ( ) | 120 | void LoginWindowImpl::restart ( ) |
94 | { | 121 | { |
95 | qApp-> quit ( ); | 122 | qApp-> quit ( ); |
96 | } | 123 | } |
97 | 124 | ||
98 | void LoginWindowImpl::quit ( ) | 125 | void LoginWindowImpl::quit ( ) |
99 | { | 126 | { |
100 | lApp-> quitToConsole ( ); | 127 | lApp-> quitToConsole ( ); |
101 | } | 128 | } |
102 | 129 | ||
103 | void LoginWindowImpl::suspend ( ) | 130 | void LoginWindowImpl::suspend ( ) |
104 | { | 131 | { |
105 | ODevice::inst ( )-> suspend ( ); | 132 | ODevice::inst ( )-> suspend ( ); |
106 | 133 | ||
107 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 134 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
108 | e << -3; // Force on | 135 | e << -3; // Force on |
109 | } | 136 | } |
110 | 137 | ||
111 | void LoginWindowImpl::backlight ( ) | 138 | void LoginWindowImpl::backlight ( ) |
112 | { | 139 | { |
113 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 140 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
114 | e << -2; // toggle | 141 | e << -2; // toggle |
115 | } | 142 | } |
116 | 143 | ||
117 | class WaitLogo : public QLabel { | 144 | class WaitLogo : public QLabel { |
118 | public: | 145 | public: |
119 | WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool ) | 146 | WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool ) |
120 | { | 147 | { |
121 | QImage img = Resource::loadImage ( "launcher/new_wait" ); | 148 | QImage img = Resource::loadImage ( "launcher/new_wait" ); |
122 | QPixmap pix; | 149 | QPixmap pix; |
123 | pix. convertFromImage ( img ); | 150 | pix. convertFromImage ( img ); |
124 | setPixmap ( pix ); | 151 | setPixmap ( pix ); |
125 | setAlignment ( AlignCenter ); | 152 | setAlignment ( AlignCenter ); |
126 | move ( 0, 0 ); | 153 | move ( 0, 0 ); |
127 | resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( )); | 154 | resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( )); |
128 | 155 | ||
129 | m_visible = false; | 156 | m_visible = false; |
130 | show ( ); | 157 | show ( ); |
131 | } | 158 | } |
132 | 159 | ||
133 | virtual void showEvent ( QShowEvent *e ) | 160 | virtual void showEvent ( QShowEvent *e ) |
134 | { | 161 | { |
135 | QLabel::showEvent ( e ); | 162 | QLabel::showEvent ( e ); |
136 | m_visible = true; | 163 | m_visible = true; |
137 | } | 164 | } |
138 | 165 | ||
139 | virtual void paintEvent ( QPaintEvent *e ) | 166 | virtual void paintEvent ( QPaintEvent *e ) |
140 | { | 167 | { |
141 | QLabel::paintEvent ( e ); | 168 | QLabel::paintEvent ( e ); |
142 | if ( m_visible ) | 169 | if ( m_visible ) |
143 | qApp-> quit ( ); | 170 | qApp-> quit ( ); |
144 | } | 171 | } |
145 | 172 | ||
146 | private: | 173 | private: |
147 | bool m_visible; | 174 | bool m_visible; |
148 | }; | 175 | }; |
149 | 176 | ||
150 | void LoginWindowImpl::login ( ) | 177 | void LoginWindowImpl::login ( ) |
151 | { | 178 | { |
152 | const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); | 179 | const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); |
153 | const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); | 180 | const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); |
154 | 181 | ||
155 | if ( !user || !user [0] ) | 182 | if ( !user || !user [0] ) |
156 | return; | 183 | return; |
157 | if ( !pass ) | 184 | if ( !pass ) |
158 | pass = ""; | 185 | pass = ""; |
159 | 186 | ||
160 | if ( lApp-> checkPassword ( user, pass )) { | 187 | if ( lApp-> checkPassword ( user, pass )) { |
161 | Config cfg ( "opie-login" ); | 188 | Config cfg ( "opie-login" ); |
162 | cfg. setGroup ( "General" ); | 189 | cfg. setGroup ( "General" ); |
163 | cfg. writeEntry ( "LastLogin", user ); | 190 | cfg. writeEntry ( "LastLogin", user ); |
164 | cfg. write ( ); | 191 | cfg. write ( ); |
165 | 192 | ||
166 | lApp-> setLoginAs ( user ); | 193 | lApp-> setLoginAs ( user ); |
167 | 194 | ||
168 | // Draw a big wait icon, the image can be altered in later revisions | 195 | // Draw a big wait icon, the image can be altered in later revisions |
169 | m_input-> hideInputMethod ( ); | 196 | m_input-> hideInputMethod ( ); |
170 | new WaitLogo ( ); | 197 | new WaitLogo ( ); |
171 | // WaitLogo::showEvent() calls qApp-> quit() | 198 | // WaitLogo::showEvent() calls qApp-> quit() |
172 | } | 199 | } |
173 | else { | 200 | else { |
174 | QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); | 201 | QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); |
175 | m_password-> clear ( ); | 202 | m_password-> clear ( ); |
176 | } | 203 | } |
177 | } | 204 | } |
diff --git a/core/opie-login/loginwindowimpl.h b/core/opie-login/loginwindowimpl.h index 2e2ba0d..e769b03 100644 --- a/core/opie-login/loginwindowimpl.h +++ b/core/opie-login/loginwindowimpl.h | |||
@@ -1,34 +1,61 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This file is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This file is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
17 | ..}^=.= = ; Public License for more details. | ||
18 | ++= -. .` .: | ||
19 | : = ...= . :.=- You should have received a copy of the GNU | ||
20 | -. .:....=;==+<; General Public License along with this file; | ||
21 | -_. . . )=. = see the file COPYING. If not, write to the | ||
22 | -- :-=` Free Software Foundation, Inc., | ||
23 | 59 Temple Place - Suite 330, | ||
24 | Boston, MA 02111-1307, USA. | ||
25 | |||
26 | */ | ||
27 | |||
1 | #ifndef __OPIE_LOGINWINDOW_IMPL_H__ | 28 | #ifndef __OPIE_LOGINWINDOW_IMPL_H__ |
2 | #define __OPIE_LOGINWINDOW_IMPL_H__ | 29 | #define __OPIE_LOGINWINDOW_IMPL_H__ |
3 | 30 | ||
4 | #include "loginwindow.h" | 31 | #include "loginwindow.h" |
5 | 32 | ||
6 | class InputMethods; | 33 | class InputMethods; |
7 | 34 | ||
8 | class LoginWindowImpl : public LoginWindow { | 35 | class LoginWindowImpl : public LoginWindow { |
9 | Q_OBJECT | 36 | Q_OBJECT |
10 | 37 | ||
11 | public: | 38 | public: |
12 | LoginWindowImpl ( ); | 39 | LoginWindowImpl ( ); |
13 | virtual ~LoginWindowImpl ( ); | 40 | virtual ~LoginWindowImpl ( ); |
14 | 41 | ||
15 | protected slots: | 42 | protected slots: |
16 | void restart ( ); | 43 | void restart ( ); |
17 | void quit ( ); | 44 | void quit ( ); |
18 | void showIM ( ); | 45 | void showIM ( ); |
19 | void suspend ( ); | 46 | void suspend ( ); |
20 | void backlight ( ); | 47 | void backlight ( ); |
21 | void login ( ); | 48 | void login ( ); |
22 | void toggleEchoMode ( bool ); | 49 | void toggleEchoMode ( bool ); |
23 | 50 | ||
24 | protected: | 51 | protected: |
25 | virtual void keyPressEvent ( QKeyEvent *e ); | 52 | virtual void keyPressEvent ( QKeyEvent *e ); |
26 | 53 | ||
27 | QStringList getAllUsers ( ); | 54 | QStringList getAllUsers ( ); |
28 | bool changeIdentity ( const char *user ); | 55 | bool changeIdentity ( const char *user ); |
29 | 56 | ||
30 | private: | 57 | private: |
31 | InputMethods *m_input; | 58 | InputMethods *m_input; |
32 | }; | 59 | }; |
33 | 60 | ||
34 | #endif | 61 | #endif |
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 91610af..2c10f77 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp | |||
@@ -1,192 +1,219 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This file is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This file is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
17 | ..}^=.= = ; Public License for more details. | ||
18 | ++= -. .` .: | ||
19 | : = ...= . :.=- You should have received a copy of the GNU | ||
20 | -. .:....=;==+<; General Public License along with this file; | ||
21 | -_. . . )=. = see the file COPYING. If not, write to the | ||
22 | -- :-=` Free Software Foundation, Inc., | ||
23 | 59 Temple Place - Suite 330, | ||
24 | Boston, MA 02111-1307, USA. | ||
25 | |||
26 | */ | ||
27 | |||
1 | #define _GNU_SOURCE | 28 | #define _GNU_SOURCE |
2 | 29 | ||
3 | #include <sys/types.h> | 30 | #include <sys/types.h> |
4 | #include <time.h> | 31 | #include <time.h> |
5 | #include <sys/time.h> | 32 | #include <sys/time.h> |
6 | #include <sys/resource.h> | 33 | #include <sys/resource.h> |
7 | #include <unistd.h> | 34 | #include <unistd.h> |
8 | #include <syslog.h> | 35 | #include <syslog.h> |
9 | #include <sys/wait.h> | 36 | #include <sys/wait.h> |
10 | #include <stdio.h> | 37 | #include <stdio.h> |
11 | #include <stdlib.h> | 38 | #include <stdlib.h> |
12 | #include <signal.h> | 39 | #include <signal.h> |
13 | #include <getopt.h> | 40 | #include <getopt.h> |
14 | #include <string.h> | 41 | #include <string.h> |
15 | 42 | ||
16 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/qcopenvelope_qws.h> | 44 | #include <qpe/qcopenvelope_qws.h> |
18 | #include <qpe/qpestyle.h> | 45 | #include <qpe/qpestyle.h> |
19 | #include <qpe/power.h> | 46 | #include <qpe/power.h> |
20 | 47 | ||
21 | #include <opie/odevice.h> | 48 | #include <opie/odevice.h> |
22 | 49 | ||
23 | #include <qwindowsystem_qws.h> | 50 | #include <qwindowsystem_qws.h> |
24 | #include <qmessagebox.h> | 51 | #include <qmessagebox.h> |
25 | #include <qlabel.h> | 52 | #include <qlabel.h> |
26 | #include <qtimer.h> | 53 | #include <qtimer.h> |
27 | 54 | ||
28 | #include "loginapplication.h" | 55 | #include "loginapplication.h" |
29 | #include "loginwindowimpl.h" | 56 | #include "loginwindowimpl.h" |
30 | #include "calibrate.h" | 57 | #include "calibrate.h" |
31 | 58 | ||
32 | using namespace Opie; | 59 | using namespace Opie; |
33 | 60 | ||
34 | int login_main ( int argc, char **argv ); | 61 | int login_main ( int argc, char **argv ); |
35 | void sigterm ( int sig ); | 62 | void sigterm ( int sig ); |
36 | void exit_closelog ( ); | 63 | void exit_closelog ( ); |
37 | 64 | ||
38 | static struct option long_options [] = { | 65 | static struct option long_options [] = { |
39 | { "autologin", 1, 0, 'a' }, | 66 | { "autologin", 1, 0, 'a' }, |
40 | { 0, 0, 0, 0 } | 67 | { 0, 0, 0, 0 } |
41 | }; | 68 | }; |
42 | 69 | ||
43 | 70 | ||
44 | int main ( int argc, char **argv ) | 71 | int main ( int argc, char **argv ) |
45 | { | 72 | { |
46 | if ( ::geteuid ( ) != 0 ) { | 73 | if ( ::geteuid ( ) != 0 ) { |
47 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | 74 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); |
48 | return 1; | 75 | return 1; |
49 | } | 76 | } |
50 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and | 77 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and |
51 | ::setuid ( 0 ); // messes up things like config files | 78 | ::setuid ( 0 ); // messes up things like config files |
52 | 79 | ||
53 | char *autolog = 0; | 80 | char *autolog = 0; |
54 | int c; | 81 | int c; |
55 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { | 82 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { |
56 | switch ( c ) { | 83 | switch ( c ) { |
57 | case 'a': | 84 | case 'a': |
58 | autolog = optarg; | 85 | autolog = optarg; |
59 | break; | 86 | break; |
60 | default: | 87 | default: |
61 | ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); | 88 | ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); |
62 | return 2; | 89 | return 2; |
63 | } | 90 | } |
64 | } | 91 | } |
65 | 92 | ||
66 | //struct rlimit rl; | 93 | //struct rlimit rl; |
67 | //::getrlimit ( RLIMIT_NOFILE, &rl ); | 94 | //::getrlimit ( RLIMIT_NOFILE, &rl ); |
68 | 95 | ||
69 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) | 96 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) |
70 | // ::close ( i ); | 97 | // ::close ( i ); |
71 | 98 | ||
72 | ::setpgid ( 0, 0 ); | 99 | ::setpgid ( 0, 0 ); |
73 | ::setsid ( ); | 100 | ::setsid ( ); |
74 | 101 | ||
75 | ::signal ( SIGTERM, sigterm ); | 102 | ::signal ( SIGTERM, sigterm ); |
76 | 103 | ||
77 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); | 104 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); |
78 | ::atexit ( exit_closelog ); | 105 | ::atexit ( exit_closelog ); |
79 | 106 | ||
80 | while ( true ) { | 107 | while ( true ) { |
81 | pid_t child = ::fork ( ); | 108 | pid_t child = ::fork ( ); |
82 | 109 | ||
83 | if ( child < 0 ) { | 110 | if ( child < 0 ) { |
84 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); | 111 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); |
85 | break; | 112 | break; |
86 | } | 113 | } |
87 | else if ( child > 0 ) { | 114 | else if ( child > 0 ) { |
88 | int status = 0; | 115 | int status = 0; |
89 | time_t started = ::time ( 0 ); | 116 | time_t started = ::time ( 0 ); |
90 | 117 | ||
91 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | 118 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } |
92 | 119 | ||
93 | if (( ::time ( 0 ) - started ) < 3 ) { | 120 | if (( ::time ( 0 ) - started ) < 3 ) { |
94 | if ( autolog ) { | 121 | if ( autolog ) { |
95 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); | 122 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); |
96 | autolog = 0; | 123 | autolog = 0; |
97 | } | 124 | } |
98 | else { | 125 | else { |
99 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); | 126 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); |
100 | break; | 127 | break; |
101 | } | 128 | } |
102 | } | 129 | } |
103 | int killedbysig = 0; | 130 | int killedbysig = 0; |
104 | 131 | ||
105 | if ( WIFSIGNALED( status )) { | 132 | if ( WIFSIGNALED( status )) { |
106 | switch ( WTERMSIG( status )) { | 133 | switch ( WTERMSIG( status )) { |
107 | case SIGINT : | 134 | case SIGINT : |
108 | case SIGTERM: | 135 | case SIGTERM: |
109 | case SIGKILL: | 136 | case SIGKILL: |
110 | break; | 137 | break; |
111 | 138 | ||
112 | default : | 139 | default : |
113 | killedbysig = WTERMSIG( status ); | 140 | killedbysig = WTERMSIG( status ); |
114 | break; | 141 | break; |
115 | } | 142 | } |
116 | } | 143 | } |
117 | if ( killedbysig ) { // qpe was killed by an uncaught signal | 144 | if ( killedbysig ) { // qpe was killed by an uncaught signal |
118 | qApp = 0; | 145 | qApp = 0; |
119 | 146 | ||
120 | QWSServer::setDesktopBackground ( QImage ( )); | 147 | QWSServer::setDesktopBackground ( QImage ( )); |
121 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); | 148 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); |
122 | app-> setFont ( QFont ( "Helvetica", 10 )); | 149 | app-> setFont ( QFont ( "Helvetica", 10 )); |
123 | app-> setStyle ( new QPEStyle ( )); | 150 | app-> setStyle ( new QPEStyle ( )); |
124 | 151 | ||
125 | const char *sig = ::strsignal ( killedbysig ); | 152 | const char *sig = ::strsignal ( killedbysig ); |
126 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); | 153 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); |
127 | l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); | 154 | l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); |
128 | l-> setAlignment ( Qt::AlignCenter ); | 155 | l-> setAlignment ( Qt::AlignCenter ); |
129 | l-> move ( 0, 0 ); | 156 | l-> move ( 0, 0 ); |
130 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 157 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |
131 | l-> show ( ); | 158 | l-> show ( ); |
132 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); | 159 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); |
133 | app-> exec ( ); | 160 | app-> exec ( ); |
134 | delete app; | 161 | delete app; |
135 | qApp = 0; | 162 | qApp = 0; |
136 | } | 163 | } |
137 | } | 164 | } |
138 | else { | 165 | else { |
139 | if ( autolog ) { | 166 | if ( autolog ) { |
140 | LoginApplication::setLoginAs ( autolog ); | 167 | LoginApplication::setLoginAs ( autolog ); |
141 | 168 | ||
142 | if ( LoginApplication::changeIdentity ( )) | 169 | if ( LoginApplication::changeIdentity ( )) |
143 | ::exit ( LoginApplication::login ( )); | 170 | ::exit ( LoginApplication::login ( )); |
144 | else | 171 | else |
145 | ::exit ( 0 ); | 172 | ::exit ( 0 ); |
146 | } | 173 | } |
147 | else | 174 | else |
148 | ::exit ( login_main ( argc, argv )); | 175 | ::exit ( login_main ( argc, argv )); |
149 | } | 176 | } |
150 | } | 177 | } |
151 | return 0; | 178 | return 0; |
152 | } | 179 | } |
153 | 180 | ||
154 | void sigterm ( int /*sig*/ ) | 181 | void sigterm ( int /*sig*/ ) |
155 | { | 182 | { |
156 | ::exit ( 0 ); | 183 | ::exit ( 0 ); |
157 | } | 184 | } |
158 | 185 | ||
159 | 186 | ||
160 | void exit_closelog ( ) | 187 | void exit_closelog ( ) |
161 | { | 188 | { |
162 | ::closelog ( ); | 189 | ::closelog ( ); |
163 | } | 190 | } |
164 | 191 | ||
165 | 192 | ||
166 | class LoginScreenSaver : public QWSScreenSaver | 193 | class LoginScreenSaver : public QWSScreenSaver |
167 | { | 194 | { |
168 | public: | 195 | public: |
169 | LoginScreenSaver ( ) | 196 | LoginScreenSaver ( ) |
170 | { | 197 | { |
171 | m_lcd_status = true; | 198 | m_lcd_status = true; |
172 | 199 | ||
173 | m_backlight_bright = -1; | 200 | m_backlight_bright = -1; |
174 | m_backlight_forcedoff = false; | 201 | m_backlight_forcedoff = false; |
175 | 202 | ||
176 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 203 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
177 | ODevice::inst ( )-> setDisplayStatus ( true ); | 204 | ODevice::inst ( )-> setDisplayStatus ( true ); |
178 | } | 205 | } |
179 | void restore() | 206 | void restore() |
180 | { | 207 | { |
181 | if ( !m_lcd_status ) // We must have turned it off | 208 | if ( !m_lcd_status ) // We must have turned it off |
182 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 209 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
183 | 210 | ||
184 | setBacklight ( -3 ); | 211 | setBacklight ( -3 ); |
185 | } | 212 | } |
186 | bool save( int level ) | 213 | bool save( int level ) |
187 | { | 214 | { |
188 | switch ( level ) { | 215 | switch ( level ) { |
189 | case 0: | 216 | case 0: |
190 | if ( backlight() > 1 ) | 217 | if ( backlight() > 1 ) |
191 | setBacklight( 1 ); // lowest non-off | 218 | setBacklight( 1 ); // lowest non-off |
192 | return true; | 219 | return true; |