summaryrefslogtreecommitdiff
path: root/core/opie-login/loginapplication.cpp
Unidiff
Diffstat (limited to 'core/opie-login/loginapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/loginapplication.cpp74
1 files changed, 67 insertions, 7 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
@@ -30,6 +30,8 @@
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
35extern "C" { 37extern "C" {
@@ -158,6 +160,10 @@ bool LoginApplication::changeIdentity ( )
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 ( );
@@ -177,16 +183,70 @@ bool LoginApplication::changeIdentity ( )
177 183
178bool LoginApplication::login ( ) 184bool 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" );
189
190 qWarning ( "failed to start an Opie session" );
191 return false;
192}
193
194void LoginApplication::logout ( )
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}
182 200
183 ::strcpy ( arg, opie );
184 ::strcat ( arg, "/bin/qpe" );
185 201
186 // start qpe via a login shell 202static char *buildarg ( const char *base, const char *script )
187 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); 203{
204 const char *dir = base ? ::getenv ( base ) : "/";
205 char *arg = new char [::strlen ( dir ) + ::strlen ( script ) + 2];
188 206
189 return false; 207 ::strcpy ( arg, dir );
208 ::strcat ( arg, "/" );
209 ::strcat ( arg, script );
210
211 return arg;
212}
213
214bool 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
239void 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
192const char *LoginApplication::loginAs ( ) 252const char *LoginApplication::loginAs ( )