-rw-r--r-- | core/opie-login/loginapplication.cpp | 74 | ||||
-rw-r--r-- | core/opie-login/loginapplication.h | 6 | ||||
-rw-r--r-- | core/opie-login/main.cpp | 10 |
3 files changed, 81 insertions, 9 deletions
diff --git a/core/opie-login/loginapplication.cpp b/core/opie-login/loginapplication.cpp index 8d86a71..1facf2d 100644 --- a/core/opie-login/loginapplication.cpp +++ b/core/opie-login/loginapplication.cpp | |||
@@ -27,12 +27,14 @@ | |||
27 | 27 | ||
28 | #include <pwd.h> | 28 | #include <pwd.h> |
29 | #include <grp.h> | 29 | #include <grp.h> |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <signal.h> | 32 | #include <signal.h> |
33 | #include <sys/stat.h> | ||
34 | #include <sys/wait.h> | ||
33 | 35 | ||
34 | #ifdef USEPAM | 36 | #ifdef USEPAM |
35 | extern "C" { | 37 | extern "C" { |
36 | #include <security/pam_appl.h> | 38 | #include <security/pam_appl.h> |
37 | } | 39 | } |
38 | #else | 40 | #else |
@@ -155,12 +157,16 @@ bool LoginApplication::changeIdentity ( ) | |||
155 | if ( !s_username ) | 157 | if ( !s_username ) |
156 | return false; | 158 | return false; |
157 | struct passwd *pw = ::getpwnam ( s_username ); | 159 | struct passwd *pw = ::getpwnam ( s_username ); |
158 | if ( !pw ) | 160 | if ( !pw ) |
159 | return false; | 161 | return false; |
160 | 162 | ||
163 | // we are still root at this point - try to run the pre-session script | ||
164 | if ( !runRootScript ( "OPIEDIR", "share/opie-login/pre-session", s_username )) | ||
165 | qWarning ( "failed to run $OPIEDIR/share/opie-login/pre-session" ); | ||
166 | |||
161 | bool fail = false; | 167 | bool fail = false; |
162 | fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid )); | 168 | fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid )); |
163 | ::endgrent ( ); | 169 | ::endgrent ( ); |
164 | fail |= ( ::setgid ( pw-> pw_gid )); | 170 | fail |= ( ::setgid ( pw-> pw_gid )); |
165 | fail |= ( ::setuid ( pw-> pw_uid )); | 171 | fail |= ( ::setuid ( pw-> pw_uid )); |
166 | 172 | ||
@@ -174,22 +180,76 @@ bool LoginApplication::changeIdentity ( ) | |||
174 | 180 | ||
175 | return !fail; | 181 | return !fail; |
176 | } | 182 | } |
177 | 183 | ||
178 | bool LoginApplication::login ( ) | 184 | bool LoginApplication::login ( ) |
179 | { | 185 | { |
180 | char *opie = ::getenv ( "OPIEDIR" ); | 186 | execUserScript ( "HOME", ".opie-session" ); |
181 | char *arg = new char [::strlen ( opie ) + 8 + 1]; | 187 | execUserScript ( "OPIEDIR", "share/opie-login/opie-session" ); |
188 | execUserScript ( "OPIEDIR", "bin/qpe" ); | ||
182 | 189 | ||
183 | ::strcpy ( arg, opie ); | 190 | qWarning ( "failed to start an Opie session" ); |
184 | ::strcat ( arg, "/bin/qpe" ); | 191 | return false; |
192 | } | ||
185 | 193 | ||
186 | // start qpe via a login shell | 194 | void LoginApplication::logout ( ) |
187 | ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); | 195 | { |
196 | // we are now root again - try to run the post-session script | ||
197 | if ( !runRootScript ( "OPIEDIR", "share/opie-login/post-session" )) | ||
198 | qWarning ( "failed to run $OPIEDIR/scripts/post-session" ); | ||
199 | } | ||
188 | 200 | ||
189 | return false; | 201 | |
202 | static char *buildarg ( const char *base, const char *script ) | ||
203 | { | ||
204 | const char *dir = base ? ::getenv ( base ) : "/"; | ||
205 | char *arg = new char [::strlen ( dir ) + ::strlen ( script ) + 2]; | ||
206 | |||
207 | ::strcpy ( arg, dir ); | ||
208 | ::strcat ( arg, "/" ); | ||
209 | ::strcat ( arg, script ); | ||
210 | |||
211 | return arg; | ||
212 | } | ||
213 | |||
214 | bool LoginApplication::runRootScript ( const char *base, const char *script, const char *param ) | ||
215 | { | ||
216 | bool res = false; | ||
217 | char *arg = buildarg ( base, script ); | ||
218 | |||
219 | struct stat st; | ||
220 | if (( ::stat ( arg, &st ) == 0 ) && ( st. st_uid == 0 )) { | ||
221 | pid_t child = ::fork ( ); | ||
222 | |||
223 | if ( child == 0 ) { | ||
224 | ::execl ( "/bin/sh", "-sh", arg, param, 0 ); | ||
225 | ::_exit ( -1 ); | ||
226 | } | ||
227 | else if ( child > 0 ) { | ||
228 | int status = 0; | ||
229 | |||
230 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | ||
231 | res = ( WIFEXITED( status )) && ( WEXITSTATUS( status ) == 0 ); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | delete [] arg; | ||
236 | return res; | ||
237 | } | ||
238 | |||
239 | void LoginApplication::execUserScript ( const char *base, const char *script ) | ||
240 | { | ||
241 | char *arg = buildarg ( base, script ); | ||
242 | |||
243 | struct stat st; | ||
244 | if ( ::stat ( arg, &st ) == 0 ) { | ||
245 | if ( st. st_mode & S_IXUSR ) | ||
246 | ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); | ||
247 | else | ||
248 | ::execl ( "/bin/sh", "-sh", arg, 0 ); | ||
249 | } | ||
190 | } | 250 | } |
191 | 251 | ||
192 | const char *LoginApplication::loginAs ( ) | 252 | const char *LoginApplication::loginAs ( ) |
193 | { | 253 | { |
194 | return s_username; | 254 | return s_username; |
195 | } | 255 | } |
diff --git a/core/opie-login/loginapplication.h b/core/opie-login/loginapplication.h index 4e7cf79..d8264ea 100644 --- a/core/opie-login/loginapplication.h +++ b/core/opie-login/loginapplication.h | |||
@@ -25,14 +25,14 @@ | |||
25 | 25 | ||
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef __OPIE_LOGINAPPLICATION_H__ | 28 | #ifndef __OPIE_LOGINAPPLICATION_H__ |
29 | #define __OPIE_LOGINAPPLICATION_H__ | 29 | #define __OPIE_LOGINAPPLICATION_H__ |
30 | 30 | ||
31 | #include <sys/types.h> | ||
31 | #include <qstringlist.h> | 32 | #include <qstringlist.h> |
32 | |||
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | 34 | ||
35 | #ifdef USEPAM | 35 | #ifdef USEPAM |
36 | struct pam_message; | 36 | struct pam_message; |
37 | struct pam_response; | 37 | struct pam_response; |
38 | #endif | 38 | #endif |
@@ -45,17 +45,21 @@ public: | |||
45 | 45 | ||
46 | static const char *loginAs ( ); | 46 | static const char *loginAs ( ); |
47 | static void setLoginAs ( const char *user ); | 47 | static void setLoginAs ( const char *user ); |
48 | 48 | ||
49 | static bool changeIdentity ( ); | 49 | static bool changeIdentity ( ); |
50 | static bool login ( ); | 50 | static bool login ( ); |
51 | static void logout ( ); | ||
51 | 52 | ||
52 | static QStringList allUsers ( ); | 53 | static QStringList allUsers ( ); |
53 | 54 | ||
54 | void quitToConsole ( ); | 55 | void quitToConsole ( ); |
55 | 56 | ||
57 | static bool runRootScript ( const char *base, const char *script, const char *param = 0 ); | ||
58 | static void execUserScript ( const char *base, const char *script ); | ||
59 | |||
56 | private: | 60 | private: |
57 | static const char *s_username; | 61 | static const char *s_username; |
58 | 62 | ||
59 | #ifdef USEPAM | 63 | #ifdef USEPAM |
60 | static int pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ); | 64 | static int pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ); |
61 | static const char *s_pam_password; | 65 | static const char *s_pam_password; |
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 674829d..81f4d1e 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp | |||
@@ -59,25 +59,25 @@ | |||
59 | #include "calibrate.h" | 59 | #include "calibrate.h" |
60 | 60 | ||
61 | using namespace Opie; | 61 | using namespace Opie; |
62 | 62 | ||
63 | int login_main ( int argc, char **argv, pid_t ppid ); | 63 | int login_main ( int argc, char **argv, pid_t ppid ); |
64 | void sigterm ( int sig ); | 64 | void sigterm ( int sig ); |
65 | void sigint ( int sig ); | ||
65 | void exit_closelog ( ); | 66 | void exit_closelog ( ); |
66 | 67 | ||
67 | static struct option long_options [] = { | 68 | static struct option long_options [] = { |
68 | { "autologin", 1, 0, 'a' }, | 69 | { "autologin", 1, 0, 'a' }, |
69 | { 0, 0, 0, 0 } | 70 | { 0, 0, 0, 0 } |
70 | }; | 71 | }; |
71 | 72 | ||
72 | 73 | ||
73 | int main ( int argc, char **argv ) | 74 | int main ( int argc, char **argv ) |
74 | { | 75 | { |
75 | pid_t ppid = ::getpid ( ); | 76 | pid_t ppid = ::getpid ( ); |
76 | 77 | ||
77 | |||
78 | if ( ::geteuid ( ) != 0 ) { | 78 | if ( ::geteuid ( ) != 0 ) { |
79 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | 79 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); |
80 | return 1; | 80 | return 1; |
81 | } | 81 | } |
82 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and | 82 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and |
83 | ::setuid ( 0 ); // messes up things like config files | 83 | ::setuid ( 0 ); // messes up things like config files |
@@ -102,12 +102,13 @@ int main ( int argc, char **argv ) | |||
102 | // ::close ( i ); | 102 | // ::close ( i ); |
103 | 103 | ||
104 | ::setpgid ( 0, 0 ); | 104 | ::setpgid ( 0, 0 ); |
105 | ::setsid ( ); | 105 | ::setsid ( ); |
106 | 106 | ||
107 | ::signal ( SIGTERM, sigterm ); | 107 | ::signal ( SIGTERM, sigterm ); |
108 | ::signal ( SIGINT, sigterm ); | ||
108 | 109 | ||
109 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); | 110 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); |
110 | ::atexit ( exit_closelog ); | 111 | ::atexit ( exit_closelog ); |
111 | 112 | ||
112 | while ( true ) { | 113 | while ( true ) { |
113 | pid_t child = ::fork ( ); | 114 | pid_t child = ::fork ( ); |
@@ -119,12 +120,14 @@ int main ( int argc, char **argv ) | |||
119 | else if ( child > 0 ) { | 120 | else if ( child > 0 ) { |
120 | int status = 0; | 121 | int status = 0; |
121 | time_t started = ::time ( 0 ); | 122 | time_t started = ::time ( 0 ); |
122 | 123 | ||
123 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | 124 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } |
124 | 125 | ||
126 | LoginApplication::logout ( ); | ||
127 | |||
125 | if (( ::time ( 0 ) - started ) < 3 ) { | 128 | if (( ::time ( 0 ) - started ) < 3 ) { |
126 | if ( autolog ) { | 129 | if ( autolog ) { |
127 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); | 130 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); |
128 | autolog = 0; | 131 | autolog = 0; |
129 | } | 132 | } |
130 | else { | 133 | else { |
@@ -146,12 +149,14 @@ int main ( int argc, char **argv ) | |||
146 | break; | 149 | break; |
147 | } | 150 | } |
148 | } | 151 | } |
149 | if ( killedbysig ) { // qpe was killed by an uncaught signal | 152 | if ( killedbysig ) { // qpe was killed by an uncaught signal |
150 | qApp = 0; | 153 | qApp = 0; |
151 | 154 | ||
155 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); | ||
156 | |||
152 | QWSServer::setDesktopBackground ( QImage ( )); | 157 | QWSServer::setDesktopBackground ( QImage ( )); |
153 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); | 158 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); |
154 | app-> setFont ( QFont ( "Helvetica", 10 )); | 159 | app-> setFont ( QFont ( "Helvetica", 10 )); |
155 | app-> setStyle ( new QPEStyle ( )); | 160 | app-> setStyle ( new QPEStyle ( )); |
156 | 161 | ||
157 | const char *sig = ::strsignal ( killedbysig ); | 162 | const char *sig = ::strsignal ( killedbysig ); |
@@ -300,19 +305,22 @@ private: | |||
300 | 305 | ||
301 | int m_backlight_bright; | 306 | int m_backlight_bright; |
302 | bool m_backlight_forcedoff; | 307 | bool m_backlight_forcedoff; |
303 | }; | 308 | }; |
304 | 309 | ||
305 | 310 | ||
311 | namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting | ||
306 | 312 | ||
307 | 313 | ||
308 | int login_main ( int argc, char **argv, pid_t ppid ) | 314 | int login_main ( int argc, char **argv, pid_t ppid ) |
309 | { | 315 | { |
310 | QWSServer::setDesktopBackground( QImage() ); | 316 | QWSServer::setDesktopBackground( QImage() ); |
311 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | 317 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); |
312 | 318 | ||
319 | Opie::force_appearance = 0; | ||
320 | |||
313 | app-> setFont ( QFont ( "Helvetica", 10 )); | 321 | app-> setFont ( QFont ( "Helvetica", 10 )); |
314 | app-> setStyle ( new QPEStyle ( )); | 322 | app-> setStyle ( new QPEStyle ( )); |
315 | 323 | ||
316 | ODevice::inst ( )-> setSoftSuspend ( true ); | 324 | ODevice::inst ( )-> setSoftSuspend ( true ); |
317 | 325 | ||
318 | #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 326 | #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |