summaryrefslogtreecommitdiff
authorsandman <sandman>2002-12-17 19:41:05 (UTC)
committer sandman <sandman>2002-12-17 19:41:05 (UTC)
commit0e05c298cc4e5a5d509286e31a3a863e78c76456 (patch) (unidiff)
tree2a86553b593ff9690c14e1796c54c707f189fdf3
parent98f90f6ed89986485a1413c4325411e30f4c0693 (diff)
downloadopie-0e05c298cc4e5a5d509286e31a3a863e78c76456.zip
opie-0e05c298cc4e5a5d509286e31a3a863e78c76456.tar.gz
opie-0e05c298cc4e5a5d509286e31a3a863e78c76456.tar.bz2
Opie login becomes useable now:
- pre- and post-session scripts (in $OPIEDIR/share/opie-login) to fix things like device ownership to user/root - logging in now doesn't simply mean: execute bin/qpe. instead opie-login * first tries to execute ~/.opie-session * if that doesn't exist $OPIEDIR/share/opie-login/opie-session * if that fails too, execute $OPIEDIR/bin/qpe you can now handle things like ssh-agent on a per-user basis. (I'll commit the scripts later - for now it simply works like before)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/loginapplication.cpp74
-rw-r--r--core/opie-login/loginapplication.h6
-rw-r--r--core/opie-login/main.cpp12
3 files changed, 82 insertions, 10 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
@@ -32,2 +32,4 @@
32#include <signal.h> 32#include <signal.h>
33#include <sys/stat.h>
34#include <sys/wait.h>
33 35
@@ -160,2 +162,6 @@ bool LoginApplication::changeIdentity ( )
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;
@@ -179,12 +185,66 @@ 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" );
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}
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
@@ -30,4 +30,4 @@
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>
@@ -50,2 +50,3 @@ public:
50 static bool login ( ); 50 static bool login ( );
51 static void logout ( );
51 52
@@ -55,2 +56,5 @@ public:
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
56private: 60private:
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
@@ -64,2 +64,3 @@ int login_main ( int argc, char **argv, pid_t ppid );
64void sigterm ( int sig ); 64void sigterm ( int sig );
65void sigint ( int sig );
65void exit_closelog ( ); 66void exit_closelog ( );
@@ -76,3 +77,2 @@ int main ( int argc, char **argv )
76 77
77
78 if ( ::geteuid ( ) != 0 ) { 78 if ( ::geteuid ( ) != 0 ) {
@@ -106,3 +106,4 @@ int main ( int argc, char **argv )
106 106
107 ::signal ( SIGTERM, sigterm ); 107 ::signal ( SIGTERM, sigterm );
108 ::signal ( SIGINT, sigterm );
108 109
@@ -124,2 +125,4 @@ int main ( int argc, char **argv )
124 125
126 LoginApplication::logout ( );
127
125 if (( ::time ( 0 ) - started ) < 3 ) { 128 if (( ::time ( 0 ) - started ) < 3 ) {
@@ -150,2 +153,4 @@ int main ( int argc, char **argv )
150 qApp = 0; 153 qApp = 0;
154
155 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig );
151 156
@@ -305,2 +310,3 @@ private:
305 310
311namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting
306 312
@@ -312,2 +318,4 @@ int login_main ( int argc, char **argv, pid_t ppid )
312 318
319 Opie::force_appearance = 0;
320
313 app-> setFont ( QFont ( "Helvetica", 10 )); 321 app-> setFont ( QFont ( "Helvetica", 10 ));