[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5
From:       Luboš Luňák <l.lunak () kde ! org>
Date:       2007-05-25 12:40:18
Message-ID: 1180096818.686486.5364.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 668198 by lunakl:

Fix the problem that the setuid kdeinit wrapper causes unsetting
some variables like LD_LIBRARY_PATH, I knew there would be somebody
who'd know what to do with it - add yet another wrapper that saves
the environment and use it again from withing the setuid wrapper.



 M  +1 -1      kdebase/startkde  
 M  +3 -1      kdelibs/kinit/Makefile.am  
 M  +32 -1     kdelibs/kinit/start_kdeinit.c  
 A             kdelibs/kinit/start_kdeinit_wrapper.c   [License: LGPL (v2)]


--- branches/KDE/3.5/kdebase/startkde #668197:668198
@@ -342,7 +342,7 @@
 
 # We set LD_BIND_NOW to increase the efficiency of kdeinit.
 # kdeinit unsets this variable before loading applications.
-LD_BIND_NOW=true start_kdeinit --new-startup +kcminit_startup
+LD_BIND_NOW=true start_kdeinit_wrapper --new-startup +kcminit_startup
 if test $? -ne 0; then
   # Startup error
   echo 'startkde: Could not start kdeinit. Check your installation.'  1>&2
--- branches/KDE/3.5/kdelibs/kinit/Makefile.am #668197:668198
@@ -20,7 +20,7 @@
 SUBDIRS = . tests
 
 bin_PROGRAMS = kdeinit kdeinit_wrapper kshell kdeinit_shutdown lnusertemp kwrapper kioslave \
-               kstartupconfig kdostartupconfig start_kdeinit
+               kstartupconfig kdostartupconfig start_kdeinit start_kdeinit_wrapper
 
 lib_LTLIBRARIES = 
 kdeinit_LTLIBRARIES = klauncher.la
@@ -71,6 +71,8 @@
 start_kdeinit_CFLAGS = $(KDE_USE_FPIE) -DEXECUTE=\"$(kdeinitpath)\"
 start_kdeinit_LDFLAGS = $(KDE_USE_PIE)
 
+start_kdeinit_wrapper_SOURCES = start_kdeinit_wrapper.c
+
 METASOURCES = AUTO
 
 noinst_HEADERS = klauncher.h autostart.h klauncher_cmds.h setproctitle.h
--- branches/KDE/3.5/kdelibs/kinit/start_kdeinit.c #668197:668198
@@ -24,6 +24,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #ifdef KDEINIT_OOM_PROTECT
@@ -67,6 +68,8 @@
    const char** new_argv;
    char helper_num[ 1024 ];
    int i;
+   char** orig_environ = NULL;
+   char header[ 7 ];
    if( pipe( pipes ) < 0 ) {
       perror( "pipe()" );
       return 1;
@@ -89,6 +92,31 @@
             return 1;
          }
          close( pipes[ 0 ] );
+         /* read original environment passed by start_kdeinit_wrapper */
+         if( read( 0, header, 7 ) == 7 && strncmp( header, "environ", 7 ) == 0 ) {
+             int count;
+             if( read( 0, &count, sizeof( int )) == sizeof( int )) {
+                 char** env = malloc(( count + 1 ) * sizeof( char* ));
+                 int ok = 1;
+                 for( i = 0;
+                      i < count && ok;
+                      ++i ) {
+                     int len;
+                     if( read( 0, &len, sizeof( int )) == sizeof( int )) {
+                         env[ i ] = malloc( len + 1 );
+                         if( read( 0, env[ i ], len ) == len ) {
+                             env[ i ][ len ] = '\0';
+                         } else {
+                             ok = 0;
+                         }
+                     }
+                 }
+                 if( ok ) {
+                   env[ i ] = NULL;
+                   orig_environ = env;
+                 }
+             }
+         }
          if(argc == 0)
             return 1;
          new_argc = argc + 2;
@@ -103,7 +131,10 @@
               i <= argc;
               ++i )
              new_argv[ i + 2 ] = argv[ i ];
-         execv(EXECUTE, (char**)new_argv);
+         if( orig_environ )
+             execve(EXECUTE, (char**)new_argv, orig_environ);
+         else
+             execv(EXECUTE, (char**)new_argv);
          perror(EXECUTE);
          return 1;
       case 0: /* child, keep privileges and do the privileged work */
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic